From a8d3e1b8c759c21227690a425552a245da883e97 Mon Sep 17 00:00:00 2001 From: zhaoxiangjun666 Date: Thu, 10 Sep 2020 14:01:50 +0800 Subject: Support for Test Topology Auto Design- Service Import MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add some test code and use lombok in catalog-model Test Topology Auto Design (NFV Testing Automatic Platform) Delete useless test code and add test code for new function Issue-ID: SDC-3179 Issue-ID: SDC-3085 Signed-off-by: zhaoxiangjun666 Change-Id: I7f555633a00848c273014caa18ea0e30d0b22113 --- catalog-ui/src/app/models/components/component.ts | 13 ++++++-- catalog-ui/src/app/models/components/service.ts | 35 ++++++++++++++++++++ .../src/app/ng2/pages/home/home.component.html | 10 ++++++ .../src/app/ng2/pages/home/home.component.ts | 18 ++++++++++ .../app/services/components/component-service.ts | 38 ++++++++++++++++++---- catalog-ui/src/app/utils/component-factory.ts | 6 ++++ .../workspace/tabs/general/general-view-model.ts | 17 ++++++++-- .../view-models/workspace/workspace-view-model.ts | 9 ++++- 8 files changed, 134 insertions(+), 12 deletions(-) (limited to 'catalog-ui') diff --git a/catalog-ui/src/app/models/components/component.ts b/catalog-ui/src/app/models/components/component.ts index b76d29c8c6..a0706b4157 100644 --- a/catalog-ui/src/app/models/components/component.ts +++ b/catalog-ui/src/app/models/components/component.ts @@ -233,6 +233,11 @@ export abstract class Component implements IComponent { this.handleTags(); return this.componentService.createComponent(this); }; + + public importComponentOnServer = (): ng.IPromise => { + this.handleTags(); + return this.componentService.importComponent(this); + }; public updateComponent = ():ng.IPromise => { this.handleTags(); @@ -243,8 +248,12 @@ export abstract class Component implements IComponent { return this.componentService.validateName(newName, subtype); }; - public downloadArtifact = (artifactId:string):ng.IPromise => { - return this.componentService.downloadArtifact(this.uniqueId, artifactId); + public downloadArtifact = (artifactId: string): ng.IPromise => { + if(this.vendorName === 'IsService'){ + return this.componentService.downloadArtifact(this.uniqueId, artifactId, this.vendorName); + }else{ + return this.componentService.downloadArtifact(this.uniqueId, artifactId); + } }; public addOrUpdateArtifact = (artifact:ArtifactModel):ng.IPromise => { diff --git a/catalog-ui/src/app/models/components/service.ts b/catalog-ui/src/app/models/components/service.ts index 911a43204f..d11a06abdf 100644 --- a/catalog-ui/src/app/models/components/service.ts +++ b/catalog-ui/src/app/models/components/service.ts @@ -27,6 +27,7 @@ import {IServiceService} from "../../services/components/service-service"; import {Component, PropertyModel, DisplayModule, InputsAndProperties, InputModel, InstancesInputsOrPropertiesMapData, InstancesInputsPropertiesMap, Distribution, DistributionComponent, ArtifactGroupModel} from "../../models"; import {ArtifactGroupType} from "../../utils/constants"; +import {FileUploadModel} from "../../directives/file-upload/file-upload"; import {ComponentMetadata} from "../component-metadata"; import {ForwardingPath} from "app/models/forwarding-path"; @@ -42,6 +43,15 @@ export class Service extends Component { public environmentContext:string; public instantiationType:string; public forwardingPaths:{ [key:string]:ForwardingPath } = {}; + public payloadData: string; + public payloadName: string; + public importedFile: FileUploadModel; + + // Onboarding parameters + public csarUUID: string; + public csarVersion: string; + public csarPackageType: string; + public packageId: string; constructor(componentService:IServiceService, $q:ng.IQService, component?:Service) { super(componentService, $q, component); @@ -56,15 +66,40 @@ export class Service extends Component { this.serviceFunction = component.serviceFunction; this.instantiationType = component.instantiationType; this.environmentContext = component.environmentContext; + this.payloadData = component.payloadData ? component.payloadData : undefined; + this.payloadName = component.payloadName ? component.payloadName : undefined; + this.csarUUID = component.csarUUID; + this.csarVersion = component.csarVersion; if (component.categories && component.categories[0]) { this.mainCategory = component.categories[0].name; this.selectedCategory = this.mainCategory; + this.importedFile = component.importedFile; } } this.componentService = componentService; this.iconSprite = "sprite-services-icons"; } + public importComponentOnServer = (): ng.IPromise => { + let deferred = this.$q.defer(); + let onSuccess = (component: Service): void => { + this.payloadData = undefined; + this.payloadName = undefined; + deferred.resolve(component); + }; + let onError = (error: any): void => { + deferred.reject(error); + }; + + this.handleTags(); + if (this.importedFile) { + this.payloadData = this.importedFile.base64; + this.payloadName = this.importedFile.filename; + } + this.componentService.importComponent(this).then(onSuccess, onError); + return deferred.promise; + }; + public getDistributionsList = ():ng.IPromise> => { return this.componentService.getDistributionsList(this.uuid); }; diff --git a/catalog-ui/src/app/ng2/pages/home/home.component.html b/catalog-ui/src/app/ng2/pages/home/home.component.html index 1c8c2b4373..3bdf54e694 100644 --- a/catalog-ui/src/app/ng2/pages/home/home.component.html +++ b/catalog-ui/src/app/ng2/pages/home/home.component.html @@ -48,6 +48,16 @@ (fileUpload)="onImportVf($event)" [convertToBase64]="true" > + diff --git a/catalog-ui/src/app/ng2/pages/home/home.component.ts b/catalog-ui/src/app/ng2/pages/home/home.component.ts index 1b69eba929..77fd3b5ae4 100644 --- a/catalog-ui/src/app/ng2/pages/home/home.component.ts +++ b/catalog-ui/src/app/ng2/pages/home/home.component.ts @@ -138,6 +138,24 @@ export class HomeComponent implements OnInit { } } + public onImportService(file: any): void { + if (file && file.filename) { + // Check that the file has valid extension. + const fileExtension: string = file.filename.split(".").pop(); + if (this.sdcConfig.csarFileExtension.indexOf(fileExtension.toLowerCase()) !== -1) { + this.$state.go('workspace.general', { + type: ComponentType.SERVICE.toLowerCase(), + importedFile: file, + serviceType: 'Service' + }); + } else { + const title: string = this.translateService.translate('NEW_SERVICE_RESOURCE_ERROR_VALID_CSAR_EXTENSIONS_TITLE'); + const message: string = this.translateService.translate('NEW_SERVICE_RESOURCE_ERROR_VALID_CSAR_EXTENSIONS', {extensions: this.sdcConfig.csarFileExtension}); + this.modalService.openWarningModal(title, message, 'error-invalid-csar-ext'); + } + } + }; + public openCreateModal(componentType: string, importedFile: any): void { if (importedFile) { this.initEntities(true); // Return from import diff --git a/catalog-ui/src/app/services/components/component-service.ts b/catalog-ui/src/app/services/components/component-service.ts index c7ab975e6e..bece12d4f0 100644 --- a/catalog-ui/src/app/services/components/component-service.ts +++ b/catalog-ui/src/app/services/components/component-service.ts @@ -32,6 +32,8 @@ export interface IComponentService { changeLifecycleState(component:Component, state:string, userRemarks:any):ng.IPromise ; validateName(newName:string, subtype?:string):ng.IPromise; createComponent(component:Component):ng.IPromise; + //importComponent + importComponent(component: Component): ng.IPromise; addOrUpdateArtifact(componentId:string, artifact:ArtifactModel):ng.IPromise; deleteArtifact(componentId:string, artifact:string, artifactLabel):ng.IPromise; addProperty(componentId:string, property:PropertyModel):ng.IPromise; @@ -48,7 +50,7 @@ export interface IComponentService { createComponentInstance(componentId:string, componentInstance:ComponentInstance):ng.IPromise; updateComponentInstance(componentId:string, componentInstance:ComponentInstance):ng.IPromise; updateMultipleComponentInstances(componentId:string, instances:Array):ng.IPromise< Array>; - downloadArtifact(componentId:string, artifactId:string):ng.IPromise; + downloadArtifact(componentId: string, artifactId: string, vendorName?: string): ng.IPromise; uploadInstanceEnvFile(componentId:string, instanceId:string, artifact:ArtifactModel):ng.IPromise; downloadInstanceArtifact(componentId:string, instanceId:string, artifactId:string):ng.IPromise; deleteComponentInstance(componentId:string, componentInstanceId:string):ng.IPromise; @@ -206,6 +208,20 @@ export class ComponentService implements IComponentService { }); return deferred.promise; }; + + public importComponent = (component: Component): ng.IPromise => { + component.vendorName = "xfr"; + component.vendorRelease = "xfr"; + let deferred = this.$q.defer(); + let headerObj = this.getHeaderMd5(component); + this.restangular.customPOST(JSON.stringify(component), 'importService', {}, headerObj).then((response: Component) => { + let component: Component = this.createComponentObject(response); + deferred.resolve(component); + }, (err) => { + deferred.reject(err); + }); + return deferred.promise; + }; public validateName = (newName:string, subtype?:string):ng.IPromise => { let deferred = this.$q.defer(); @@ -244,13 +260,21 @@ export class ComponentService implements IComponentService { return deferred.promise; }; - public downloadArtifact = (componentId:string, artifactId:string):ng.IPromise => { + public downloadArtifact = (componentId: string, artifactId: string, vendorName?: string): ng.IPromise => { let deferred = this.$q.defer(); - this.restangular.one(componentId).one("artifacts").one(artifactId).get().then((response:any) => { - deferred.resolve(response.plain()); - }, (err)=> { - deferred.reject(err); - }); + if(vendorName === 'IsService'){ + this.restangular.one('importService').one(componentId).one("artifacts").one(artifactId).get().then((response: any) => { + deferred.resolve(response.plain()); + }, (err) => { + deferred.reject(err); + }); + }else{ + this.restangular.one(componentId).one("artifacts").one(artifactId).get().then((response: any) => { + deferred.resolve(response.plain()); + }, (err) => { + deferred.reject(err); + }); + } return deferred.promise; }; diff --git a/catalog-ui/src/app/utils/component-factory.ts b/catalog-ui/src/app/utils/component-factory.ts index 5fda9c8db2..fd82c27dd8 100644 --- a/catalog-ui/src/app/utils/component-factory.ts +++ b/catalog-ui/src/app/utils/component-factory.ts @@ -185,6 +185,12 @@ export class ComponentFactory { }; + public importComponentOnServer = (componentObject: Component): ng.IPromise => { + let component: Component = this.createComponent(componentObject); + return component.importComponentOnServer(); + + }; + public getComponentWithMetadataFromServer = (componentType:string, componentId:string):ng.IPromise => { let deferred = this.$q.defer(); let component = this.createEmptyComponent(componentType); diff --git a/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts b/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts index 87937dd761..e10dc98fac 100644 --- a/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts +++ b/catalog-ui/src/app/view-models/workspace/tabs/general/general-view-model.ts @@ -219,7 +219,7 @@ export class GeneralViewModel { this.$scope.importCsarProgressKey = "importCsarProgressKey"; - this.$scope.browseFileLabel = this.$scope.component.isResource() && (this.$scope.component).resourceType === ResourceType.VF ? 'Upload File:' : 'Upload VFC:'; + this.$scope.browseFileLabel = (this.$scope.component.isResource() && ((this.$scope.component).resourceType === ResourceType.VF || (this.$scope.component).resourceType === 'SRVC')) || this.$scope.component.isService() ? 'Upload File:' : 'Upload VFC:'; this.$scope.progressService = this.progressService; this.$scope.componentCategories = new componentCategories(); this.$scope.componentCategories.selectedCategory = this.$scope.component.selectedCategory; @@ -245,6 +245,15 @@ export class GeneralViewModel { this.$scope.isShowFileBrowse = true; } } else if(this.$scope.component.isService()){ + let service: Service = this.$scope.component; + console.log(service.name + ": " + service.csarUUID); + if (service.importedFile) { // Component has imported file. + this.$scope.isShowFileBrowse = true; + (this.$scope.component).serviceType = 'Service'; + } + if (this.$scope.isEditMode() && service.serviceType == 'Service' && !service.csarUUID) { + this.$scope.isShowFileBrowse = true; + } // Init Instantiation types this.$scope.initInstantiationTypes(); } @@ -497,7 +506,11 @@ export class GeneralViewModel { return; } - const subtype:string = ComponentType.RESOURCE == this.$scope.componentType ? this.$scope.component.getComponentSubType() : undefined; + + let subtype:string = ComponentType.RESOURCE == this.$scope.componentType ? this.$scope.component.getComponentSubType() : undefined; + if (subtype == "SRVC") { + subtype = "VF" + } const onFailed = (response) => { // console.info('onFaild', response); diff --git a/catalog-ui/src/app/view-models/workspace/workspace-view-model.ts b/catalog-ui/src/app/view-models/workspace/workspace-view-model.ts index 11667283b2..e132d53eaf 100644 --- a/catalog-ui/src/app/view-models/workspace/workspace-view-model.ts +++ b/catalog-ui/src/app/view-models/workspace/workspace-view-model.ts @@ -27,6 +27,7 @@ import { IUserProperties, IAppMenu, Resource, + Service, Component, Plugin, PluginsConfiguration, @@ -431,8 +432,14 @@ export class WorkspaceViewModel { components: this.components }, {inherit: false}); }; + + console.log(this.$scope.component, "this.$scope.component") + if ((this.$scope.component).serviceType == "Service") { + this.ComponentFactory.importComponentOnServer(this.$scope.component).then(onSuccessCreate, onFailed); + } else { + this.ComponentFactory.createComponentOnServer(this.$scope.component).then(onSuccessCreate, onFailed); + } - this.ComponentFactory.createComponentOnServer(this.$scope.component).then(onSuccessCreate, onFailed); }; -- cgit 1.2.3-korg