Skip to content
This repository has been archived by the owner on Nov 22, 2019. It is now read-only.

Commit

Permalink
ConnectionStatus work
Browse files Browse the repository at this point in the history
  • Loading branch information
mdrillin committed Apr 12, 2018
1 parent 896a2dd commit 825547b
Show file tree
Hide file tree
Showing 17 changed files with 488 additions and 257 deletions.
Expand Up @@ -522,6 +522,8 @@ export class AddConnectionWizardComponent implements OnInit {
*/
private createDeployConnection(connection: NewConnection): void {
const self = this;
// flag with wizard service that this connection will need schema generated
this.wizardService.setConnectionIdForSchemaRegen(connection.getName());
this.connectionService
.createDeployConnection(connection)
.subscribe(
Expand Down
Expand Up @@ -13,43 +13,36 @@
</div>
<span class="pull-left fa fa-check-circle-o fa-2x card-action-icon"
style="color:green;"
*ngIf="connection.schemaActive"
*ngIf="connection.isActive"
data-toggle="tooltip"
data-placement="right"
title="Active">
</span>
<span class="pull-left fa fa-times-circle-o fa-2x card-action-icon"
style="color:red;"
*ngIf="connection.schemaFailed"
*ngIf="connection.isFailed"
data-toggle="tooltip"
data-placement="right"
title="Failed to activate">
</span>
<span class="pull-left fa fa-exclamation-triangle fa-2x card-action-icon"
style="color:orange;"
*ngIf="connection.schemaInactive"
data-toggle="tooltip"
data-placement="right"
title="Inactive">
</span>
<span class="pull-left fa fa-times-circle-o fa-2x card-action-icon"
style="color:red;"
*ngIf="connection.schemaNotDeployed"
*ngIf="connection.isInactive"
data-toggle="tooltip"
data-placement="right"
title="Inactive">
</span>
<span class="pull-left fa fa-spinner fa-pulse fa-2x card-action-icon"
*ngIf="connection.schemaLoading">
*ngIf="connection.isLoading">
</span>
<span *ngIf="!connection.schemaLoading"
<span *ngIf="!connection.isLoading"
class="pull-right fa fa-edit card-action-icon"
(click)="onClick(editEvent)"
data-toggle="tooltip"
data-placement="right"
title="Edit">
</span>
<span *ngIf="connection.schemaLoading"
<span *ngIf="connection.isLoading"
class="pull-right fa fa-edit card-action-icon-disabled"
data-toggle="tooltip"
data-placement="right"
Expand Down
@@ -1,5 +1,6 @@
import { async, ComponentFixture, TestBed } from "@angular/core/testing";
import { RouterTestingModule } from "@angular/router/testing";
import { ConnectionStatus } from "@connections/shared/connection-status";
import { Connection } from "@connections/shared/connection.model";
import { LoggerService } from "@core/logger.service";
import { PatternFlyNgModule } from "patternfly-ng";
Expand All @@ -22,8 +23,14 @@ describe("ConnectionCardComponent", () => {
fixture = TestBed.createComponent(ConnectionCardComponent);
component = fixture.componentInstance;

// Create a connection
const connection = new Connection();
connection.setId( "MyConnection" );

// Set a status on the connection
const connStatus = ConnectionStatus.createLoadingStatus("MyConnection");
connection.setStatus(connStatus);

component.connection = connection;
component.selectedConnections = [ connection ];

Expand Down
Expand Up @@ -83,8 +83,8 @@ export class ConnectionCardComponent implements DoCheck, OnInit {
}

public ngDoCheck(): void {
if ( this.isLoading !== this.connection.schemaLoading ) {
this.isLoading = this.connection.schemaLoading;
if ( this.isLoading !== this.connection.isLoading ) {
this.isLoading = this.connection.isLoading;

this.actionConfig.moreActions[ this.activateActionIndex ].disabled = this.isLoading;
this.actionConfig.moreActions[ this.deleteActionIndex ].disabled = this.isLoading;
Expand Down
Expand Up @@ -19,11 +19,10 @@
</div>
<div class="list-pf-content-wrapper">
<div class="list-pf-main-content">
<span class="pull-left pficon-ok" *ngIf="item.schemaActive"></span>
<span class="pull-left pficon-error-circle-o" *ngIf="item.schemaFailed"></span>
<span class="pull-left pficon-warning-triangle-o" *ngIf="item.schemaInactive"></span>
<span class="pull-left pficon-error-circle-o" *ngIf="item.schemaNotDeployed"></span>
<span class="pull-left fa fa-spinner fa-pulse" *ngIf="item.schemaLoading"></span>
<span class="pull-left pficon-ok" *ngIf="item.isActive"></span>
<span class="pull-left pficon-error-circle-o" *ngIf="item.isFailed"></span>
<span class="pull-left pficon-warning-triangle-o" *ngIf="item.isInactive"></span>
<span class="pull-left fa fa-spinner fa-pulse" *ngIf="item.isLoading"></span>
<a class="object-name-link" [routerLink]="[item.name]" (click)="onEditConnection(item.name)">{{ item.name }}</a>
<div class="list-pf-description">{{ getDescription(item) }}</div>
</div>
Expand Down
Expand Up @@ -83,7 +83,7 @@ export class ConnectionsListComponent implements OnInit {
const actionConfig = {
primaryActions: [
{
disabled: connection.schemaLoading,
disabled: connection.isLoading,
id: this.editActionId,
template: editActionTemplate,
title: "Edit",
Expand All @@ -92,14 +92,14 @@ export class ConnectionsListComponent implements OnInit {
],
moreActions: [
{
disabled: connection.schemaLoading,
disabled: connection.isLoading,
id: this.activateActionId,
template: activateActionTemplate,
title: "Activate",
tooltip: "Activate this connection"
},
{
disabled: connection.schemaLoading,
disabled: connection.isLoading,
id: this.deleteActionId,
template: deleteActionTemplate,
title: "Delete",
Expand Down
109 changes: 89 additions & 20 deletions ngapp/src/app/connections/connections.component.ts
Expand Up @@ -17,25 +17,25 @@

import { Component, OnInit, ViewChild } from "@angular/core";
import { ActivatedRoute, Router } from "@angular/router";
import { ConnectionStatus } from "@connections/shared/connection-status";
import { Connection } from "@connections/shared/connection.model";
import { ConnectionService } from "@connections/shared/connection.service";
import { ConnectionsConstants } from "@connections/shared/connections-constants";
import { AppSettingsService } from "@core/app-settings.service";
import { LoggerService } from "@core/logger.service";
import { DeploymentState } from "@dataservices/shared/deployment-state.enum";
import { NotifierService } from "@dataservices/shared/notifier.service";
import { WizardService } from "@dataservices/shared/wizard.service";
import { AbstractPageComponent } from "@shared/abstract-page.component";
import { ConfirmDeleteComponent } from "@shared/confirm-delete/confirm-delete.component";
import { LayoutType } from "@shared/layout-type.enum";
import { ActionConfig, EmptyStateConfig, Filter } from "patternfly-ng";
import { FilterConfig } from "patternfly-ng";
import { FilterField } from "patternfly-ng";
import { FilterEvent } from "patternfly-ng";
import { SortConfig } from "patternfly-ng";
import { SortField } from "patternfly-ng";
import { SortEvent } from "patternfly-ng";
import { FilterType } from "patternfly-ng";
import { ActionConfig, EmptyStateConfig, Filter } from "patternfly-ng";
import { SortConfig } from "patternfly-ng";
import { Subscription } from "rxjs/Subscription";

@Component({
Expand Down Expand Up @@ -64,7 +64,7 @@ export class ConnectionsComponent extends AbstractPageComponent implements OnIni
private connectionService: ConnectionService;
private wizardService: WizardService;
private notifierService: NotifierService;
private connectionVdbStateSubscription: Subscription;
private connectionStatusSubscription: Subscription;

@ViewChild(ConfirmDeleteComponent) private confirmDeleteDialog: ConfirmDeleteComponent;

Expand All @@ -77,9 +77,9 @@ export class ConnectionsComponent extends AbstractPageComponent implements OnIni
this.connectionService = connectionService;
this.wizardService = wizardService;
this.notifierService = notifierService;
// Register for connection VDB state changes
this.connectionVdbStateSubscription = this.notifierService.getConnectionStateMap().subscribe((connectionStateMap) => {
this.onConnectionVdbStateChanged(connectionStateMap);
// Register for connection status changes
this.connectionStatusSubscription = this.notifierService.getConnectionStatusMap().subscribe((connectionStatusMap) => {
this.onConnectionStatusChanged(connectionStatusMap);
});
}

Expand Down Expand Up @@ -144,12 +144,21 @@ export class ConnectionsComponent extends AbstractPageComponent implements OnIni
const self = this;

this.connectionService
.getConnections(true, false)
.getConnections(true, true)
.subscribe(
(connectionSummaries) => {
const conns = [];
// If there is a newly added connection, it has been flagged for schema regen
const newlyAddedConnName = self.wizardService.getConnectionIdForSchemaRegen();
for ( const connSummary of connectionSummaries ) {
conns.push(connSummary.getConnection());
const conn = connSummary.getConnection();
let status = connSummary.getStatus();
// Newly added connection is given a loading status
if (conn.getId() === newlyAddedConnName) {
status = ConnectionStatus.createLoadingStatus(newlyAddedConnName);
}
conn.setStatus(status);
conns.push(conn);
}
self.allConns = conns;
self.filteredConns = conns;
Expand Down Expand Up @@ -254,17 +263,31 @@ export class ConnectionsComponent extends AbstractPageComponent implements OnIni
}

/**
* Handle Activation of the specified Connection. Initiates refresh of the connection schema.
* Handle Activation of the specified Connection. The activate actions taken depend on the vdb
* and schema states.
* @param {string} connName
*/
public onActivate(connName: string): void {
const selectedConnection = this.filteredConnections.find((x) => x.getId() === connName);
selectedConnection.setSchemaState(DeploymentState.LOADING);

// If connection VDB missing or failed - redeploy the vdb and then generate schema
const deployVdb = selectedConnection.serverVdbMissing || selectedConnection.serverVdbFailed;
// If vdb deployment is required, flag the need to regen the schema
if (deployVdb) {
this.wizardService.setConnectionIdForSchemaRegen(connName);
}

// Will trigger schema reload unless it is currently loading
const genSchema = !selectedConnection.schemaLoading;

// Sets a spinner on the connection until everything is done
const connectionStatus: ConnectionStatus = ConnectionStatus.createLoadingStatus(connName);
selectedConnection.setStatus(connectionStatus);

const self = this;
// Start the connection deployment
this.connectionService
.refreshConnectionSchema(connName)
.refreshConnectionSchema(connName, deployVdb, genSchema)
.subscribe(
(wasSuccess) => {
self.connectionService.updateConnectionSchemaStates();
Expand All @@ -281,9 +304,6 @@ export class ConnectionsComponent extends AbstractPageComponent implements OnIni
public onDeleteConnection(): void {
const selectedConn = this.filteredConnections.find((x) => x.getId() === this.connectionNameForDelete);

// const itemsToDelete: Connection[] = ArrayUtils.intersect(this.selectedConns, this.filteredConns);
// const selectedConn = itemsToDelete[0];

// Note: we can only doDelete selected items that we can see in the UI.
this.logger.log("[ConnectionsPageComponent] Deleting selected Connection.");
const self = this;
Expand Down Expand Up @@ -385,10 +405,10 @@ export class ConnectionsComponent extends AbstractPageComponent implements OnIni
.deleteUndeployConnectionVdb(connectionId)
.subscribe(
(wasSuccess) => {
// nothing to do
self.connectionService.updateConnectionSchemaStates();
},
(error) => {
// nothing to do
self.connectionService.updateConnectionSchemaStates();
}
);
}
Expand All @@ -402,16 +422,65 @@ export class ConnectionsComponent extends AbstractPageComponent implements OnIni
}

/*
* Update the displayed connection states using the provided states
* Update the connection states using the provided status map
*/
private onConnectionVdbStateChanged(stateMap: Map<string, DeploymentState>): void {
private onConnectionStatusChanged(stateMap: Map<string, ConnectionStatus>): void {
// Get name of connection for schema regen (empty if none)
const connForSchemaRegen = this.wizardService.getConnectionIdForSchemaRegen();

// For displayed dataservices, update the State using supplied services
for ( const conn of this.filteredConns ) {
const connId = conn.getId();
if (stateMap && stateMap.has(connId)) {
conn.setSchemaState(stateMap.get(connId));
// If there is a schema marked for regen, it's status is ignored. regen will set it
if (connId !== connForSchemaRegen) {
conn.setStatus(stateMap.get(connId));
}
}
}

// If there is a newly added connection, initiate schema generation
if (this.wizardService.hasConnectionForSchemaRegen) {
this.initiateSchemaGeneration(connForSchemaRegen);
}
}

/*
* Initiate schema generation for the specified connection, if it is found
*/
private initiateSchemaGeneration(connName: string): void {
const connectionExists = this.connectionExists(connName);
const self = this;
if (connectionExists) {
this.connectionService
.refreshConnectionSchema(connName, false, true)
.subscribe(
(wasSuccess) => {
self.wizardService.setConnectionIdForSchemaRegen(""); // reset connection for regen when done
self.connectionService.updateConnectionSchemaStates(); // triggers refresh to get latest connection states
},
(error) => {
self.wizardService.setConnectionIdForSchemaRegen(""); // reset connection for regen when done
self.connectionService.updateConnectionSchemaStates(); // triggers refresh to get latest connection states
}
);
}
}

/**
* Determine if a connection with the supplied name exists in the current connections
* @param {string} connName the connection name
* @returns {boolean} 'true' if connection exists
*/
private connectionExists(connName: string): boolean {
let connFound = false;
for ( const conn of this.allConns ) {
const connId = conn.getId();
if (connName === connId) {
connFound = true;
break;
}
}
return connFound;
}
}

0 comments on commit 825547b

Please sign in to comment.