From e24f838d81ac9d847c9ccc221b099d9b620925a2 Mon Sep 17 00:00:00 2001 From: zyjiaobj Date: Wed, 14 Nov 2018 20:12:25 +0800 Subject: [PATCH 01/98] [autoscaler] add autoscaler tab --- .../auto-scaler-tab.component.html | 3 + .../auto-scaler-tab.component.scss | 6 ++ .../auto-scaler-tab.component.spec.ts | 69 +++++++++++++++++++ .../auto-scaler-tab.component.ts | 24 +++++++ .../applications/applications.module.ts | 2 + .../applications/applications.routing.ts | 2 + 6 files changed, 106 insertions(+) create mode 100644 src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.html create mode 100644 src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.scss create mode 100644 src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.spec.ts create mode 100644 src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.ts diff --git a/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.html b/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.html new file mode 100644 index 0000000000..f2e5e67904 --- /dev/null +++ b/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.html @@ -0,0 +1,3 @@ +
+ +
diff --git a/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.scss b/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.scss new file mode 100644 index 0000000000..94ca044473 --- /dev/null +++ b/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.scss @@ -0,0 +1,6 @@ +.app-auto-scaler { + display: flex; + height: 100%; + position: relative; + width: 100%; +} diff --git a/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.spec.ts b/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.spec.ts new file mode 100644 index 0000000000..9fd903bb52 --- /dev/null +++ b/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.spec.ts @@ -0,0 +1,69 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { BrowserAnimationsModule, NoopAnimationsModule } from '@angular/platform-browser/animations'; +import { RouterTestingModule } from '@angular/router/testing'; +import { StoreModule } from '@ngrx/store'; + +import { CoreModule } from '../../../../../../core/core.module'; +import { MDAppModule } from '../../../../../../core/md.module'; +import { ApplicationStateService } from '../../../../../../shared/components/application-state/application-state.service'; +import { LogViewerComponent } from '../../../../../../shared/components/log-viewer/log-viewer.component'; +import { EntityMonitorFactory } from '../../../../../../shared/monitors/entity-monitor.factory.service'; +import { PaginationMonitorFactory } from '../../../../../../shared/monitors/pagination-monitor.factory'; +import { GetApplication } from '../../../../../../store/actions/application.actions'; +import { applicationSchemaKey, entityFactory } from '../../../../../../store/helpers/entity-factory'; +import { AppStoreModule } from '../../../../../../store/store.module'; +import { generateTestApplicationServiceProvider } from '../../../../../../test-framework/application-service-helper'; +import { generateTestEntityServiceProvider } from '../../../../../../test-framework/entity-service.helper'; +import { createBasicStoreModule } from '../../../../../../test-framework/store-test-helper'; +import { ApplicationEnvVarsService } from '../build-tab/application-env-vars.service'; +import { LogStreamTabComponent } from './auto-scaler-tab.component'; + + +describe('LogStreamTabComponent', () => { + let component: LogStreamTabComponent; + let fixture: ComponentFixture; + + const appId = ''; + const cfId = '2'; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [ + StoreModule, + CoreModule, + NoopAnimationsModule, + RouterTestingModule, + MDAppModule, + createBasicStoreModule() + ], + declarations: [ + LogViewerComponent, + LogStreamTabComponent + ], + providers: [ + generateTestEntityServiceProvider( + appId, + entityFactory(applicationSchemaKey), + new GetApplication(appId, cfId) + ), + generateTestApplicationServiceProvider(cfId, appId), + AppStoreModule, + ApplicationStateService, + ApplicationEnvVarsService, + EntityMonitorFactory, + PaginationMonitorFactory + ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(LogStreamTabComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should be created', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.ts b/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.ts new file mode 100644 index 0000000000..0ba16870ce --- /dev/null +++ b/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.ts @@ -0,0 +1,24 @@ +import { Component, OnInit } from '@angular/core'; +import { DomSanitizer } from '@angular/platform-browser'; +import { ApplicationService } from '../../../../application.service'; + +@Component({ + selector: 'app-auto-scaler-tab', + templateUrl: './auto-scaler-tab.component.html', + styleUrls: ['./auto-scaler-tab.component.scss'] +}) +export class AutoScalerTabComponent implements OnInit { + + srcUrl: any; + + constructor(private sanitizer: DomSanitizer, private applicationService: ApplicationService) { + this.srcUrl = this.sanitizer.bypassSecurityTrustResourceUrl('https://scalingconsole.stage1.eu-gb.bluemix.net/apps/' + this.applicationService.appGuid); + console.log("url", this.srcUrl) + } + + ngOnInit() { + console.log('cfGuid', this.applicationService.cfGuid) + console.log('appGuid', this.applicationService.appGuid) + } + +} diff --git a/src/frontend/packages/core/src/features/applications/applications.module.ts b/src/frontend/packages/core/src/features/applications/applications.module.ts index 75db658c1f..d03deb8285 100644 --- a/src/frontend/packages/core/src/features/applications/applications.module.ts +++ b/src/frontend/packages/core/src/features/applications/applications.module.ts @@ -17,6 +17,7 @@ import { EventsTabComponent } from './application/application-tabs-base/tabs/eve import { GitSCMTabComponent } from './application/application-tabs-base/tabs/gitscm-tab/gitscm-tab.component'; import { InstancesTabComponent } from './application/application-tabs-base/tabs/instances-tab/instances-tab.component'; import { LogStreamTabComponent } from './application/application-tabs-base/tabs/log-stream-tab/log-stream-tab.component'; +import { AutoScalerTabComponent } from './application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component'; import { MetricsTabComponent } from './application/application-tabs-base/tabs/metrics-tab/metrics-tab.component'; import { RoutesTabComponent } from './application/application-tabs-base/tabs/routes-tab/routes-tab/routes-tab.component'; import { ServicesTabComponent } from './application/application-tabs-base/tabs/services-tab/services-tab.component'; @@ -46,6 +47,7 @@ import { NewApplicationBaseStepComponent } from './new-application-base-step/new ApplicationBaseComponent, EventsTabComponent, LogStreamTabComponent, + AutoScalerTabComponent, ServicesTabComponent, BuildTabComponent, VariablesTabComponent, diff --git a/src/frontend/packages/core/src/features/applications/applications.routing.ts b/src/frontend/packages/core/src/features/applications/applications.routing.ts index ea3522160a..526de56cfb 100644 --- a/src/frontend/packages/core/src/features/applications/applications.routing.ts +++ b/src/frontend/packages/core/src/features/applications/applications.routing.ts @@ -19,6 +19,7 @@ import { EventsTabComponent } from './application/application-tabs-base/tabs/eve import { GitSCMTabComponent } from './application/application-tabs-base/tabs/gitscm-tab/gitscm-tab.component'; import { InstancesTabComponent } from './application/application-tabs-base/tabs/instances-tab/instances-tab.component'; import { LogStreamTabComponent } from './application/application-tabs-base/tabs/log-stream-tab/log-stream-tab.component'; +import { AutoScalerTabComponent } from './application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component'; import { MetricsTabComponent } from './application/application-tabs-base/tabs/metrics-tab/metrics-tab.component'; import { RoutesTabComponent } from './application/application-tabs-base/tabs/routes-tab/routes-tab/routes-tab.component'; import { ServicesTabComponent } from './application/application-tabs-base/tabs/services-tab/services-tab.component'; @@ -106,6 +107,7 @@ const applicationsRoutes: Routes = [ { path: 'events', component: EventsTabComponent }, { path: 'gitscm', component: GitSCMTabComponent }, { path: 'metrics', component: MetricsTabComponent }, + { path: 'auto-scaler', component: AutoScalerTabComponent }, { path: '**', component: PageNotFoundComponentComponent, From 49ffa85ee28d3196823d7374c7a852e21e00364a Mon Sep 17 00:00:00 2001 From: zyjiaobj Date: Tue, 20 Nov 2018 11:36:00 +0800 Subject: [PATCH 02/98] [autoscaler] show basic info in autoscaler tab --- .../auto-scaler-tab.component.html | 42 +++++++++++++++++-- .../auto-scaler-tab.component.ts | 42 ++++++++++++++----- .../application-service-helper.ts | 3 ++ .../store/src/helpers/entity-factory.ts | 8 ++++ .../api-request-reducers.generator.ts | 6 ++- .../packages/store/src/types/entity.types.ts | 6 ++- src/jetstream/passthrough.go | 6 +++ 7 files changed, 98 insertions(+), 15 deletions(-) diff --git a/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.html b/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.html index f2e5e67904..776c3b2c0b 100644 --- a/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.html +++ b/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.html @@ -1,3 +1,39 @@ -
- -
+
+ + + + + + Status + + + + + + + + + + Limits + + + + + + + + + + +
\ No newline at end of file diff --git a/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.ts b/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.ts index 0ba16870ce..2ca83499f5 100644 --- a/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.ts +++ b/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.ts @@ -1,24 +1,46 @@ -import { Component, OnInit } from '@angular/core'; -import { DomSanitizer } from '@angular/platform-browser'; +import { Component, OnDestroy, OnInit } from '@angular/core'; +import { Observable } from 'rxjs'; +import { EntityService } from '../../../../../../core/entity-service'; +import { EntityServiceFactory } from '../../../../../../core/entity-service-factory.service'; +import { + entityFactory, + appAutoscalerPolicySchemaKey, +} from '../../../../../../store/helpers/entity-factory'; import { ApplicationService } from '../../../../application.service'; +import { GetAppAutoscalerPolicyAction } from '../../../../../../store/actions/app-autoscaler.actions'; +import { AppAutoscalerPolicy } from '../../../../../../store/types/app-autoscaler.types'; +import { map } from 'rxjs/operators'; @Component({ selector: 'app-auto-scaler-tab', templateUrl: './auto-scaler-tab.component.html', - styleUrls: ['./auto-scaler-tab.component.scss'] + styleUrls: ['./auto-scaler-tab.component.scss'], }) export class AutoScalerTabComponent implements OnInit { - srcUrl: any; + appAutoscalerPolicyService: EntityService; + appAutoscalerPolicy$: Observable; - constructor(private sanitizer: DomSanitizer, private applicationService: ApplicationService) { - this.srcUrl = this.sanitizer.bypassSecurityTrustResourceUrl('https://scalingconsole.stage1.eu-gb.bluemix.net/apps/' + this.applicationService.appGuid); - console.log("url", this.srcUrl) - } + constructor( + private applicationService: ApplicationService, + private entityServiceFactory: EntityServiceFactory, + ) { } ngOnInit() { - console.log('cfGuid', this.applicationService.cfGuid) - console.log('appGuid', this.applicationService.appGuid) + this.appAutoscalerPolicyService = this.entityServiceFactory.create( + appAutoscalerPolicySchemaKey, + entityFactory(appAutoscalerPolicySchemaKey), + this.applicationService.appGuid, + new GetAppAutoscalerPolicyAction(this.applicationService.appGuid), + false + ); + this.appAutoscalerPolicy$ = this.appAutoscalerPolicyService.entityObs$.pipe( + map(({ entity }) => entity), + map(policyEntity => { + console.log("appAutoscalerPolicy", policyEntity) + return policyEntity && policyEntity.entity + }) + ); } } diff --git a/src/frontend/packages/core/test-framework/application-service-helper.ts b/src/frontend/packages/core/test-framework/application-service-helper.ts index afb06d55a5..b665e3b421 100644 --- a/src/frontend/packages/core/test-framework/application-service-helper.ts +++ b/src/frontend/packages/core/test-framework/application-service-helper.ts @@ -13,6 +13,7 @@ import { AppState } from '../../store/src/app-state'; import { EntityServiceFactory } from '../src/core/entity-service-factory.service'; import { PaginationMonitorFactory } from '../src/shared/monitors/pagination-monitor.factory'; import { Observable, of as observableOf } from 'rxjs'; +import { AppAutoscalerPolicy, AppAutoscalerHealth } from '../store/types/app-autoscaler.types'; function createEntity(entity: T): APIResource { return { @@ -51,6 +52,8 @@ export class ApplicationServiceMock { appSummary$: Observable>> = observableOf({ entityRequestInfo: { fetching: false } } as EntityInfo>); + appAutoscalerPolicy$: Observable> = observableOf(({ entityRequestInfo: { fetching: false } } as EntityInfo)); + appAutoscalerHealth$: Observable> = observableOf(({ entityRequestInfo: { fetching: false } } as EntityInfo)); appStats$: Observable[]> = observableOf(new Array>()); applicationStratProject$: Observable = observableOf({ deploySource: { type: '', timestamp: 0, commit: '' }, deployOverrides: null }); diff --git a/src/frontend/packages/store/src/helpers/entity-factory.ts b/src/frontend/packages/store/src/helpers/entity-factory.ts index cdc5c69e1d..d31655d78a 100644 --- a/src/frontend/packages/store/src/helpers/entity-factory.ts +++ b/src/frontend/packages/store/src/helpers/entity-factory.ts @@ -36,6 +36,8 @@ export const servicePlanVisibilitySchemaKey = 'servicePlanVisibility'; export const serviceBrokerSchemaKey = 'serviceBroker'; export const userFavoritesSchemaKey = 'userFavorites'; export const userProvidedServiceInstanceSchemaKey = 'userProvidedServiceInstance'; +export const appAutoscalerHealthSchemaKey = 'autoscalerHealth'; +export const appAutoscalerPolicySchemaKey = 'autoscalerPolicy'; export const spaceWithOrgKey = 'spaceWithOrg'; export const serviceInstancesWithSpaceSchemaKey = 'serviceInstancesWithSpace'; @@ -313,6 +315,12 @@ entityCache[servicePlanVisibilitySchemaKey] = ServicePlanVisibilitySchema; const UserFavoritesSchemaKey = new EntitySchema(userFavoritesSchemaKey, {}, { idAttribute: getAPIResourceGuid }); entityCache[userFavoritesSchemaKey] = UserFavoritesSchemaKey; +const AppAutoscalerPolicySchema = new EntitySchema(appAutoscalerPolicySchemaKey, {}, { idAttribute: getAPIResourceGuid }); +entityCache[appAutoscalerPolicySchemaKey] = AppAutoscalerPolicySchema; + +const AppAutoscalerHealthSchema = new EntitySchema(appAutoscalerHealthSchemaKey, {}, { idAttribute: getAPIResourceGuid }); +entityCache[appAutoscalerHealthSchemaKey] = AppAutoscalerHealthSchema; + const ApplicationEntitySchema = new EntitySchema( applicationSchemaKey, { diff --git a/src/frontend/packages/store/src/reducers/api-request-reducers.generator.ts b/src/frontend/packages/store/src/reducers/api-request-reducers.generator.ts index f8f1293e89..949d2ed7bf 100644 --- a/src/frontend/packages/store/src/reducers/api-request-reducers.generator.ts +++ b/src/frontend/packages/store/src/reducers/api-request-reducers.generator.ts @@ -29,6 +29,8 @@ import { userFavoritesSchemaKey, userProfileSchemaKey, userProvidedServiceInstanceSchemaKey, + appAutoscalerPolicySchemaKey, + appAutoscalerHealthSchemaKey, } from '../helpers/entity-factory'; import { endpointStoreNames } from '../types/endpoint.types'; import { IRequestDataState, IRequestState } from '../types/entity.types'; @@ -116,7 +118,9 @@ const entities = [ servicePlanVisibilitySchemaKey, serviceBrokerSchemaKey, userFavoritesSchemaKey, - userProvidedServiceInstanceSchemaKey + userProvidedServiceInstanceSchemaKey, + appAutoscalerPolicySchemaKey, + appAutoscalerHealthSchemaKey, ]; export function registerAPIRequestEntity(schemaKey: string) { diff --git a/src/frontend/packages/store/src/types/entity.types.ts b/src/frontend/packages/store/src/types/entity.types.ts index 25858b43f3..d5fd999804 100644 --- a/src/frontend/packages/store/src/types/entity.types.ts +++ b/src/frontend/packages/store/src/types/entity.types.ts @@ -46,6 +46,8 @@ import { stackSchemaKey, userFavoritesSchemaKey, userProvidedServiceInstanceSchemaKey, + appAutoscalerHealthSchemaKey, + appAutoscalerPolicySchemaKey, } from '../helpers/entity-factory'; import { RequestInfoState } from '../reducers/api-request-reducer/types'; import { APIResource } from './api.types'; @@ -138,5 +140,7 @@ export const defaultCfEntitiesState = { [servicePlanVisibilitySchemaKey]: {}, [serviceBrokerSchemaKey]: {}, [userFavoritesSchemaKey]: {}, - [userProvidedServiceInstanceSchemaKey]: [] + [userProvidedServiceInstanceSchemaKey]: [], + [appAutoscalerHealthSchemaKey]: {}, + [appAutoscalerPolicySchemaKey]: {}, }; diff --git a/src/jetstream/passthrough.go b/src/jetstream/passthrough.go index 604817f08d..37fb8c0cf5 100644 --- a/src/jetstream/passthrough.go +++ b/src/jetstream/passthrough.go @@ -254,6 +254,12 @@ func (p *portalProxy) ProxyRequest(c echo.Context, uri *url.URL) (map[string]*in if strings.HasPrefix(cnsiRequest.URL.Host, apiPrefix) { // Replace 'api.' prefix with supplied prefix cnsiRequest.URL.Host = strings.Replace(cnsiRequest.URL.Host, apiPrefix, apiHost, 1) + if apiHost == "autoscaler." { + cnsiRequest.URL.Path = strings.Replace(cnsiRequest.URL.Path, "v2", "v1", 1) + } + if apiHost == "scalingconsole." { + cnsiRequest.URL.Path = strings.Replace(cnsiRequest.URL.Path, "v2", "v1", 1) + } } else { // Add supplied prefix to the domain cnsiRequest.URL.Host = apiHost + cnsiRequest.URL.Host From 689037571b873610255c653f8715cf3e47531387 Mon Sep 17 00:00:00 2001 From: zyjiaobj Date: Tue, 20 Nov 2018 18:06:22 +0800 Subject: [PATCH 03/98] [autoscaler] add metric hostory request (fail) --- .../auto-scaler-tab.component.html | 26 ++++- .../auto-scaler-tab.component.scss | 11 ++ .../auto-scaler-tab.component.spec.ts | 69 ------------ .../auto-scaler-tab.component.ts | 61 ++++++++++- .../store/actions/app-autoscaler.actions.ts | 103 ++++++++++++++++++ .../app/store/types/app-autoscaler.types.ts | 14 +++ .../store/src/helpers/entity-factory.ts | 12 ++ .../api-request-reducers.generator.ts | 6 + .../packages/store/src/types/entity.types.ts | 6 + 9 files changed, 231 insertions(+), 77 deletions(-) delete mode 100644 src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.spec.ts create mode 100644 src/frontend/app/store/actions/app-autoscaler.actions.ts create mode 100644 src/frontend/app/store/types/app-autoscaler.types.ts diff --git a/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.html b/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.html index 776c3b2c0b..7687ef46a8 100644 --- a/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.html +++ b/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.html @@ -15,7 +15,7 @@ - + Limits @@ -31,9 +31,29 @@ + + + + + + Scaling Rules + + + + + + + - + \ No newline at end of file diff --git a/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.scss b/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.scss index 94ca044473..1685de240a 100644 --- a/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.scss +++ b/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.scss @@ -4,3 +4,14 @@ position: relative; width: 100%; } + +.app-metadata { + display: flex; + flex-direction: row; + &__two-cols { + flex: 1; + app-metadata-item:first-child { + margin-top: 0; + } + } +} diff --git a/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.spec.ts b/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.spec.ts deleted file mode 100644 index 9fd903bb52..0000000000 --- a/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.spec.ts +++ /dev/null @@ -1,69 +0,0 @@ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -import { BrowserAnimationsModule, NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { RouterTestingModule } from '@angular/router/testing'; -import { StoreModule } from '@ngrx/store'; - -import { CoreModule } from '../../../../../../core/core.module'; -import { MDAppModule } from '../../../../../../core/md.module'; -import { ApplicationStateService } from '../../../../../../shared/components/application-state/application-state.service'; -import { LogViewerComponent } from '../../../../../../shared/components/log-viewer/log-viewer.component'; -import { EntityMonitorFactory } from '../../../../../../shared/monitors/entity-monitor.factory.service'; -import { PaginationMonitorFactory } from '../../../../../../shared/monitors/pagination-monitor.factory'; -import { GetApplication } from '../../../../../../store/actions/application.actions'; -import { applicationSchemaKey, entityFactory } from '../../../../../../store/helpers/entity-factory'; -import { AppStoreModule } from '../../../../../../store/store.module'; -import { generateTestApplicationServiceProvider } from '../../../../../../test-framework/application-service-helper'; -import { generateTestEntityServiceProvider } from '../../../../../../test-framework/entity-service.helper'; -import { createBasicStoreModule } from '../../../../../../test-framework/store-test-helper'; -import { ApplicationEnvVarsService } from '../build-tab/application-env-vars.service'; -import { LogStreamTabComponent } from './auto-scaler-tab.component'; - - -describe('LogStreamTabComponent', () => { - let component: LogStreamTabComponent; - let fixture: ComponentFixture; - - const appId = ''; - const cfId = '2'; - - beforeEach(async(() => { - TestBed.configureTestingModule({ - imports: [ - StoreModule, - CoreModule, - NoopAnimationsModule, - RouterTestingModule, - MDAppModule, - createBasicStoreModule() - ], - declarations: [ - LogViewerComponent, - LogStreamTabComponent - ], - providers: [ - generateTestEntityServiceProvider( - appId, - entityFactory(applicationSchemaKey), - new GetApplication(appId, cfId) - ), - generateTestApplicationServiceProvider(cfId, appId), - AppStoreModule, - ApplicationStateService, - ApplicationEnvVarsService, - EntityMonitorFactory, - PaginationMonitorFactory - ] - }) - .compileComponents(); - })); - - beforeEach(() => { - fixture = TestBed.createComponent(LogStreamTabComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should be created', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.ts b/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.ts index 2ca83499f5..c12dc35545 100644 --- a/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.ts +++ b/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.ts @@ -5,11 +5,19 @@ import { EntityServiceFactory } from '../../../../../../core/entity-service-fact import { entityFactory, appAutoscalerPolicySchemaKey, + appAutoscalerScalingHistorySchemaKey, + appAutoscalerAppMetricHistorySchemaKey, + appAutoscalerInsMetricHistorySchemaKey, + appAutoscalerHealthSchemaKey } from '../../../../../../store/helpers/entity-factory'; import { ApplicationService } from '../../../../application.service'; -import { GetAppAutoscalerPolicyAction } from '../../../../../../store/actions/app-autoscaler.actions'; -import { AppAutoscalerPolicy } from '../../../../../../store/types/app-autoscaler.types'; +import { GetAppAutoscalerPolicyAction, GetAppAutoscalerScalingHistoryAction, GetAppAutoscalerHealthAction } from '../../../../../../store/actions/app-autoscaler.actions'; +import { AppAutoscalerPolicy, AppAutoscalerScalingHistory, AppAutoscalerHealth } from '../../../../../../store/types/app-autoscaler.types'; import { map } from 'rxjs/operators'; +import { + CfAppInstancesConfigService, +} from '../../../../../../shared/components/list/list-types/app-instance/cf-app-instances-config.service'; +import { ListConfig } from '../../../../../../shared/components/list/list.component.types'; @Component({ selector: 'app-auto-scaler-tab', @@ -18,8 +26,13 @@ import { map } from 'rxjs/operators'; }) export class AutoScalerTabComponent implements OnInit { + appAutoscalerHealthService: EntityService; appAutoscalerPolicyService: EntityService; + appAutoscalerScalingHistoryService: EntityService; + + appAutoscalerHealth$: Observable; appAutoscalerPolicy$: Observable; + appAutoscalerScalingHistory$: Observable; constructor( private applicationService: ApplicationService, @@ -27,6 +40,13 @@ export class AutoScalerTabComponent implements OnInit { ) { } ngOnInit() { + this.appAutoscalerHealthService = this.entityServiceFactory.create( + appAutoscalerHealthSchemaKey, + entityFactory(appAutoscalerHealthSchemaKey), + "public", + new GetAppAutoscalerHealthAction(), + false + ); this.appAutoscalerPolicyService = this.entityServiceFactory.create( appAutoscalerPolicySchemaKey, entityFactory(appAutoscalerPolicySchemaKey), @@ -34,13 +54,44 @@ export class AutoScalerTabComponent implements OnInit { new GetAppAutoscalerPolicyAction(this.applicationService.appGuid), false ); + this.appAutoscalerScalingHistoryService = this.entityServiceFactory.create( + appAutoscalerScalingHistorySchemaKey, + entityFactory(appAutoscalerScalingHistorySchemaKey), + this.applicationService.appGuid, + new GetAppAutoscalerScalingHistoryAction(this.applicationService.appGuid), + false + ); + + this.appAutoscalerHealth$ = this.appAutoscalerHealthService.entityObs$.pipe( + map(({ entity }) => { + console.log(entity) + return entity + }), + map((healthEntity, ddd) => { + console.log("appAutoscalerHealth", healthEntity, ddd) + return healthEntity && healthEntity.entity + }) + ); this.appAutoscalerPolicy$ = this.appAutoscalerPolicyService.entityObs$.pipe( - map(({ entity }) => entity), - map(policyEntity => { - console.log("appAutoscalerPolicy", policyEntity) + map(({ entity }) => { + console.log(entity) + return entity + }), + map((policyEntity, ddd) => { + console.log("appAutoscalerPolicy", policyEntity, ddd) return policyEntity && policyEntity.entity }) ); + this.appAutoscalerScalingHistory$ = this.appAutoscalerScalingHistoryService.entityObs$.pipe( + map(({ entity }) => { + console.log(entity) + return entity + }), + map((historyEntity,ddd) => { + console.log("appAutoscalerScalingHistory", historyEntity, ddd) + return historyEntity && historyEntity.entity + }) + ); } } diff --git a/src/frontend/app/store/actions/app-autoscaler.actions.ts b/src/frontend/app/store/actions/app-autoscaler.actions.ts new file mode 100644 index 0000000000..af38a3026c --- /dev/null +++ b/src/frontend/app/store/actions/app-autoscaler.actions.ts @@ -0,0 +1,103 @@ +import { RequestOptions, Headers, URLSearchParams } from '@angular/http'; + +import { + appAutoscalerHealthSchemaKey, + appAutoscalerPolicySchemaKey, + appAutoscalerScalingHistorySchemaKey, + appAutoscalerAppMetricHistorySchemaKey, + appAutoscalerInsMetricHistorySchemaKey, + entityFactory, +} from '../helpers/entity-factory'; +import { CFStartAction, ICFAction } from '../types/request.types'; + +const endpointApiHostHeader = 'x-cap-api-host'; + +export const AppAutoscalerPolicyEvents = { + GET_APP_AUTOSCALER_POLICY: '[App Autoscaler] Get autoscaler policy', + GET_APP_AUTOSCALER_POLICY_SUCCESS: '[App Autoscaler] Get autoscaler policy success', + GET_APP_AUTOSCALER_POLICY_FAILED: '[App Autoscaler] Get autoscaler policy failed' +}; + +export const AppAutoscalerScalingHistoryEvents = { + GET_APP_AUTOSCALER_SCALING_HISTORY: '[App Autoscaler] Get autoscaler scaling history', + GET_APP_AUTOSCALER_SCALING_HISTORY_SUCCESS: '[App Autoscaler] Get autoscaler scaling history success', + GET_APP_AUTOSCALER_SCALING_HISTORY_FAILED: '[App Autoscaler] Get autoscaler scaling history failed' +}; + +export const AppAutoscalerHealthEvents = { + GET_APP_AUTOSCALER_HEALTH: '[App Autoscaler] Get autoscaler health', + GET_APP_AUTOSCALER_HEALTH_SUCCESS: '[App Autoscaler] Get autoscaler health success', + GET_APP_AUTOSCALER_HEALTH_FAILED: '[App Autoscaler] Get autoscaler health failed' +}; + +export class GetAppAutoscalerHealthAction extends CFStartAction implements ICFAction { + options: RequestOptions; + constructor( + ) { + super(); + this.options = new RequestOptions(); + this.options.url = `public/health_check` + this.options.method = 'get' + this.options.headers = new Headers(); + this.options.headers.set(endpointApiHostHeader, 'scalingconsole'); + } + entity = [entityFactory(appAutoscalerHealthSchemaKey)]; + entityKey = appAutoscalerHealthSchemaKey; + paginationKey: string; + actions = [ + AppAutoscalerHealthEvents.GET_APP_AUTOSCALER_HEALTH, + AppAutoscalerHealthEvents.GET_APP_AUTOSCALER_HEALTH_SUCCESS, + AppAutoscalerHealthEvents.GET_APP_AUTOSCALER_HEALTH_FAILED + ]; +} + +export class GetAppAutoscalerPolicyAction extends CFStartAction implements ICFAction { + options: RequestOptions; + constructor( + public guid: string, + ) { + super(); + this.options = new RequestOptions(); + this.options.url = `apps/${guid}/policy` + this.options.method = 'get' + this.options.headers = new Headers(); + this.options.headers.set(endpointApiHostHeader, 'autoscaler'); + } + entity = [entityFactory(appAutoscalerPolicySchemaKey)]; + entityKey = appAutoscalerPolicySchemaKey; + paginationKey: string; + actions = [ + AppAutoscalerPolicyEvents.GET_APP_AUTOSCALER_POLICY, + AppAutoscalerPolicyEvents.GET_APP_AUTOSCALER_POLICY_SUCCESS, + AppAutoscalerPolicyEvents.GET_APP_AUTOSCALER_POLICY_FAILED + ]; +} + +export class GetAppAutoscalerScalingHistoryAction extends CFStartAction implements ICFAction { + options: RequestOptions; + constructor( + public guid: string, + ) { + super(); + this.options = new RequestOptions(); + this.options.url = `apps/${guid}/scaling_histories` + this.options.method = 'get' + this.options.headers = new Headers(); + this.options.headers.set(endpointApiHostHeader, 'autoscaler'); + this.options.params = new URLSearchParams(); + this.options.params.append('start-time', '1542124800000000000'); + this.options.params.append('end-time', '1542729600000000000'); + this.options.params.append('page', '1'); + this.options.params.append('results-per-page', '10'); + this.options.params.append('order', 'desc'); + } + entity = [entityFactory(appAutoscalerScalingHistorySchemaKey)]; + entityKey = appAutoscalerScalingHistorySchemaKey; + paginationKey: string; + flattenPagination: false; + actions = [ + AppAutoscalerScalingHistoryEvents.GET_APP_AUTOSCALER_SCALING_HISTORY, + AppAutoscalerScalingHistoryEvents.GET_APP_AUTOSCALER_SCALING_HISTORY_SUCCESS, + AppAutoscalerScalingHistoryEvents.GET_APP_AUTOSCALER_SCALING_HISTORY_FAILED + ]; +} \ No newline at end of file diff --git a/src/frontend/app/store/types/app-autoscaler.types.ts b/src/frontend/app/store/types/app-autoscaler.types.ts new file mode 100644 index 0000000000..e8cc648c91 --- /dev/null +++ b/src/frontend/app/store/types/app-autoscaler.types.ts @@ -0,0 +1,14 @@ +export interface AppAutoscalerPolicy { + guid: string; +} + +export interface AppAutoscalerHealth { + status: boolean; + error: { + cloudfoundry_autoscaler: string; + cloudfoundry_autoscaler_timestamp: string; + } +} + +export interface AppAutoscalerScalingHistory { +} diff --git a/src/frontend/packages/store/src/helpers/entity-factory.ts b/src/frontend/packages/store/src/helpers/entity-factory.ts index d31655d78a..5ba99f77ae 100644 --- a/src/frontend/packages/store/src/helpers/entity-factory.ts +++ b/src/frontend/packages/store/src/helpers/entity-factory.ts @@ -38,6 +38,9 @@ export const userFavoritesSchemaKey = 'userFavorites'; export const userProvidedServiceInstanceSchemaKey = 'userProvidedServiceInstance'; export const appAutoscalerHealthSchemaKey = 'autoscalerHealth'; export const appAutoscalerPolicySchemaKey = 'autoscalerPolicy'; +export const appAutoscalerScalingHistorySchemaKey = 'autoscalerScalingHistory'; +export const appAutoscalerAppMetricHistorySchemaKey = 'autoscalerAppMetricHistory'; +export const appAutoscalerInsMetricHistorySchemaKey = 'autoscalerInsMetricHistory'; export const spaceWithOrgKey = 'spaceWithOrg'; export const serviceInstancesWithSpaceSchemaKey = 'serviceInstancesWithSpace'; @@ -321,6 +324,15 @@ entityCache[appAutoscalerPolicySchemaKey] = AppAutoscalerPolicySchema; const AppAutoscalerHealthSchema = new EntitySchema(appAutoscalerHealthSchemaKey, {}, { idAttribute: getAPIResourceGuid }); entityCache[appAutoscalerHealthSchemaKey] = AppAutoscalerHealthSchema; +const AppAutoscalerScalingHistorySchema = new EntitySchema(appAutoscalerScalingHistorySchemaKey, {}, { idAttribute: getAPIResourceGuid }); +entityCache[appAutoscalerScalingHistorySchemaKey] = AppAutoscalerScalingHistorySchema; + +const AppAutoscalerAppMetricSchema = new EntitySchema(appAutoscalerAppMetricHistorySchemaKey, {}, { idAttribute: getAPIResourceGuid }); +entityCache[appAutoscalerAppMetricHistorySchemaKey] = AppAutoscalerAppMetricSchema; + +const AppAutoscalerInsMetricSchema = new EntitySchema(appAutoscalerInsMetricHistorySchemaKey, {}, { idAttribute: getAPIResourceGuid }); +entityCache[appAutoscalerInsMetricHistorySchemaKey] = AppAutoscalerInsMetricSchema; + const ApplicationEntitySchema = new EntitySchema( applicationSchemaKey, { diff --git a/src/frontend/packages/store/src/reducers/api-request-reducers.generator.ts b/src/frontend/packages/store/src/reducers/api-request-reducers.generator.ts index 949d2ed7bf..f01f867bea 100644 --- a/src/frontend/packages/store/src/reducers/api-request-reducers.generator.ts +++ b/src/frontend/packages/store/src/reducers/api-request-reducers.generator.ts @@ -31,6 +31,9 @@ import { userProvidedServiceInstanceSchemaKey, appAutoscalerPolicySchemaKey, appAutoscalerHealthSchemaKey, + appAutoscalerScalingHistorySchemaKey, + appAutoscalerAppMetricHistorySchemaKey, + appAutoscalerInsMetricHistorySchemaKey, } from '../helpers/entity-factory'; import { endpointStoreNames } from '../types/endpoint.types'; import { IRequestDataState, IRequestState } from '../types/entity.types'; @@ -121,6 +124,9 @@ const entities = [ userProvidedServiceInstanceSchemaKey, appAutoscalerPolicySchemaKey, appAutoscalerHealthSchemaKey, + appAutoscalerScalingHistorySchemaKey, + appAutoscalerAppMetricHistorySchemaKey, + appAutoscalerInsMetricHistorySchemaKey, ]; export function registerAPIRequestEntity(schemaKey: string) { diff --git a/src/frontend/packages/store/src/types/entity.types.ts b/src/frontend/packages/store/src/types/entity.types.ts index d5fd999804..6cc4f1e8fa 100644 --- a/src/frontend/packages/store/src/types/entity.types.ts +++ b/src/frontend/packages/store/src/types/entity.types.ts @@ -48,6 +48,9 @@ import { userProvidedServiceInstanceSchemaKey, appAutoscalerHealthSchemaKey, appAutoscalerPolicySchemaKey, + appAutoscalerScalingHistorySchemaKey, + appAutoscalerAppMetricHistorySchemaKey, + appAutoscalerInsMetricHistorySchemaKey, } from '../helpers/entity-factory'; import { RequestInfoState } from '../reducers/api-request-reducer/types'; import { APIResource } from './api.types'; @@ -143,4 +146,7 @@ export const defaultCfEntitiesState = { [userProvidedServiceInstanceSchemaKey]: [], [appAutoscalerHealthSchemaKey]: {}, [appAutoscalerPolicySchemaKey]: {}, + [appAutoscalerScalingHistorySchemaKey]: {}, + [appAutoscalerAppMetricHistorySchemaKey]: {}, + [appAutoscalerInsMetricHistorySchemaKey]: {}, }; From 02a5bbbf43063e2faff047aa00dcd8c434286fa7 Mon Sep 17 00:00:00 2001 From: zyjiaobj Date: Wed, 28 Nov 2018 15:52:34 +0800 Subject: [PATCH 04/98] [autoscaler] add autoscaler tables --- .../auto-scaler-tab.component.html | 141 +++++++++++++++++- .../auto-scaler-tab.component.scss | 28 +++- .../auto-scaler-tab.component.ts | 4 + 3 files changed, 165 insertions(+), 8 deletions(-) diff --git a/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.html b/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.html index 7687ef46a8..571a40617e 100644 --- a/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.html +++ b/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.html @@ -9,13 +9,27 @@ - + + + + Instances + + + + + + + Limits @@ -24,32 +38,145 @@ + + + + Latest Metrics + + + + + + - + Scaling Rules + + + + + + + Scheduled Limit Rules + + + +
+
- +
{{ scalingHistory.total_results}}
diff --git a/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.scss b/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.scss index 1685de240a..b8ec9fa55c 100644 --- a/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.scss +++ b/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.scss @@ -1,6 +1,5 @@ .app-auto-scaler { display: flex; - height: 100%; position: relative; width: 100%; } @@ -15,3 +14,30 @@ } } } + +app-tile-grid { + width: 100% +} + +table { + width: 100% +} + +.app-auto-scaler-policy-left { + flex: 0 0 40%; +} + +.app-auto-scaler-tile-1of2 { + flex: 0 0 50%; +} + +.app-auto-scaler-tile-1of6 { + flex: 0 0 16.78%; +} + +.app-auto-scaler-limit { + display: inherit; + mat-card { + width: 50% + } +} \ No newline at end of file diff --git a/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.ts b/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.ts index c12dc35545..d6cae060f6 100644 --- a/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.ts +++ b/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.ts @@ -34,6 +34,10 @@ export class AutoScalerTabComponent implements OnInit { appAutoscalerPolicy$: Observable; appAutoscalerScalingHistory$: Observable; + scalingRuleColumns: string[] = ['metric', 'condition', 'action'] + specificDateColumns: string[] = ['from', 'to', 'init', 'min', 'max'] + recurringScheduleColumns: string[] = ['effect', 'repeat', 'from', 'to', 'init', 'min', 'max'] + constructor( private applicationService: ApplicationService, private entityServiceFactory: EntityServiceFactory, From 4d66acb48846e79a86b979cf3a331b4c24e0d8e7 Mon Sep 17 00:00:00 2001 From: zyjiaobj Date: Thu, 29 Nov 2018 14:08:02 +0800 Subject: [PATCH 05/98] [autoscaler] request app metrics --- .../auto-scaler-tab.component.html | 16 ++--- .../auto-scaler-tab.component.ts | 66 ++++++++++++++----- .../store/actions/app-autoscaler.actions.ts | 38 ++++++++++- .../app/store/types/app-autoscaler.types.ts | 3 + .../packages/store/src/effects/api.effects.ts | 21 ++++++ .../store/src/helpers/entity-factory.ts | 12 ++-- .../api-request-reducers.generator.ts | 8 +-- .../packages/store/src/types/entity.types.ts | 8 +-- .../packages/store/src/types/request.types.ts | 1 + 9 files changed, 134 insertions(+), 39 deletions(-) diff --git a/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.html b/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.html index 571a40617e..16d549499a 100644 --- a/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.html +++ b/src/frontend/app/features/applications/application/application-tabs-base/tabs/auto-scaler-tab/auto-scaler-tab.component.html @@ -53,17 +53,17 @@