node_modules/
jspm_packages/
dist/
+dist10/
# TypeScript v1 declaration files
typings/
+<?xml version="1.0" encoding="UTF-8"?>
<!--
============LICENSE_START==========================================
===================================================================
See the License for the specific language governing permissions and
limitations under the License.
============LICENSE_END============================================ -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onap.ccsdk.cds</groupId>
<artifactId>ui</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>application</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>cds-ui-application</name>
+<?xml version="1.0" encoding="UTF-8"?>
<!--
============LICENSE_START==========================================
===================================================================
See the License for the specific language governing permissions and
limitations under the License.
============LICENSE_END============================================ -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onap.ccsdk.cds</groupId>
<artifactId>ui</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>ui-client</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>cds-ui-client</name>
}
};
-export const LoopbackConfig = {
- url: "http://127.0.0.1:3000",
- authtoken: "ccsdkapps"
-}
export const ResourceDictionaryURLs = {
saveResourceDictionary: '/resourcedictionary/save',
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders, HttpResponse, HttpHeaderResponse } from '@angular/common/http';
import { Observable } from 'rxjs';
-import { LoopbackConfig } from '../../constants/app-constants';
@Injectable()
export class ApiService {
name?: string;
files?: any;
filesData?: any;
+ uploadedFileName?: string;
isLoadSuccess?: boolean;
isUpdateSuccess?: boolean;
isSaveSuccess?: boolean;
blueprint: action.payload.blueprint,
name: action.payload.name,
files: action.payload.files,
- filesData: action.payload.filesData
+ filesData: action.payload.filesData,
+ uploadedFileName: action.payload.uploadedFileName
}
default:
return state;
private fileObject: any;
private tocsaMetadaData: any;
metadata: IMetaData;
+ uploadedFileName: string;
private transformer = (node: Node, level: number) => {
return {
this.filesData = blueprintdata.filesData;
this.dataSource.data = this.filesTree;
this.blueprintName = blueprintdata.name;
+ this.uploadedFileName = blueprintdata.uploadedFileName;
let blueprint = [];
for (let key in this.blueprintdata) {
if (this.blueprintdata.hasOwnProperty(key)) {
this.artifactVersion = metadatavalues[4];
this.editor.getEditor().getSession().setTabSize(2);
this.editor.getEditor().getSession().setUseWrapMode(true);
+ this.editor.getEditor().getSession().setValue("");
this.setEditorMode();
})
}
blueprint: this.blueprint,
name: this.blueprintName,
files: this.filesTree,
- filesData: this.filesData
+ filesData: this.filesData,
+ uploadedFileName: this.uploadedFileName
}
this.store.dispatch(new SetBlueprintState(blueprintState));
// console.log(this.text);
this.filetoDelete = file.name;
this.currentFilePath = this.currentFilePath + this.selectedFile;
this.filesData.forEach((fileNode) => {
- if (fileNode.name.includes(file.name)) {
+ if (fileNode.name.includes(file.name) && fileNode.name == this.currentFilePath) {
this.text = fileNode.data;
}
})
this.paths = [];
for (var file in zip.files) {
this.fileObject = {
- name: zip.files[file].name,
+ // name: zip.files[file].name,
+ // name: this.uploadedFileName + '/' + zip.files[file].name,
+ name: this.uploadedFileName + zip.files[file].name,
data: ''
};
const value = <any>await zip.files[file].async('string');
if (this.validfile) {
this.fetchTOSACAMetadata();
+ this.filesData = this.paths;
this.tree = this.arrangeTreeData(this.paths);
} else {
alert('Please update proper file with TOSCA metadata');
import { HttpClient } from '@angular/common/http';
import { Observable, observable } from 'rxjs';
import { ApiService } from '../../../../common/core/services/api.service';
-import { LoopbackConfig } from '../../../../common/constants/app-constants';
import { saveAs } from 'file-saver';
@Injectable()
}
enrich(uri: string, body: FormData): Observable<any> {
- return this.api.post(LoopbackConfig.url + uri, body, { responseType: 'blob' });
+ return this.api.post(uri, body, { responseType: 'blob' });
}
downloadCBA(uri: string): string {
- this.api.get(LoopbackConfig.url + uri, { responseType: 'blob' })
+ this.api.get(uri, { responseType: 'blob' })
.subscribe(response => {
let blob = new Blob([response], { 'type': "application/octet-stream" });
saveAs(blob, "CBA.zip");
}
post(uri: string, body: any | null, options?: any): Observable<any> {
- return this.api.post(LoopbackConfig.url + uri, body, options);
+ return this.api.post(uri, body, options);
}
deployPost(uri: string, body: any | null, options?: any): Observable<any> {
- return this.api.post(LoopbackConfig.url + uri, body, { responseType: 'text' });
+ return this.api.post(uri, body, { responseType: 'text' });
}
}
\ No newline at end of file
blueprint: data,
name: this.blueprintName,
files: this.tree,
- filesData: this.paths
+ filesData: this.paths,
+ uploadedFileName: this.uploadedFileName
}
this.store.dispatch(new SetBlueprintState(blueprintState))
// this.store.dispatch(new LoadBlueprintSuccess(data));
async buildFileViewData(zip) {
this.validfile = false;
this.paths = [];
+ console.log(zip.files);
for (var file in zip.files) {
+ console.log("name: " +zip.files[file].name);
this.fileObject = {
// nameForUIDisplay: this.uploadedFileName + '/' + zip.files[file].name,
// name: zip.files[file].name,
import { HttpClient } from '@angular/common/http';
import { Observable, observable } from 'rxjs';
import { ApiService } from '../../../common/core/services/api.service';
-import { LoopbackConfig } from '../../../common/constants/app-constants';
@Injectable()
export class TestTemplateService {
import { HttpClient } from '@angular/common/http';
import { Observable, observable } from 'rxjs';
import { ApiService } from '../../../../common/core/services/api.service';
-import { LoopbackConfig, ResourceDictionaryURLs } from '../../../../common/constants/app-constants';
+import { ResourceDictionaryURLs } from '../../../../common/constants/app-constants';
@Injectable()
export class ExsistingModelService {
}
searchByTags(tag) {
- return this.api.get(LoopbackConfig.url+ ResourceDictionaryURLs.searchResourceDictionaryByTags + '/' + tag);
+ return this.api.get(ResourceDictionaryURLs.searchResourceDictionaryByTags + '/' + tag);
}
}
\ No newline at end of file
* ONAP : CDS
* ================================================================================
* Copyright 2019 TechMahindra
+*
+* Modifications Copyright (C) 2019 IBM
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ONAP : CDS
* ================================================================================
* Copyright 2019 TechMahindra
+*
+* Modifications Copyright (C) 2019 IBM
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ONAP : CDS
* ================================================================================
* Copyright 2019 TechMahindra
+*
+* Modifications Copyright (C) 2019 IBM
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ONAP : CDS
* ================================================================================
* Copyright 2019 TechMahindra
+*
+* Modifications Copyright (C) 2019 IBM
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ONAP : CDS
* ================================================================================
* Copyright 2019 TechMahindra
+*
+* Modifications Copyright (C) 2019 IBM
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ONAP : CDS
* ================================================================================
* Copyright 2019 TechMahindra
+*
+* Modifications Copyright (C) 2019 IBM
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ONAP : CDS\r
* ================================================================================\r
* Copyright 2019 TechMahindra\r
+*\r
+* Modifications Copyright (C) 2019 IBM\r
*=================================================================================\r
* Licensed under the Apache License, Version 2.0 (the "License");\r
* you may not use this file except in compliance with the License.\r
* ONAP : CDS\r
* ================================================================================\r
* Copyright 2019 TechMahindra\r
+*\r
+* Modifications Copyright (C) 2019 IBM\r
*=================================================================================\r
* Licensed under the Apache License, Version 2.0 (the "License");\r
* you may not use this file except in compliance with the License.\r
* ONAP : CDS\r
* ================================================================================\r
* Copyright 2019 TechMahindra\r
+*\r
+* Modifications Copyright (C) 2019 IBM\r
*=================================================================================\r
* Licensed under the Apache License, Version 2.0 (the "License");\r
* you may not use this file except in compliance with the License.\r
* ONAP : CDS\r
* ================================================================================\r
* Copyright 2019 TechMahindra\r
+*\r
+* Modifications Copyright (C) 2019 IBM\r
*=================================================================================\r
* Licensed under the Apache License, Version 2.0 (the "License");\r
* you may not use this file except in compliance with the License.\r
* ONAP : CDS
* ================================================================================
* Copyright 2019 TechMahindra
+*
+* Modifications Copyright (C) 2019 IBM
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ONAP : CDS
* ================================================================================
* Copyright 2019 TechMahindra
+*
+* Modifications Copyright (C) 2019 IBM
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ONAP : CDS
* ================================================================================
* Copyright 2019 TechMahindra
+*
+* Modifications Copyright (C) 2019 IBM
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ONAP : CDS
* ================================================================================
* Copyright 2019 TechMahindra
+*
+* Modifications Copyright (C) 2019 IBM
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ONAP : CDS
* ================================================================================
* Copyright 2019 TechMahindra
+*
+* Modifications Copyright (C) 2019 IBM
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ONAP : CDS
* ================================================================================
* Copyright 2019 TechMahindra
+*
+* Modifications Copyright (C) 2019 IBM
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ONAP : CDS
* ================================================================================
* Copyright 2019 TechMahindra
+*
+* Modifications Copyright (C) 2019 IBM
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ONAP : CDS
* ================================================================================
* Copyright 2019 TechMahindra
+*
+* Modifications Copyright (C) 2019 IBM
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ONAP : CDS
* ================================================================================
* Copyright 2019 TechMahindra
+*
+* Modifications Copyright (C) 2019 IBM
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ONAP : CDS
* ================================================================================
* Copyright 2019 TechMahindra
+*
+* Modifications Copyright (C) 2019 IBM
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ONAP : CDS
* ================================================================================
* Copyright 2019 TechMahindra
+*
+* Modifications Copyright (C) 2019 IBM
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ONAP : CDS
* ================================================================================
* Copyright 2019 TechMahindra
+*
+* Modifications Copyright (C) 2019 IBM
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ONAP : CDS
* ================================================================================
* Copyright (C) 2019 TechMahindra
+*
+* Modifications Copyright (C) 2019 IBM
* =================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ONAP : CDS
* ================================================================================
* Copyright (C) 2019 TechMahindra
+*
+* Modifications Copyright (C) 2019 IBM
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ONAP : CDS
* ================================================================================
* Copyright (C) 2019 TechMahindra
+*
+* Modifications Copyright (C) 2019 IBM
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ONAP : CDS
* ================================================================================
* Copyright (C) 2019 TechMahindra
+*
+* Modifications Copyright (C) 2019 IBM
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ONAP : CDS
* ================================================================================
* Copyright (C) 2019 TechMahindra
+*
+* Modifications Copyright (C) 2019 IBM
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ONAP : CDS
* ================================================================================
* Copyright (C) 2019 TechMahindra
+*
+* Modifications Copyright (C) 2019 IBM
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import { HttpClient } from '@angular/common/http';
import { Observable, observable } from 'rxjs';
import { ApiService } from '../../../common/core/services/api.service';
-import { LoopbackConfig, ResourceDictionaryURLs } from '../../../common/constants/app-constants';
+import { ResourceDictionaryURLs } from '../../../common/constants/app-constants';
@Injectable()
export class ResourceEditService {
}
saveResource(resource) {
- return this.api.post(LoopbackConfig.url+ ResourceDictionaryURLs.saveResourceDictionary, resource);
+ return this.api.post(ResourceDictionaryURLs.saveResourceDictionary, resource);
}
}
\ No newline at end of file
* ONAP : CDS
* ================================================================================
* Copyright 2019 TechMahindra
+*
+* Modifications Copyright (C) 2019 IBM
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ONAP : CDS\r
* ================================================================================\r
* Copyright 2019 TechMahindra\r
+*\r
+* Modifications Copyright (C) 2019 IBM\r
*=================================================================================\r
* Licensed under the Apache License, Version 2.0 (the "License");\r
* you may not use this file except in compliance with the License.\r
* ONAP : CDS
* ================================================================================
* Copyright 2019 TechMahindra
+*
+* Modifications Copyright (C) 2019 IBM
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ONAP : CDS
* ================================================================================
* Copyright 2019 TechMahindra
+*
+* Modifications Copyright (C) 2019 IBM
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ONAP : CDS
* ================================================================================
* Copyright 2019 TechMahindra
+*
+* Modifications Copyright (C) 2019 IBM
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ONAP : CDS\r
* ================================================================================\r
* Copyright 2019 TechMahindra\r
+*\r
+* Modifications Copyright (C) 2019 IBM\r
*=================================================================================\r
* Licensed under the Apache License, Version 2.0 (the "License");\r
* you may not use this file except in compliance with the License.\r
* ONAP : CDS
* ================================================================================
* Copyright 2019 TechMahindra
+*
+* Modifications Copyright (C) 2019 IBM
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* ONAP : CDS
* ================================================================================
* Copyright (C) 2019 TechMahindra
+*
+* Modifications Copyright (C) 2019 IBM
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
+<?xml version="1.0" encoding="UTF-8"?>
<!--
============LICENSE_START==========================================
===================================================================
See the License for the specific language governing permissions and
limitations under the License.
============LICENSE_END============================================ -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
- <version>1.2.2-SNAPSHOT</version>
+ <version>1.3.0-SNAPSHOT</version>
<relativePath/>
</parent>
<groupId>org.onap.ccsdk.cds</groupId>
<artifactId>ui</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>cds-ui-parent</name>
<module>application</module>
</modules>
-</project>
\ No newline at end of file
+</project>
--- /dev/null
+export const controllerApiConfig = Object.freeze({
+ url: process.env.API_BLUEPRINT_CONTROLLER_BASE_URL || "http://localhost:8080/api/v1",
+ authToken: process.env.API_BLUEPRINT_CONTROLLER_AUTH_TOKEN || "Basic Y2NzZGthcHBzOmNjc2RrYXBwcw=="
+});
+
+export const processorApiConfig = Object.freeze({
+ url: process.env.API_BLUEPRINT_PROCESSOR_BASE_URL || "http://localhost:8081/api/v1",
+ authToken: process.env.API_BLUEPRINT_PROCESSOR_AUTH_TOKEN || "Basic Y2NzZGthcHBzOmNjc2RrYXBwcw=="
+});
\ No newline at end of file
+<?xml version="1.0" encoding="UTF-8"?>
<!--
============LICENSE_START==========================================
===================================================================
See the License for the specific language governing permissions and
limitations under the License.
============LICENSE_END============================================ -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onap.ccsdk.cds</groupId>
<artifactId>ui</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>ui-server</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>cds-ui-server</name>
import * as fs from 'fs';
import * as multiparty from 'multiparty';
import * as request_lib from 'request';
-
-const REST_BLUEPRINT_CONTROLLER_BASE_URL = process.env.REST_BLUEPRINT_CONTROLLER_BASE_URL || "http://localhost:8080/api/v1";
-const REST_BLUEPRINT_CONTROLLER_BASIC_AUTH_HEADER = process.env.REST_BLUEPRINT_CONTROLLER_BASIC_AUTH_HEADER || "Basic Y2NzZGthcHBzOmNjc2RrYXBwcw==";
-const REST_BLUEPRINT_PROCESSOR_BASE_URL= process.env.REST_BLUEPRINT_PROCESSOR_BASE_URL ||"http://localhost:8081/api/v1";
-const MULTIPART_FORM_UPLOAD_DIR = process.env.MULTIPART_FORM_UPLOAD_DIR || "/tmp";
+import {controllerApiConfig, processorApiConfig} from '../../config/app-config';
export class BlueprintRestController {
constructor(
},
})
async getall() {
- return await this.bpservice.getAllblueprints(REST_BLUEPRINT_CONTROLLER_BASIC_AUTH_HEADER);
+ return await this.bpservice.getAllblueprints();
}
@post('/create-blueprint')
): Promise<Response> {
return new Promise((resolve, reject) => {
this.getFileFromMultiPartForm(request).then(file=>{
- this.uploadFileToBlueprintController(file, REST_BLUEPRINT_CONTROLLER_BASE_URL+"/blueprint-model/", response).then(resp=>{
+ this.uploadFileToBlueprintController(file, "/blueprint-model/", response).then(resp=>{
resolve(resp);
}, err=>{
reject(err);
});
});
}
+
@post('/publish')
async publish(
@requestBody({
): Promise<Response> {
return new Promise((resolve, reject) => {
this.getFileFromMultiPartForm(request).then(file=>{
- this.uploadFileToBlueprintController(file, REST_BLUEPRINT_CONTROLLER_BASE_URL+"/blueprint-model/publish/", response).then(resp=>{
+ this.uploadFileToBlueprintController(file, "/blueprint-model/publish/", response).then(resp=>{
resolve(resp);
}, err=>{
reject(err);
});
});
}
+
@post('/enrich-blueprint')
async enrich(
@requestBody({
): Promise<Response> {
return new Promise((resolve, reject) => {
this.getFileFromMultiPartForm(request).then(file=>{
- this.uploadFileToBlueprintController(file, REST_BLUEPRINT_CONTROLLER_BASE_URL+"/blueprint-model/enrich/", response).then(resp=>{
+ this.uploadFileToBlueprintController(file, "/blueprint-model/enrich/", response).then(resp=>{
resolve(resp);
}, err=>{
reject(err);
@param.path.string('version') version:string,
@inject(RestBindings.Http.RESPONSE) response: Response,
): Promise<Response> {
- return this.downloadFileFromBlueprintController(REST_BLUEPRINT_CONTROLLER_BASE_URL+"/blueprint-model/download/by-name/"+name+"/version/"+version, response);
+ return this.downloadFileFromBlueprintController("/blueprint-model/download/by-name/"+name+"/version/"+version, response);
}
async getFileFromMultiPartForm(request: Request): Promise<multiparty.File>{
): Promise<Response> {
return new Promise((resolve, reject) => {
this.getFileFromMultiPartForm(request).then(file=>{
- this.uploadFileToBlueprintController(file, REST_BLUEPRINT_PROCESSOR_BASE_URL+"/execution-service/upload/", response).then(resp=>{
+ this.uploadFileToBlueprintProcessor(file, "/execution-service/upload/", response).then(resp=>{
resolve(resp);
}, err=>{
reject(err);
});
});
}
+
async uploadFileToBlueprintController(file: multiparty.File, uri: string, response: Response): Promise<Response>{
+ return this.uploadFileToBlueprintService(file, controllerApiConfig.url + uri, controllerApiConfig.authToken, response);
+ }
+
+ async uploadFileToBlueprintProcessor(file: multiparty.File, uri: string, response: Response): Promise<Response>{
+ return this.uploadFileToBlueprintService(file, processorApiConfig.url + uri, processorApiConfig.authToken, response);
+ }
+
+ async uploadFileToBlueprintService(file: multiparty.File, url: string, authToken: string, response: Response): Promise<Response>{
let options = {
- // url: REST_BLUEPRINT_CONTROLLER_BASE_URL + uri,
- url:uri,
+ url: url,
headers: {
- Authorization: REST_BLUEPRINT_CONTROLLER_BASIC_AUTH_HEADER,
+ Authorization: authToken,
'content-type': 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW'
},
formData: {
});
})
}
+
async downloadFileFromBlueprintController(uri: string, response: Response): Promise<Response> {
+ return this.downloadFileFromBlueprintService(controllerApiConfig.url + uri, controllerApiConfig.authToken, response);
+ }
+
+ async downloadFileFromBlueprintService(url: string, authToken: string, response: Response): Promise<Response> {
let options = {
- url: uri,
- // REST_BLUEPRINT_CONTROLLER_BASE_URL + uri,
+ url: url,
headers: {
- Authorization: REST_BLUEPRINT_CONTROLLER_BASIC_AUTH_HEADER,
+ Authorization: authToken,
}
};
return new Promise((resolve, reject) => {
import { inject } from '@loopback/core';
import { ResourceDictionaryService } from '../services';
-const REST_RESOURCE_DICTIONARY_BASIC_AUTH_HEADER = process.env.REST_BLUEPRINT_CONTROLLER_BASIC_AUTH_HEADER || "Basic Y2NzZGthcHBzOmNjc2RrYXBwcw==";
export class DataDictionaryController {
constructor(
@inject('services.ResourceDictionaryService')
},
})
async getByName(@param.path.string('name') name: string) {
- return await this.rdservice.getByName(name, REST_RESOURCE_DICTIONARY_BASIC_AUTH_HEADER);
+ return await this.rdservice.getByName(name);
}
+
@get('/resourcedictionary/search/{tags}', {
responses: {
'200': {
},
})
async getByTags(@param.path.string('tags') tags: string) {
- return await this.rdservice.getByTags(tags, REST_RESOURCE_DICTIONARY_BASIC_AUTH_HEADER);
+ return await this.rdservice.getByTags(tags);
}
@get('/resourcedictionary/source-mapping', {
},
})
async getSourceMapping() {
- return await this.rdservice.getSourceMapping(REST_RESOURCE_DICTIONARY_BASIC_AUTH_HEADER);
+ return await this.rdservice.getSourceMapping();
}
+
@post('/resourcedictionary/save', {
responses: {
'200': {
content: { 'application/json': { schema: { 'x-ts-type': JSON } } },
accepts: { 'application/json': { schema: { 'x-ts-type': JSON } } }
}) resourceDictionary: JSON): Promise<any> {
- return await this.rdservice.save(REST_RESOURCE_DICTIONARY_BASIC_AUTH_HEADER, resourceDictionary);
+ return await this.rdservice.save(resourceDictionary);
}
+
@post('/resourcedictionary/search/by-names', {
responses: {
'200': {
content: { 'application/json': { schema: { 'x-ts-type': JSON } } },
accepts: { 'application/json': { schema: { 'x-ts-type': JSON } } }
}) resourceDictionaryList: JSON): Promise<any> {
- return await this.rdservice.searchbyNames(REST_RESOURCE_DICTIONARY_BASIC_AUTH_HEADER, resourceDictionaryList);
+ return await this.rdservice.searchbyNames(resourceDictionaryList);
}
}
-{
+import {controllerApiConfig} from '../../config/app-config';
+
+export default {
"name": "blueprint",
"connector": "rest",
- "baseURL": "http://localhost:8080/api/v1/",
+ "baseURL": controllerApiConfig.url,
"crud": false,
"operations": [{
"template": {
"method": "GET",
- "url": "http://localhost:8080/api/v1/blueprint-model/",
+ "url": controllerApiConfig.url + "/blueprint-model/",
"headers": {
"accepts": "application/json",
"content-type": "application/json",
- "authorization": "{authtoken}"
+ "authorization": controllerApiConfig.authToken
},
"responsePath": "$.*"
},
"functions": {
- "getAllblueprints": ["authtoken"]
+ "getAllblueprints": []
}
}]
-}
\ No newline at end of file
+};
\ No newline at end of file
import {inject} from '@loopback/core';
import {juggler} from '@loopback/repository';
-import * as config from './blueprint.datasource.json';
+import config from './blueprint.datasource-template';
export class BlueprintDataSource extends juggler.DataSource {
static dataSourceName = 'blueprint';
-{
+import {controllerApiConfig} from '../../config/app-config';
+
+export default {
"name": "resourceDictionary",
"connector": "rest",
- "baseURL": "http://localhost:8080/api/v1/dictionary",
+ "baseURL": controllerApiConfig.url + "/dictionary",
"crud": false,
"operations": [{
"template": {
"method": "GET",
- "url": "http://localhost:8080/api/v1/dictionary/{name}",
+ "url": controllerApiConfig.url + "/dictionary/{name}",
"headers": {
"accepts": "application/json",
"content-type": "application/json",
- "authorization": "{authtoken}"
+ "authorization": controllerApiConfig.authToken
},
"responsePath": "$.*"
},
"functions": {
- "getByName": ["name", "authtoken"]
+ "getByName": ["name"]
}
},
{
"template": {
"method": "GET",
- "url": "http://localhost:8080/api/v1/dictionary/source-mapping",
+ "url": controllerApiConfig.url + "/dictionary/source-mapping",
"headers": {
"accepts": "application/json",
"content-type": "application/json",
- "authorization": "{authtoken}"
+ "authorization": controllerApiConfig.authToken
},
"responsePath": "$.*"
},
"functions": {
- "getSourceMapping": ["authtoken"]
+ "getSourceMapping": []
}
},
{
"template": {
"method": "GET",
- "url": "http://localhost:8080/api/v1/dictionary/search/{tags}",
+ "url": controllerApiConfig.url + "/dictionary/search/{tags}",
"headers": {
"accepts": "application/json",
"content-type": "application/json",
- "authorization": "{authtoken}"
+ "authorization": controllerApiConfig.authToken
},
"responsePath": "$.*"
},
"functions": {
- "getByTags": ["tags", "authtoken"]
+ "getByTags": ["tags"]
}
},
{
"template": {
"method": "POST",
- "url": "http://localhost:8080/api/v1/dictionary",
+ "url": controllerApiConfig.url + "/dictionary",
"headers": {
"accepts": "application/json",
"content-type": "application/json",
- "authorization": "{authtoken}"
+ "authorization": controllerApiConfig.authToken
},
"body": "{resourceDictionary}",
"responsePath": "$.*"
},
"functions": {
- "save": ["authtoken", "resourceDictionary"]
+ "save": ["resourceDictionary"]
}
},
{
"template": {
"method": "POST",
- "url": "http://localhost:8080/api/v1/dictionary/by-names",
+ "url": controllerApiConfig.url + "/dictionary/by-names",
"headers": {
"accepts": "application/json",
"content-type": "application/json",
- "authorization": "{authtoken}"
+ "authorization": controllerApiConfig.authToken
},
"body": "{resourceDictionaryList}",
"responsePath": "$.*"
},
"functions": {
- "searchbyNames": ["authtoken", "resourceDictionaryList"]
+ "searchbyNames": ["resourceDictionaryList"]
}
}
]
-}
\ No newline at end of file
+};
\ No newline at end of file
import {inject} from '@loopback/core';
import {juggler} from '@loopback/repository';
-import * as config from './resource-dictionary.datasource.json';
+import config from './resource-dictionary.datasource-template';
export class ResourceDictionaryDataSource extends juggler.DataSource {
static dataSourceName = 'resourceDictionary';
import {BlueprintDataSource} from '../datasources';
export interface BlueprintService {
- getAllblueprints(authtoken: string): Promise<any>;
+ getAllblueprints(): Promise<any>;
}
export class BlueprintServiceProvider implements Provider<BlueprintService> {
import {ResourceDictionaryDataSource} from '../datasources';
export interface ResourceDictionaryService {
- getByName(name: string, authtoken: string): Promise<JSON>;
- getSourceMapping(authtoken: string): Promise<JSON>;
- getByTags(tags: string, authtoken: string): Promise<JSON>;
- save(authtoken: string, resourceDictionary: JSON): Promise<JSON>;
- searchbyNames(authtoken: string, resourceDictionaryList: JSON): Promise<JSON>;
+ getByName(name: string): Promise<JSON>;
+ getSourceMapping(): Promise<JSON>;
+ getByTags(tags: string): Promise<JSON>;
+ save(resourceDictionary: JSON): Promise<JSON>;
+ searchbyNames(resourceDictionaryList: JSON): Promise<JSON>;
}
export class ResourceDictionaryServiceProvider implements Provider<ResourceDictionaryService> {
<parent>
<groupId>org.onap.ccsdk.cds</groupId>
<artifactId>parent</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
<relativePath>../../../</relativePath>
</parent>
<groupId>org.onap.ccsdk.cds.components</groupId>
<artifactId>proto-definition</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Controller Blueprints Proto Definition</name>
<parent>
<groupId>org.onap.ccsdk.cds</groupId>
<artifactId>components</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
</parent>
<groupId>org.onap.ccsdk.cds.components</groupId>
<artifactId>parent</artifactId>
<parent>
<groupId>org.onap.ccsdk.cds</groupId>
<artifactId>parent</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>components</artifactId>
<parent>
<groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
<artifactId>parent</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
<relativePath>../parent</relativePath>
</parent>
<artifactId>application</artifactId>
<parent>
<groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
<artifactId>parent</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
<relativePath>../parent</relativePath>
</parent>
<artifactId>distribution</artifactId>
<parent>
<artifactId>functions</artifactId>
<groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>cli-executor</artifactId>
<parent>
<groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
<artifactId>functions</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.onap.ccsdk.cds.blueprintsprocessor.functions</groupId>
<parent>
<groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
<artifactId>parent</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
<relativePath>../parent</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>functions</artifactId>
<groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
package org.onap.ccsdk.cds.blueprintsprocessor.functions.python.executor
import com.fasterxml.jackson.databind.JsonNode
+import com.fasterxml.jackson.databind.ObjectMapper
import io.mockk.every
import io.mockk.mockk
import kotlinx.coroutines.runBlocking
import org.junit.Test
-import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.*
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.PrepareRemoteEnvInput
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.RemoteScriptExecutionInput
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.RemoteScriptExecutionOutput
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.StatusType
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.StepData
import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.RemoteScriptExecutionService
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
import org.onap.ccsdk.cds.controllerblueprints.core.putJsonElement
+import org.onap.ccsdk.cds.controllerblueprints.core.service.DefaultBluePrintRuntimeService
import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
import kotlin.test.assertEquals
executionServiceInput.stepData = stepInputData
componentRemotePythonExecutor.applyNB(executionServiceInput)
}
+ }
+
+ /**
+ * Test cases for python executor to work with the process NB of remote
+ * executor.
+ */
+ @Test
+ fun testComponentRemotePythonExecutorProcessNB() {
+ runBlocking {
+ val remoteScriptExecutionService =
+ MockRemoteScriptExecutionService()
+ val componentRemotePythonExecutor = ComponentRemotePythonExecutor(
+ remoteScriptExecutionService)
+ val bluePrintRuntime = mockk<DefaultBluePrintRuntimeService>(
+ "123456-1000")
+ val input = getMockedOutput(bluePrintRuntime)
+ componentRemotePythonExecutor.bluePrintRuntimeService =
+ bluePrintRuntime
+ componentRemotePythonExecutor.applyNB(input)
+ }
+ }
+
+ /**
+ * Mocked input information for remote python executor.
+ */
+ fun getMockedOutput(svc: DefaultBluePrintRuntimeService):
+ ExecutionServiceInput {
+ val stepMetaData: MutableMap<String, JsonNode> = hashMapOf()
+
+ stepMetaData.putJsonElement(
+ BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE,
+ "execute-remote-python")
+ stepMetaData.putJsonElement(
+ BluePrintConstants.PROPERTY_CURRENT_INTERFACE,
+ "ComponentRemotePythonExecutor")
+ stepMetaData.putJsonElement(
+ BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process")
+
+ val mapper = ObjectMapper()
+ val rootNode = mapper.createObjectNode()
+ rootNode.put("ip-address", "0.0.0.0")
+ rootNode.put("type", "rest")
+
+ val operationalInputs: MutableMap<String, JsonNode> = hashMapOf()
+ operationalInputs.putJsonElement(
+ BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE,
+ "execute-remote-python")
+ operationalInputs.putJsonElement(
+ BluePrintConstants.PROPERTY_CURRENT_INTERFACE,
+ "ComponentRemotePythonExecutor")
+ operationalInputs.putJsonElement(
+ BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process")
+ operationalInputs.putJsonElement("endpoint-selector", "aai")
+ operationalInputs.putJsonElement("dynamic-properties", rootNode)
+ operationalInputs.putJsonElement("command", "./run.sh")
+ operationalInputs.putJsonElement("packages", "py")
+
+ every {
+ svc.resolveNodeTemplateInterfaceOperationInputs(
+ "execute-remote-python",
+ "ComponentRemotePythonExecutor", "process")
+ } returns operationalInputs
+
+ val stepInputData = StepData().apply {
+ name = "execute-remote-python"
+ properties = stepMetaData
+ }
+ val executionServiceInput = JacksonUtils
+ .readValueFromClassPathFile(
+ "payload/requests/sample-remote-python-request.json",
+ ExecutionServiceInput::class.java)!!
+ executionServiceInput.stepData = stepInputData
+
+ val operationOutputs = hashMapOf<String, JsonNode>()
+ every {
+ svc.resolveNodeTemplateInterfaceOperationOutputs(
+ "execute-remote-python",
+ "ComponentRemotePythonExecutor", "process")
+ } returns operationOutputs
+ val bluePrintRuntimeService = BluePrintMetadataUtils
+ .getBluePrintRuntime("123456-1000",
+ "./../../../../components/model-" +
+ "catalog/blueprint-model/test-blueprint/" +
+ "remote_scripts")
+ every {
+ svc.resolveNodeTemplateArtifactDefinition(
+ "execute-remote-python", "component-script")
+ } returns bluePrintRuntimeService.resolveNodeTemplateArtifactDefinition(
+ "execute-remote-python", "component-script")
+ every {
+ svc.setNodeTemplateAttributeValue(
+ "execute-remote-python", "prepare-environment-logs",
+ "prepared successfully".asJsonPrimitive())
+ } returns Unit
+ every {
+ svc.setNodeTemplateAttributeValue(
+ "execute-remote-python",
+ "execute-command-logs", "N/A".asJsonPrimitive())
+ } returns Unit
+ every {
+ svc.setNodeTemplateAttributeValue(
+ "execute-remote-python",
+ "execute-command-logs",
+ "processed successfully".asJsonPrimitive())
+ } returns Unit
+
+ every {
+ svc.bluePrintContext()
+ } returns bluePrintRuntimeService.bluePrintContext()
+ return executionServiceInput
}
}
--- /dev/null
+{
+ "actionIdentifiers": {
+ "actionName": "activate",
+ "blueprintName": "remote_scripts",
+ "blueprintVersion": "1.0.0",
+ "mode": "sync"
+ },
+ "commonHeader": {
+ "flags": {
+ "force": true,
+ "ttl": 3600
+ },
+ "originatorId": "sdnc",
+ "requestId": "123456-1000",
+ "subRequestId": "sub-123456-1000",
+ "timestamp": "2012-04-23T18:25:43.511Z"
+ },
+ "payload": {
+ "execute-remote-python": {
+ "input": "1234"
+ }
+ }
+}
<parent>
<groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
<artifactId>functions</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
</parent>
<groupId>org.onap.ccsdk.cds.blueprintsprocessor.functions</groupId>
<artifactId>resource-resolution</artifactId>
<parent>
<artifactId>functions</artifactId>
<groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.onap.ccsdk.cds.blueprintsprocessor.functions</groupId>
<parent>
<groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
<artifactId>commons</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
</parent>
<artifactId>db-lib</artifactId>
<parent>
<groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
<artifactId>commons</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
</parent>
<artifactId>dmaap-lib</artifactId>
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>commons</artifactId>
<groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
</dependency>
</dependencies>
-</project>
\ No newline at end of file
+</project>
package org.onap.ccsdk.cds.blueprintsprocessor.grpc.service
+import com.fasterxml.jackson.databind.JsonNode
+import com.fasterxml.jackson.databind.ObjectMapper
import org.junit.Test
import org.junit.runner.RunWith
import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintProperties
import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertyConfiguration
import org.onap.ccsdk.cds.blueprintsprocessor.grpc.BasicAuthGrpcClientProperties
import org.onap.ccsdk.cds.blueprintsprocessor.grpc.BluePrintGrpcLibConfiguration
+import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TokenAuthGrpcClientProperties
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.test.context.ContextConfiguration
import org.springframework.test.context.TestPropertySource
import org.springframework.test.context.junit4.SpringRunner
+import kotlin.test.assertEquals
import kotlin.test.assertNotNull
+import kotlin.test.assertTrue
@RunWith(SpringRunner::class)
@ContextConfiguration(classes = [BluePrintGrpcLibConfiguration::class,
"blueprintsprocessor.grpcclient.sample.host=127.0.0.1",
"blueprintsprocessor.grpcclient.sample.port=50505",
"blueprintsprocessor.grpcclient.sample.username=sampleuser",
- "blueprintsprocessor.grpcclient.sample.password=sampleuser"
+ "blueprintsprocessor.grpcclient.sample.password=sampleuser",
+ "blueprintsprocessor.grpcclient.token.type=token-auth",
+ "blueprintsprocessor.grpcclient.token.host=127.0.0.1",
+ "blueprintsprocessor.grpcclient.token.port=50505",
+ "blueprintsprocessor.grpcclient.token.username=sampleuser",
+ "blueprintsprocessor.grpcclient.token.password=sampleuser"
])
class BluePrintGrpcLibPropertyServiceTest {
@Autowired
lateinit var bluePrintGrpcLibPropertyService: BluePrintGrpcLibPropertyService
+ /**
+ * Tests the GRPC client properties with selector for basic auth.
+ */
@Test
fun testGrpcClientProperties() {
val properties = bluePrintGrpcLibPropertyService.grpcClientProperties(
- "blueprintsprocessor.grpcclient.sample") as BasicAuthGrpcClientProperties
+ "blueprintsprocessor.grpcclient.sample")
+ as BasicAuthGrpcClientProperties
assertNotNull(properties, "failed to create property bean")
- assertNotNull(properties.host, "failed to get host property in property bean")
- assertNotNull(properties.port, "failed to get host property in property bean")
- assertNotNull(properties.username, "failed to get host property in property bean")
- assertNotNull(properties.password, "failed to get host property in property bean")
+ assertNotNull(properties.host, "failed to get host property" +
+ " in property bean")
+ assertNotNull(properties.port, "failed to get host property" +
+ " in property bean")
+ assertNotNull(properties.username, "failed to get host pro" +
+ "perty in property bean")
+ assertNotNull(properties.password, "failed to get host pr" +
+ "operty in property bean")
+ }
+
+ /**
+ * Tests the GRPC client properties with JSON node for token auth.
+ */
+ @Test
+ fun testGrpcClientPropertiesWithJson() {
+ val json: String = "{\n" +
+ " \"type\" : \"token-auth\",\n" +
+ " \"host\" : \"127.0.0.1\",\n" +
+ " \"port\" : \"50505\"\n" +
+ "}"
+ val mapper = ObjectMapper()
+ val actualObj: JsonNode = mapper.readTree(json)
+ val properties = bluePrintGrpcLibPropertyService.grpcClientProperties(
+ actualObj) as TokenAuthGrpcClientProperties
+ assertNotNull(properties, "failed to create property bean")
+ assertEquals(properties.host, "127.0.0.1")
+ assertNotNull(properties.port, "50505")
+ }
+
+ /**
+ * Tests the GRPC client service with selector for basic auth.
+ */
+ @Test
+ fun testGrpcClientServiceBasic() {
+ val svc = bluePrintGrpcLibPropertyService.blueprintGrpcClientService(
+ "sample")
+ assertTrue(svc is BasicAuthGrpcClientService)
+ }
+
+ /**
+ * Tests the GRPC client service with selector for token auth.
+ */
+ @Test
+ fun testGrpcClientServiceToken() {
+ val svc = bluePrintGrpcLibPropertyService.blueprintGrpcClientService(
+ "token")
+ assertTrue(svc is TokenAuthGrpcClientService)
+ }
+
+ /**
+ * Tests the GRPC client service with JSON node for basic auth.
+ */
+ @Test
+ fun testGrpcClientServiceWithJson() {
+ val json: String = "{\n" +
+ " \"type\" : \"basic-auth\",\n" +
+ " \"host\" : \"127.0.0.1\",\n" +
+ " \"port\" : \"50505\",\n" +
+ " \"username\" : \"sampleuser\",\n" +
+ " \"password\" : \"samplepwd\"\n" +
+ "}"
+ val mapper = ObjectMapper()
+ val actualObj: JsonNode = mapper.readTree(json)
+ val svc = bluePrintGrpcLibPropertyService
+ .blueprintGrpcClientService(actualObj)
+ assertTrue(svc is BasicAuthGrpcClientService)
}
}
\ No newline at end of file
<parent>
<groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
<artifactId>modules</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
</parent>
<artifactId>commons</artifactId>
<parent>
<groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
<artifactId>commons</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
</parent>
<artifactId>processor-core</artifactId>
<parent>
<groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
<artifactId>commons</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
</parent>
<artifactId>rest-lib</artifactId>
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper
-import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintProperties
"blueprintsprocessor.restclient.ssl.sslKey=src/test/resources/keystore.p12",
"blueprintsprocessor.restclient.ssl.sslKeyPassword=changeit"
])
-@Ignore
class BluePrintRestLibPropertyServiceTest {
@Autowired
"eprintWebClientService")
}
+ @Test
+ fun testBlueprintWebClientServiceWithJsonNode() {
+ val json: String = "{\n" +
+ " \"type\" : \"ssl-basic-auth\",\n" +
+ " \"url\" : \"https://localhost:8443\",\n" +
+ " \"keyStoreInstance\" : \"PKCS12\",\n" +
+ " \"sslTrust\" : \"src/test/resources/keystore.p12\",\n" +
+ " \"sslTrustPassword\" : \"changeit\",\n" +
+ " \"basicAuth\" : {\n" +
+ " \"username\" : \"admin\",\n" +
+ " \"password\" : \"cds\"\n" +
+ " }\n" +
+ "}"
+ val mapper = ObjectMapper()
+ val actualObj: JsonNode = mapper.readTree(json)
+ val blueprintWebClientService = bluePrintRestLibPropertyService
+ .blueprintWebClientService(actualObj)
+ assertNotNull(blueprintWebClientService, "failed to create blu" +
+ "eprintWebClientService")
+ }
}
<parent>
<groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
<artifactId>modules</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
</parent>
<artifactId>inbounds</artifactId>
<parent>
<groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
<artifactId>inbounds</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
</parent>
<artifactId>resource-api</artifactId>
<parent>
<groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
<artifactId>inbounds</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
</parent>
<artifactId>selfservice-api</artifactId>
<parent>
<groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
<artifactId>modules</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
</parent>
<artifactId>outbounds</artifactId>
<parent>
<groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
<artifactId>parent</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
<relativePath>../parent</relativePath>
</parent>
<parent>
<groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
<artifactId>services</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
</parent>
<artifactId>execution-service</artifactId>
package org.onap.ccsdk.cds.blueprintsprocessor.services.execution.scripts;
import com.fasterxml.jackson.databind.JsonNode
+import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.node.ObjectNode
import io.mockk.every
import io.mockk.mockk
import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.StepData
import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction
+import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentFunctionScriptingService
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName
import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
import org.onap.ccsdk.cds.controllerblueprints.core.service.DefaultBluePrintRuntimeService
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
+import org.onap.ccsdk.cds.controllerblueprints.scripts.BluePrintScriptsServiceImpl
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.test.context.ContextConfiguration
import org.springframework.test.context.junit4.SpringRunner
import kotlin.test.BeforeTest
import kotlin.test.assertEquals
* Unit test cases for abstract component function.
*/
@RunWith(SpringRunner::class)
+@ContextConfiguration(classes = [ComponentFunctionScriptingService::class,
+ BluePrintScriptsServiceImpl::class,PythonExecutorProperty::class,
+ BlueprintJythonService::class])
class AbstractComponentFunctionTest {
lateinit var blueprintContext: BluePrintContext
+ @Autowired
+ lateinit var compSvc: ComponentFunctionScriptingService
+
@BeforeTest
fun init() {
blueprintContext = mockk<BluePrintContext>()
}
}
+ /**
+ * Tests the abstract script component functionality.
+ */
+ @Test
+ fun testAbstractScriptComponent() {
+ runBlocking {
+ val bluePrintRuntime = mockk<DefaultBluePrintRuntimeService>("1234")
+ val samp = SampleRestconfComponent(compSvc)
+ val comp = samp as AbstractComponentFunction
+
+ comp.bluePrintRuntimeService = bluePrintRuntime
+ comp.stepName = "sample-step"
+ assertNotNull(comp, "failed to get kotlin instance")
+
+ val input = getMockedInput(bluePrintRuntime)
+ val inp = getMockedContext()
+
+ val output = comp.applyNB(input)
+
+ assertEquals(output.actionIdentifiers.actionName, "activate")
+ assertEquals(output.commonHeader.requestId, "1234")
+ assertEquals(output.stepData!!.name, "activate-restconf")
+ assertEquals(output.status.message, "success")
+ }
+ }
+
+ /**
+ * Mocked input for abstract function test.
+ */
+ private fun getMockedContext() {
+ val operationOutputs = hashMapOf<String, JsonNode>()
+ every {
+ blueprintContext.name()
+ } returns "SampleTest"
+ every {
+ blueprintContext.version()
+ } returns "SampleScriptComponent"
+ }
/**
* Mocked input for abstract function test.
*/
private fun getMockedInput(bluePrintRuntime: DefaultBluePrintRuntimeService):
ExecutionServiceInput {
+
+ val mapper = ObjectMapper()
+ val rootNode = mapper.createObjectNode()
+ rootNode.put("ip-address", "0.0.0.0")
+ rootNode.put("type", "rest")
+
val operationInputs = hashMapOf<String, JsonNode>()
operationInputs[BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE] =
"activate-restconf".asJsonPrimitive()
"interfaceName".asJsonPrimitive()
operationInputs[BluePrintConstants.PROPERTY_CURRENT_OPERATION] =
"operationName".asJsonPrimitive()
+ operationInputs["dynamic-properties"] = rootNode
+
val stepInputData = StepData().apply {
name = "activate-restconf"
return executionServiceInput
}
+
}
+
import org.springframework.test.context.ContextConfiguration
import org.springframework.test.context.TestPropertySource
import org.springframework.test.context.junit4.SpringRunner
-import kotlin.test.assertNotNull
import kotlin.test.BeforeTest
+import kotlin.test.assertNotNull
@RunWith(SpringRunner::class)
@ContextConfiguration(classes = [BlueprintJythonService::class, PythonExecutorProperty::class])
import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction
+import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptComponentFunction
+import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentFunctionScriptingService
+
import org.slf4j.LoggerFactory
open class SampleComponent : AbstractComponentFunction() {
}
}
-open class SampleScriptComponent : AbstractComponentFunction() {
+open class SampleRestconfComponent (private var componentFunctionScriptingService: ComponentFunctionScriptingService)
+ : AbstractComponentFunction() {
val log = LoggerFactory.getLogger(SampleScriptComponent::class.java)!!
override suspend fun processNB(executionRequest: ExecutionServiceInput) {
+ var scriptComponent: AbstractScriptComponentFunction
+ scriptComponent = componentFunctionScriptingService
+ .scriptInstance<AbstractScriptComponentFunction>(this,
+ "internal",
+ "org.onap.ccsdk.cds.blueprintsprocessor.services" +
+ ".execution.scripts.SampleTest",
+ mutableListOf())
+ scriptComponent.executeScript(executionServiceInput)
+ }
+
+ override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
+ }
+}
+
+open class SampleScriptComponent : AbstractScriptComponentFunction() {
+
+ val log = LoggerFactory.getLogger(SampleScriptComponent::class.java)!!
+
+
+ override suspend fun processNB(executionRequest: ExecutionServiceInput) {
+
}
override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
--- /dev/null
+package org.onap.ccsdk.cds.blueprintsprocessor.services.execution.scripts
+
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - CDS
+ * ================================================================================
+ * Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
+import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptComponentFunction
+import org.slf4j.LoggerFactory
+import kotlin.test.assertEquals
+import kotlin.test.assertTrue
+
+open class SampleTest : AbstractScriptComponentFunction() {
+
+ val log = LoggerFactory.getLogger(SampleTest::class.java)!!
+
+
+ override suspend fun processNB(executionRequest: ExecutionServiceInput) {
+ val isPresent = checkDynamicProperties("type")
+ assertTrue(isPresent)
+ val prop = getDynamicProperties("ip-address").toString()
+ assertEquals(prop, "\"0.0.0.0\"")
+ }
+
+ override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
+ }
+}
\ No newline at end of file
<parent>
<groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
<artifactId>modules</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
</parent>
<artifactId>services</artifactId>
<parent>
<groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
<artifactId>services</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onap.ccsdk.cds</groupId>
<artifactId>blueprintsprocessor</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
</parent>
<groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId>
<artifactId>parent</artifactId>
<jsch.version>0.1.55</jsch.version>
<protobuff.java.utils.version>3.6.1</protobuff.java.utils.version>
<eelf.version>1.0.0</eelf.version>
- <sli.version>0.4.2-SNAPSHOT</sli.version>
<guava.version>27.0.1-jre</guava.version>
<jython.version>2.7.1</jython.version>
<springfox.swagger2.version>2.9.2</springfox.swagger2.version>
<dependency>
<groupId>org.onap.ccsdk.sli.core</groupId>
<artifactId>sli-provider</artifactId>
- <version>${sli.version}</version>
+ <version>${ccsdk.sli.core.version}</version>
<exclusions>
<exclusion>
<groupId>commons-lang</groupId>
<parent>
<groupId>org.onap.ccsdk.cds</groupId>
<artifactId>ms</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>blueprintsprocessor</artifactId>
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onap.ccsdk.cds</groupId>
<artifactId>ms</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>command-executor</artifactId>
<parent>
<groupId>org.onap.ccsdk.cds.controllerblueprints</groupId>
<artifactId>parent</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
<relativePath>../parent</relativePath>
</parent>
<artifactId>application</artifactId>
<parent>
<groupId>org.onap.ccsdk.cds.controllerblueprints</groupId>
<artifactId>parent</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
<relativePath>../parent</relativePath>
</parent>
<artifactId>distribution</artifactId>
<parent>
<groupId>org.onap.ccsdk.cds.controllerblueprints</groupId>
<artifactId>modules</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
</parent>
<artifactId>blueprint-core</artifactId>
<name>Controller Blueprints Core</name>
--- /dev/null
+package org.onap.ccsdk.cds.controllerblueprints.core
+
+import org.junit.Test
+import kotlin.test.assertEquals
+import kotlin.test.assertTrue
+
+class BluePrintErrorTest {
+
+ @Test
+ fun testBluePrintErrorIsCreatedWithemptyList() {
+ val bluePrintError = BluePrintError()
+
+ assertTrue(bluePrintError.errors.isEmpty())
+ }
+
+ @Test
+ fun testAddErrorWith3Params() {
+ val bluePrintError = BluePrintError()
+
+ bluePrintError.addError("type", "name", "error")
+
+ assertEquals("type : name : error", bluePrintError.errors[0])
+ }
+
+ @Test
+ fun testAddErrorWith1Params() {
+ val bluePrintError = BluePrintError()
+
+ bluePrintError.addError("error")
+
+ assertEquals("error", bluePrintError.errors[0])
+ }
+}
\ No newline at end of file
package org.onap.ccsdk.cds.controllerblueprints.core
+import com.fasterxml.jackson.databind.JsonNode
+import com.fasterxml.jackson.databind.ObjectMapper
+import com.fasterxml.jackson.databind.node.*
import org.junit.Test
-import kotlin.test.assertEquals
+import kotlin.test.*
+
/**
*
*
*/
class CustomFunctionsTest {
@Test
- fun testFormat(): Unit {
+ fun testFormat() {
val returnValue : String = format("This is {} for times {}", "test", 2)
assertEquals("This is test for times 2", returnValue, "Failed to format String")
val returnValue1 : String = format("This is test for times 2")
assertEquals("This is test for times 2", returnValue1, "Failed to format empty args")
}
+
+ @Test
+ fun testStringAsJsonPrimitive() {
+ val returnValue: TextNode = "hello".asJsonPrimitive()
+ assertEquals("hello", returnValue.textValue())
+ }
+
+ @Test
+ fun testIntAsJsonPrimitive() {
+ val returnValue: IntNode = 1.asJsonPrimitive()
+ assertEquals(1, returnValue.intValue())
+ }
+
+ @Test
+ fun testBooleanAsJsonPrimitive() {
+ val returnValue: BooleanNode = false.asJsonPrimitive()
+ assertFalse(returnValue.asBoolean())
+ }
+
+ @Test
+ fun testAsJsonType() {
+ val nullReturnValue: JsonNode = null.asJsonType()
+ assertEquals(NullNode.instance, nullReturnValue)
+
+ val returnValueString: JsonNode = "hello".asJsonType()
+ assertEquals("hello", returnValueString.textValue())
+
+ val returnValueJsonNode: JsonNode = returnValueString.asJsonType()
+ assertEquals(returnValueString, returnValueJsonNode)
+
+ val returnValueInt: JsonNode = 1.asJsonType()
+ assertEquals(1, returnValueInt.intValue())
+
+ val returnValueBool: JsonNode = false.asJsonType()
+ assertFalse(returnValueBool.asBoolean())
+
+ val returnValue: JsonNode = BluePrintError().asJsonType()
+ assertEquals(JsonNodeType.OBJECT, returnValue.getNodeType())
+ }
+
+ @Test
+ fun testMapAsObjectNode() {
+ val returnValue: ObjectNode = hashMapOf("test" to BluePrintError()).asObjectNode()
+ assertNotNull(returnValue.get("test"))
+ }
+
+ @Test
+ fun testCastOptionalValue() {
+ val initMap: Map<String, *> = hashMapOf("test" to 1.1, "test2" to null)
+ val returnValue = initMap.castOptionalValue("test", Number::class)
+
+ assert(returnValue is Number)
+
+ val returnValueNull = initMap.castOptionalValue("test1", Number::class)
+
+ assertNull(returnValueNull)
+
+ val returnValueString: String? = initMap.castOptionalValue("test2", String::class)
+
+ assertNull(returnValueString)
+ }
+
+ @Test(expected = BluePrintException::class)
+ fun testCastValue() {
+ val initMap: Map<String, Double> = hashMapOf("test" to 1.1)
+ val returnValue = initMap.castValue("test", Number::class)
+
+ assertNotNull(returnValue)
+
+ initMap.castValue("test1", Number::class)
+ }
+
+ @Test
+ fun testAsListOfString() {
+ val arrayNode: ArrayNode = ObjectMapper().createObjectNode().putArray("array")
+
+ val result: List<String> = arrayNode.asListOfString()
+
+ assertTrue(result.isEmpty())
+ }
+
+ @Test
+ fun testReturnNullIfMissing() {
+ val valueExist = "hello".asJsonType().returnNullIfMissing()
+ assertNotNull(valueExist)
+
+ val valueNull = NullNode.instance.returnNullIfMissing()
+ assertNull(valueNull)
+
+ val missingValue = MissingNode.getInstance().returnNullIfMissing()
+ assertNull(missingValue)
+ }
+
+ @Test(expected = BluePrintException::class)
+ fun testRootFieldsToMap() {
+ 1.asJsonType().rootFieldsToMap()
+ }
+
+ @Test
+ fun testPutJsonElement() {
+ val mutMap = mutableMapOf("test" to 2.asJsonType())
+
+ mutMap.putJsonElement("hello", 3)
+
+ assertEquals(3, mutMap["hello"]?.asInt())
+ }
+
+ @Test(expected = BluePrintException::class)
+ fun testMapGetAsString() {
+ val initMap = hashMapOf("test" to "hello".asJsonType())
+
+ assertEquals("hello", initMap.getAsString("test"))
+
+ initMap.getAsString("test2")
+ }
+
+ @Test(expected = BluePrintException::class)
+ fun testMapGetAsBoolean() {
+ val initMap = hashMapOf("test" to true.asJsonType())
+
+ assertTrue(initMap.getAsBoolean("test"))
+
+ initMap.getAsBoolean("test2")
+ }
+
+ @Test(expected = BluePrintException::class)
+ fun testMapGetAsInt() {
+ val initMap = hashMapOf("test" to 1.asJsonType())
+
+ assertEquals(1, initMap.getAsInt("test"))
+
+ initMap.getAsInt("test2")
+ }
+
+ @Test(expected = BluePrintException::class)
+ fun testCheckEquals() {
+ assertTrue(checkEquals("hello", "hello", { -> "error"}))
+
+ checkEquals("hello", "test", { -> "error"})
+ }
+
+ @Test(expected = IllegalStateException::class)
+ fun testCheckNotEmpty() {
+ assertEquals("hello", checkNotEmpty("hello", { -> "error"}))
+
+ checkNotEmpty("", { -> "error"})
+ }
+
+ @Test(expected = IllegalStateException::class)
+ fun testCheckNotBlank() {
+ assertEquals("hello", checkNotBlank("hello", { -> "error"}))
+
+ checkNotBlank(" ", { -> "error"})
+ }
+
+ @Test
+ fun testNullToEmpty() {
+ assertEquals("", nullToEmpty(null))
+
+ assertEquals("hello", nullToEmpty("hello"))
+ }
}
\ No newline at end of file
package org.onap.ccsdk.cds.controllerblueprints.core.service
+import com.fasterxml.jackson.databind.ObjectMapper
import org.slf4j.LoggerFactory
import org.junit.Test
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
+import org.onap.ccsdk.cds.controllerblueprints.core.data.*
import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
+import kotlin.test.assertEquals
import kotlin.test.assertNotNull
+import kotlin.test.assertNull
+import kotlin.test.assertTrue
/**
*
log.trace("Properties {}", JacksonUtils.getJson(nodeType, true))
}
+ @Test
+ fun testImports() {
+ val serviceTemplate = ServiceTemplate()
+ serviceTemplate.imports = mutableListOf()
+ val bluePrintContext = BluePrintContext(serviceTemplate)
+
+ assertTrue(bluePrintContext.imports()!!.isEmpty())
+
+ serviceTemplate.imports = null
+ assertNull(bluePrintContext.imports())
+ }
+
+ @Test
+ fun testDataTypes() {
+ val serviceTemplate = ServiceTemplate()
+ serviceTemplate.dataTypes = mutableMapOf()
+ val bluePrintContext = BluePrintContext(serviceTemplate)
+
+ assertTrue(bluePrintContext.dataTypes()!!.isEmpty())
+
+ serviceTemplate.dataTypes = null
+ assertNull(bluePrintContext.dataTypes())
+ }
+
+ @Test
+ fun testInputs() {
+ val topologyTemplate = TopologyTemplate()
+ topologyTemplate.inputs = mutableMapOf()
+ val serviceTemplate = ServiceTemplate()
+ serviceTemplate.topologyTemplate = topologyTemplate
+ val bluePrintContext = BluePrintContext(serviceTemplate)
+
+ assertTrue(bluePrintContext.inputs()!!.isEmpty())
+
+ topologyTemplate.inputs = null
+
+ assertNull(bluePrintContext.inputs())
+ }
+
+ @Test
+ fun testBluePrintJson() {
+ val serviceTemplate = ServiceTemplate()
+ val bluePrintContext = BluePrintContext(serviceTemplate)
+
+ assertEquals("{\"tosca_definitions_version\":\"controller_blueprint_1_0_0\"}", bluePrintContext.blueprintJson())
+ }
+
+ @Test(expected = BluePrintException::class)
+ fun testName() {
+ val serviceTemplate = ServiceTemplate()
+ serviceTemplate.metadata = mutableMapOf(BluePrintConstants.METADATA_TEMPLATE_NAME to "hello")
+ val bluePrintContext = BluePrintContext(serviceTemplate)
+
+ assertEquals("hello", bluePrintContext.name())
+
+ serviceTemplate.metadata = mutableMapOf()
+ val bluePrintContext2 = BluePrintContext(serviceTemplate)
+ bluePrintContext2.name()
+ }
+
+ @Test(expected = BluePrintException::class)
+ fun testVersion() {
+ val serviceTemplate = ServiceTemplate()
+ serviceTemplate.metadata = mutableMapOf(BluePrintConstants.METADATA_TEMPLATE_VERSION to "hello")
+ val bluePrintContext = BluePrintContext(serviceTemplate)
+
+ assertEquals("hello", bluePrintContext.version())
+
+ serviceTemplate.metadata = mutableMapOf()
+ val bluePrintContext2 = BluePrintContext(serviceTemplate)
+ bluePrintContext2.version()
+ }
+
+ @Test(expected = BluePrintException::class)
+ fun testAuthor() {
+ val serviceTemplate = ServiceTemplate()
+ serviceTemplate.metadata = mutableMapOf(BluePrintConstants.METADATA_TEMPLATE_AUTHOR to "hello")
+ val bluePrintContext = BluePrintContext(serviceTemplate)
+
+ assertEquals("hello", bluePrintContext.author())
+
+ serviceTemplate.metadata = mutableMapOf()
+ val bluePrintContext2 = BluePrintContext(serviceTemplate)
+ bluePrintContext2.author()
+ }
+
+ @Test
+ fun testWorkflows() {
+ val topologyTemplate = TopologyTemplate()
+ topologyTemplate.workflows = mutableMapOf()
+ val serviceTemplate = ServiceTemplate()
+ serviceTemplate.topologyTemplate = topologyTemplate
+ val bluePrintContext = BluePrintContext(serviceTemplate)
+
+ assertTrue(bluePrintContext.workflows()!!.isEmpty())
+
+ topologyTemplate.workflows = null
+ assertNull(bluePrintContext.workflows())
+ }
+
+ @Test(expected = BluePrintException::class)
+ fun testWorkFlowsByName() {
+ val topologyTemplate = TopologyTemplate()
+ topologyTemplate.workflows = mutableMapOf("workflow" to Workflow())
+ val serviceTemplate = ServiceTemplate()
+ serviceTemplate.topologyTemplate = topologyTemplate
+ val bluePrintContext = BluePrintContext(serviceTemplate)
+
+ assertNotNull(bluePrintContext.workflowByName("workflow"))
+
+ bluePrintContext.workflowByName("")
+ }
+
+ @Test
+ fun testWorkflowInput() {
+ val topologyTemplate = TopologyTemplate()
+ val workflow = Workflow()
+ workflow.inputs = mutableMapOf()
+ topologyTemplate.workflows = mutableMapOf("workflow" to workflow)
+ val serviceTemplate = ServiceTemplate()
+ serviceTemplate.topologyTemplate = topologyTemplate
+ val bluePrintContext = BluePrintContext(serviceTemplate)
+
+ assertTrue(bluePrintContext.workflowInputs("workflow")!!.isEmpty())
+
+ workflow.inputs = null
+
+ assertNull(bluePrintContext.workflowInputs("workflow"))
+ }
+
+ @Test(expected = BluePrintException::class)
+ fun testWorkflowStepByName() {
+ val topologyTemplate = TopologyTemplate()
+ val workflow = Workflow()
+ workflow.steps = mutableMapOf("step" to Step())
+ topologyTemplate.workflows = mutableMapOf("workflow" to workflow)
+ val serviceTemplate = ServiceTemplate()
+ serviceTemplate.topologyTemplate = topologyTemplate
+ val bluePrintContext = BluePrintContext(serviceTemplate)
+
+ assertNotNull(bluePrintContext.workflowStepByName("workflow", "step"))
+
+ bluePrintContext.workflowStepByName("workflow", "")
+ }
+
+ @Test(expected = BluePrintException::class)
+ fun testWorkflowStepNodeTemplate() {
+ val topologyTemplate = TopologyTemplate()
+ val workflow = Workflow()
+ val step = Step()
+ step.target = "hello"
+ workflow.steps = mutableMapOf("step" to step)
+ topologyTemplate.workflows = mutableMapOf("workflow" to workflow)
+ val serviceTemplate = ServiceTemplate()
+ serviceTemplate.topologyTemplate = topologyTemplate
+ val bluePrintContext = BluePrintContext(serviceTemplate)
+
+ assertEquals("hello", bluePrintContext.workflowStepNodeTemplate("workflow", "step"))
+
+ bluePrintContext.workflowStepNodeTemplate("workflow", "")
+ }
+
+ @Test(expected = BluePrintException::class)
+ fun testWorkflowFirstStepNodeTemplate() {
+ val topologyTemplate = TopologyTemplate()
+ val workflow = Workflow()
+ val step = Step()
+ step.target = "hello"
+ workflow.steps = mutableMapOf("step" to step, "step2" to Step())
+ topologyTemplate.workflows = mutableMapOf("workflow" to workflow)
+ val serviceTemplate = ServiceTemplate()
+ serviceTemplate.topologyTemplate = topologyTemplate
+ val bluePrintContext = BluePrintContext(serviceTemplate)
+
+ assertEquals("hello", bluePrintContext.workflowFirstStepNodeTemplate("workflow"))
+
+ workflow.steps = null
+ bluePrintContext.workflowFirstStepNodeTemplate("workflow")
+ }
+
+ @Test(expected = BluePrintException::class)
+ fun testWorkflowStepFirstCallOperation() {
+ val topologyTemplate = TopologyTemplate()
+ val workflow = Workflow()
+ val step = Step()
+ val activity = Activity()
+ activity.callOperation = "hello"
+ step.activities = arrayListOf(activity)
+ workflow.steps = mutableMapOf("step" to step)
+ topologyTemplate.workflows = mutableMapOf("workflow" to workflow)
+ val serviceTemplate = ServiceTemplate()
+ serviceTemplate.topologyTemplate = topologyTemplate
+ val bluePrintContext = BluePrintContext(serviceTemplate)
+
+ assertEquals("hello", bluePrintContext.workflowStepFirstCallOperation("workflow", "step"))
+
+ bluePrintContext.workflowStepFirstCallOperation("workflow", "")
+ }
+
+ @Test
+ fun testDatatypeByName() {
+ val serviceTemplate = ServiceTemplate()
+ serviceTemplate.dataTypes = mutableMapOf("data" to DataType())
+ val bluePrintContext = BluePrintContext(serviceTemplate)
+
+ assertNotNull(bluePrintContext.dataTypeByName("data"))
+ assertNull(bluePrintContext.dataTypeByName(""))
+ }
+
+ @Test
+ fun testArtifactTypes() {
+ val serviceTemplate = ServiceTemplate()
+ serviceTemplate.artifactTypes = mutableMapOf()
+ val bluePrintContext = BluePrintContext(serviceTemplate)
+
+ assertTrue(bluePrintContext.artifactTypes()!!.isEmpty())
+
+ serviceTemplate.artifactTypes = null
+ assertNull(bluePrintContext.artifactTypes())
+ }
+
+ @Test
+ fun testPolicyTypes() {
+ val serviceTemplate = ServiceTemplate()
+ serviceTemplate.policyTypes = mutableMapOf()
+ val bluePrintContext = BluePrintContext(serviceTemplate)
+
+ assertTrue(bluePrintContext.policyTypes()!!.isEmpty())
+
+ serviceTemplate.policyTypes = null
+ assertNull(bluePrintContext.policyTypes())
+ }
+
+ @Test(expected = BluePrintException::class)
+ fun testPolicyTypeByName() {
+ val serviceTemplate = ServiceTemplate()
+ serviceTemplate.policyTypes = mutableMapOf("policy" to PolicyType())
+ val bluePrintContext = BluePrintContext(serviceTemplate)
+
+ assertNotNull(bluePrintContext.policyTypeByName("policy"))
+ bluePrintContext.policyTypeByName("")
+ }
+
+ @Test
+ fun testPolicyTypesDerivedFrom() {
+ val serviceTemplate = ServiceTemplate()
+ val policyType = PolicyType()
+ policyType.derivedFrom = "hi"
+ val policyType2 = PolicyType()
+ policyType2.derivedFrom = "hello"
+ serviceTemplate.policyTypes = mutableMapOf("policy" to policyType, "policy2" to policyType2)
+ val bluePrintContext = BluePrintContext(serviceTemplate)
+
+ assertEquals(1, bluePrintContext.policyTypesDerivedFrom("hi")!!.size)
+
+ serviceTemplate.policyTypes = null
+ assertNull(bluePrintContext.policyTypesDerivedFrom("hi"))
+ }
+
+ @Test
+ fun testPolicyTypesTarget() {
+ val serviceTemplate = ServiceTemplate()
+ val policyType = PolicyType()
+ policyType.targets = mutableListOf("hi")
+ val policyType2 = PolicyType()
+ policyType2.targets = mutableListOf()
+ serviceTemplate.policyTypes = mutableMapOf("policy" to policyType, "policy2" to policyType2)
+ val bluePrintContext = BluePrintContext(serviceTemplate)
+
+ assertEquals(1, bluePrintContext.policyTypesTarget("hi")!!.size)
+
+ serviceTemplate.policyTypes = null
+ assertNull(bluePrintContext.policyTypesTarget("hi"))
+ }
+
+ @Test
+ fun testPolicyTypesTargetNDerivedFrom() {
+ val serviceTemplate = ServiceTemplate()
+ val policyType = PolicyType()
+ policyType.targets = mutableListOf("hi")
+ policyType.derivedFrom = "hi"
+ val policyType2 = PolicyType()
+ policyType2.targets = mutableListOf()
+ policyType2.derivedFrom = "hi"
+ serviceTemplate.policyTypes = mutableMapOf("policy" to policyType, "policy2" to policyType2)
+ val bluePrintContext = BluePrintContext(serviceTemplate)
+
+ assertEquals(1, bluePrintContext.policyTypesTargetNDerivedFrom("hi", "hi")!!.size)
+
+ serviceTemplate.policyTypes = null
+ assertNull(bluePrintContext.policyTypesTargetNDerivedFrom("hi", "hi"))
+ }
+
+ @Test
+ fun testNodeTypeDerivedFrom() {
+ val serviceTemplate = ServiceTemplate()
+ val nodeType = NodeType()
+ nodeType.derivedFrom = "hi"
+ val nodeType2 = NodeType()
+ nodeType2.derivedFrom = "hiii"
+ serviceTemplate.nodeTypes = mutableMapOf("node" to nodeType, "node2" to nodeType2)
+ val bluePrintContext = BluePrintContext(serviceTemplate)
+
+ assertEquals(1, bluePrintContext.nodeTypeDerivedFrom("hi")!!.size)
+
+ serviceTemplate.nodeTypes = null
+ assertNull(bluePrintContext.nodeTypeDerivedFrom("hi"))
+ }
+
+ @Test(expected = BluePrintException::class)
+ fun testInterfaceNameForNodeType() {
+ val serviceTemplate = ServiceTemplate()
+ val nodeType = NodeType()
+ nodeType.interfaces = mutableMapOf("hello" to InterfaceDefinition(), "hi" to InterfaceDefinition())
+ serviceTemplate.nodeTypes = mutableMapOf("node" to nodeType)
+ val bluePrintContext = BluePrintContext(serviceTemplate)
+
+ assertEquals("hello", bluePrintContext.interfaceNameForNodeType("node"))
+
+ bluePrintContext.interfaceNameForNodeType("")
+ }
+
+ @Test
+ fun testNodeTemplateForNodeType() {
+ val serviceTemplate = ServiceTemplate()
+ val nodeTemplate = NodeTemplate()
+ nodeTemplate.type = "hello"
+ val nodeTemplate2 = NodeTemplate()
+ nodeTemplate2.type = "hi"
+ serviceTemplate.topologyTemplate = TopologyTemplate()
+ serviceTemplate.topologyTemplate!!.nodeTemplates = mutableMapOf("node" to nodeTemplate, "node2" to nodeTemplate2)
+ val bluePrintContext = BluePrintContext(serviceTemplate)
+
+ assertEquals(1, bluePrintContext.nodeTemplateForNodeType("hello")!!.size)
+
+ serviceTemplate.topologyTemplate!!.nodeTemplates = null
+ assertNull(bluePrintContext.nodeTemplateForNodeType("hello"))
+ }
+
+ @Test
+ fun testNodeTemplateProperty() {
+ val serviceTemplate = ServiceTemplate()
+ val nodeTemplate = NodeTemplate()
+ nodeTemplate.properties = mutableMapOf("prop" to ObjectMapper().createObjectNode())
+ serviceTemplate.topologyTemplate = TopologyTemplate()
+ serviceTemplate.topologyTemplate!!.nodeTemplates = mutableMapOf("node" to nodeTemplate)
+ val bluePrintContext = BluePrintContext(serviceTemplate)
+
+ assertNotNull(bluePrintContext.nodeTemplateProperty("node", "prop"))
+
+ assertNull(bluePrintContext.nodeTemplateProperty("node", ""))
+
+ nodeTemplate.properties = null
+ assertNull(bluePrintContext.nodeTemplateProperty("node", "prop"))
+ }
+
+ @Test
+ fun testNodeTemplateArtifacts() {
+ val serviceTemplate = ServiceTemplate()
+ val nodeTemplate = NodeTemplate()
+ nodeTemplate.artifacts = mutableMapOf()
+ serviceTemplate.topologyTemplate = TopologyTemplate()
+ serviceTemplate.topologyTemplate!!.nodeTemplates = mutableMapOf("node" to nodeTemplate)
+ val bluePrintContext = BluePrintContext(serviceTemplate)
+
+ assertTrue(bluePrintContext.nodeTemplateArtifacts("node")!!.isEmpty())
+ }
+
+ @Test(expected = BluePrintException::class)
+ fun testNodeTemplateArtifact() {
+ val serviceTemplate = ServiceTemplate()
+ val nodeTemplate = NodeTemplate()
+ nodeTemplate.artifacts = mutableMapOf("art" to ArtifactDefinition())
+ serviceTemplate.topologyTemplate = TopologyTemplate()
+ serviceTemplate.topologyTemplate!!.nodeTemplates = mutableMapOf("node" to nodeTemplate)
+ val bluePrintContext = BluePrintContext(serviceTemplate)
+
+ assertNotNull(bluePrintContext.nodeTemplateArtifact("node", "art"))
+
+ bluePrintContext.nodeTemplateArtifact("node", "")
+ }
+
+ @Test(expected = BluePrintException::class)
+ fun testNodeTemplateArtifactForArtifactType() {
+ val serviceTemplate = ServiceTemplate()
+ val nodeTemplate = NodeTemplate()
+ val artifactDefinition = ArtifactDefinition()
+ artifactDefinition.type = "type"
+ val artifactDefinition2 = ArtifactDefinition()
+ artifactDefinition2.type = "No type"
+ nodeTemplate.artifacts = mutableMapOf("art" to artifactDefinition, "art2" to artifactDefinition2)
+ serviceTemplate.topologyTemplate = TopologyTemplate()
+ serviceTemplate.topologyTemplate!!.nodeTemplates = mutableMapOf("node" to nodeTemplate)
+ val bluePrintContext = BluePrintContext(serviceTemplate)
+
+ assertNotNull(bluePrintContext.nodeTemplateArtifactForArtifactType("node", "type"))
+
+ bluePrintContext.nodeTemplateArtifactForArtifactType("", "")
+ }
+
+ @Test(expected = BluePrintException::class)
+ fun testNodeTemplateFirstInterface() {
+ val serviceTemplate = ServiceTemplate()
+ val nodeTemplate = NodeTemplate()
+ nodeTemplate.interfaces = mutableMapOf("interface" to InterfaceAssignment(), "interf" to InterfaceAssignment())
+ serviceTemplate.topologyTemplate = TopologyTemplate()
+ serviceTemplate.topologyTemplate!!.nodeTemplates = mutableMapOf("node" to nodeTemplate)
+ val bluePrintContext = BluePrintContext(serviceTemplate)
+
+ assertNotNull(bluePrintContext.nodeTemplateFirstInterface("node"))
+
+ nodeTemplate.interfaces = null
+ bluePrintContext.nodeTemplateFirstInterface("node")
+ }
+
+ @Test(expected = BluePrintException::class)
+ fun testNodeTemplateFirstInterfaceName() {
+ val serviceTemplate = ServiceTemplate()
+ val nodeTemplate = NodeTemplate()
+ nodeTemplate.interfaces = mutableMapOf("interface" to InterfaceAssignment(), "interf" to InterfaceAssignment())
+ serviceTemplate.topologyTemplate = TopologyTemplate()
+ serviceTemplate.topologyTemplate!!.nodeTemplates = mutableMapOf("node" to nodeTemplate)
+ val bluePrintContext = BluePrintContext(serviceTemplate)
+
+ assertEquals("interface", bluePrintContext.nodeTemplateFirstInterfaceName("node"))
+
+ nodeTemplate.interfaces = null
+ bluePrintContext.nodeTemplateFirstInterfaceName("node")
+ }
+
+ @Test(expected = BluePrintException::class)
+ fun testNodeTemplateFirstInterfaceFirstOperationName() {
+ val serviceTemplate = ServiceTemplate()
+ val nodeTemplate = NodeTemplate()
+ val interfaceAssignment = InterfaceAssignment()
+ interfaceAssignment.operations = mutableMapOf("op" to OperationAssignment(), "op2" to OperationAssignment())
+ nodeTemplate.interfaces = mutableMapOf("intf" to interfaceAssignment)
+ serviceTemplate.topologyTemplate = TopologyTemplate()
+ serviceTemplate.topologyTemplate!!.nodeTemplates = mutableMapOf("node" to nodeTemplate)
+ val bluePrintContext = BluePrintContext(serviceTemplate)
+
+ assertEquals("op", bluePrintContext.nodeTemplateFirstInterfaceFirstOperationName("node"))
+
+ interfaceAssignment.operations = null
+ bluePrintContext.nodeTemplateFirstInterfaceFirstOperationName("node")
+ }
+
+ @Test(expected = BluePrintException::class)
+ fun testNodeTemplateCapability() {
+ val serviceTemplate = ServiceTemplate()
+ val nodeTemplate = NodeTemplate()
+ nodeTemplate.capabilities = mutableMapOf("cap" to CapabilityAssignment())
+ serviceTemplate.topologyTemplate = TopologyTemplate()
+ serviceTemplate.topologyTemplate!!.nodeTemplates = mutableMapOf("node" to nodeTemplate)
+ val bluePrintContext = BluePrintContext(serviceTemplate)
+
+ assertNotNull(bluePrintContext.nodeTemplateCapability("node", "cap"))
+
+ bluePrintContext.nodeTemplateCapability("node", "")
+ }
+
+ @Test(expected = BluePrintException::class)
+ fun testNodeTemplateRequirement() {
+ val serviceTemplate = ServiceTemplate()
+ val nodeTemplate = NodeTemplate()
+ nodeTemplate.requirements = mutableMapOf("req" to RequirementAssignment())
+ serviceTemplate.topologyTemplate = TopologyTemplate()
+ serviceTemplate.topologyTemplate!!.nodeTemplates = mutableMapOf("node" to nodeTemplate)
+ val bluePrintContext = BluePrintContext(serviceTemplate)
+
+ assertNotNull(bluePrintContext.nodeTemplateRequirement("node", "req"))
+
+ bluePrintContext.nodeTemplateRequirement("node", "")
+ }
+
+ @Test(expected = BluePrintException::class)
+ fun testNodeTemplateRequirementNode() {
+ val serviceTemplate = ServiceTemplate()
+ val nodeTemplate = NodeTemplate()
+ val requirementAssignment = RequirementAssignment()
+ requirementAssignment.node = "node"
+ nodeTemplate.requirements = mutableMapOf("req" to requirementAssignment)
+ serviceTemplate.topologyTemplate = TopologyTemplate()
+ serviceTemplate.topologyTemplate!!.nodeTemplates = mutableMapOf("node" to nodeTemplate)
+ val bluePrintContext = BluePrintContext(serviceTemplate)
+
+ assertNotNull(bluePrintContext.nodeTemplateRequirementNode("node", "req"))
+
+ bluePrintContext.nodeTemplateRequirementNode("node", "")
+ }
+
+ @Test
+ fun testNodeTemplateCapabilityProperty() {
+ val serviceTemplate = ServiceTemplate()
+ val nodeTemplate = NodeTemplate()
+ val capabilityAssignment = CapabilityAssignment()
+ capabilityAssignment.properties = mutableMapOf("prop" to ObjectMapper().createObjectNode())
+ nodeTemplate.capabilities = mutableMapOf("cap" to capabilityAssignment)
+ serviceTemplate.topologyTemplate = TopologyTemplate()
+ serviceTemplate.topologyTemplate!!.nodeTemplates = mutableMapOf("node" to nodeTemplate)
+ val bluePrintContext = BluePrintContext(serviceTemplate)
+
+ assertNotNull(bluePrintContext.nodeTemplateCapabilityProperty("node", "cap", "prop"))
+
+ capabilityAssignment.properties = null
+
+ assertNull(bluePrintContext.nodeTemplateCapabilityProperty("node", "cap", "prop"))
+ }
}
<parent>
<artifactId>modules</artifactId>
<groupId>org.onap.ccsdk.cds.controllerblueprints</groupId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>blueprint-scripts</artifactId>
<parent>
<groupId>org.onap.ccsdk.cds.controllerblueprints</groupId>
<artifactId>modules</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
</parent>
<artifactId>blueprint-validation</artifactId>
<name>Controller Blueprints Validation Service</name>
<parent>
<groupId>org.onap.ccsdk.cds.controllerblueprints</groupId>
<artifactId>modules</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
</parent>
<artifactId>db-resources</artifactId>
<name>Controller Blueprints DB Resources</name>
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onap.ccsdk.cds.controllerblueprints</groupId>
<artifactId>parent</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
<relativePath>../parent</relativePath>
</parent>
<artifactId>modules</artifactId>
<parent>
<groupId>org.onap.ccsdk.cds.controllerblueprints</groupId>
<artifactId>modules</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
</parent>
<artifactId>resource-dict</artifactId>
<name>Controller Blueprints Resource Dictionary</name>
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onap.ccsdk.cds.controllerblueprints</groupId>
<artifactId>modules</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
</parent>
<artifactId>service</artifactId>
<name>Controller Blueprints Service</name>
<parent>
<groupId>org.onap.ccsdk.cds</groupId>
<artifactId>controllerblueprints</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
</parent>
<groupId>org.onap.ccsdk.cds.controllerblueprints</groupId>
<artifactId>parent</artifactId>
<parent>
<groupId>org.onap.ccsdk.cds</groupId>
<artifactId>ms</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>controllerblueprints</artifactId>
<name>Controller Blueprints Root</name>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
<properties>
<service.name>ControllerBlueprints</service.name>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
* See the License for the specific language governing permissions and
* limitations under the License.
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onap.ccsdk.cds</groupId>
<artifactId>parent</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>ms</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Micro-services Root</name>
<?xml version="1.0" encoding="UTF-8"?>
<!--
- ~ Copyright (C) 2019 Bell Canada. All rights reserved.
+ ~ Copyright © 2019 Bell Canada.
~
- ~ NOTICE: All the intellectual and technical concepts contained herein are
- ~ proprietary to Bell Canada and are protected by trade secret or copyright law.
- ~ Unauthorized copying of this file, via any medium is strictly prohibited.
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onap.ccsdk.cds.sdclistener</groupId>
<artifactId>parent</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
<relativePath>../parent</relativePath>
</parent>
<artifactId>application</artifactId>
<packaging>jar</packaging>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
<name>SDC Listener Application</name>
<properties>
import java.nio.file.Paths;
import java.util.List;
import java.util.Objects;
-import java.util.Optional;
import org.onap.ccsdk.cds.sdclistener.dto.SdcListenerDto;
import org.onap.ccsdk.cds.sdclistener.service.ListenerService;
import org.onap.ccsdk.cds.sdclistener.status.SdcListenerStatus;
+import org.onap.ccsdk.cds.sdclistener.status.SdcListenerStatus.NotificationType;
import org.onap.ccsdk.cds.sdclistener.util.FileUtil;
import org.onap.sdc.api.IDistributionClient;
import org.onap.sdc.api.consumer.INotificationCallback;
*/
private void downloadCsarArtifacts(IArtifactInfo info, IDistributionClient distributionClient) {
final String url = info.getArtifactURL();
+ sdcListenerDto.setArtifactUrl(url);
final String id = info.getArtifactUUID();
+ final String distributionId = sdcListenerDto.getDistributionId();
if (Objects.equals(info.getArtifactType(), SdcListenerConfiguration.TOSCA_CSAR)) {
LOGGER.info("Trying to download the artifact from : {} and UUID is {} ", url, id);
IDistributionClientDownloadResult result = distributionClient.download(info);
if (!Objects.equals(result.getDistributionActionResult(), SUCCESS)) {
- String errorMessage = String.format("Failed to download the artifact from : %s due to %s ", url,
+ final String errorMessage = String.format("Failed to download the artifact from : %s due to %s ", url,
result.getDistributionActionResult());
- listenerStatus.sendResponseStatusBackToSDC(sdcListenerDto.getDistributionId(),
- DistributionStatusEnum.COMPONENT_DONE_ERROR, errorMessage);
+ listenerStatus
+ .sendResponseBackToSdc(distributionId, DistributionStatusEnum.DOWNLOAD_ERROR, errorMessage,
+ url, NotificationType.DOWNLOAD);
LOGGER.error(errorMessage);
} else {
+ listenerStatus.sendResponseBackToSdc(distributionId, DistributionStatusEnum.DOWNLOAD_OK, null, url,
+ NotificationType.DOWNLOAD);
LOGGER.info("Trying to write CSAR artifact to file with URL {} and UUID {}", url, id);
processCsarArtifact(result);
}
}
}
- public void processCsarArtifact(IDistributionClientDownloadResult result) {
+ private void processCsarArtifact(IDistributionClientDownloadResult result) {
Path cbaArchivePath = Paths.get(pathToStoreArchives, "cba-archive");
Path csarArchivePath = Paths.get(pathToStoreArchives, "csar-archive");
// Extract and store the CSAR archive into local disk.
- listenerService.extractCsarAndStore(result, csarArchivePath.toString());
+ listenerService.extractCsarAndStore(result, csarArchivePath);
- Optional<List<File>> csarFiles = FileUtil.getFilesFromDisk(csarArchivePath);
+ List<File> csarFiles = FileUtil.getFilesFromDisk(csarArchivePath);
- if (csarFiles.isPresent()) {
- //Extract CBA archive from CSAR package and store it into local disk.
- List<File> files = csarFiles.get();
+ if (!csarFiles.isEmpty()) {
+ final String archivePath = cbaArchivePath.toString();
- if (!files.isEmpty()) {
- final String archivePath = cbaArchivePath.toString();
- files.forEach(file -> listenerService.extractBluePrint(file.getAbsolutePath(), archivePath));
- files.forEach(file -> FileUtil.deleteFile(file, archivePath));
- } else {
- LOGGER.error("The CSAR file is not present at this location {}", csarArchivePath);
- }
+ //Extract CBA archive from CSAR package and store it into local disk
+ csarFiles.forEach(file -> listenerService.extractBluePrint(file.getAbsolutePath(), archivePath));
+ csarFiles.forEach(file -> FileUtil.deleteFile(file, csarArchivePath.toString()));
+ } else {
+ LOGGER.error("Could not able to read CSAR files from this location {}", csarArchivePath);
}
listenerService.saveBluePrintToCdsDatabase(cbaArchivePath, sdcListenerDto.getManagedChannelForGrpc());
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.onap.ccsdk.cds.sdclistener.client;
import io.grpc.CallOptions;
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.onap.ccsdk.cds.sdclistener.controller;
import org.springframework.http.MediaType;
@Value("${listenerservice.config.grpcPort}")
private int grpcPort;
+ private String artifactUrl;
+
@Autowired
private SdcListenerAuthClientInterceptor sdcListenerAuthClientInterceptor;
public ManagedChannel getManagedChannelForGrpc() {
return managedChannel;
}
+
+ public String getArtifactUrl() {
+ return artifactUrl;
+ }
+
+ public void setArtifactUrl(String artifactUrl) {
+ this.artifactUrl = artifactUrl;
+ }
}
* @param result - IDistributionClientDownloadResult contains payload.
* @param csarArchivePath The destination path where CSAR will be stored.
*/
- void extractCsarAndStore(IDistributionClientDownloadResult result, String csarArchivePath);
+ void extractCsarAndStore(IDistributionClientDownloadResult result, Path csarArchivePath);
}
/*
- * Copyright © 2017-2019 AT&T, Bell Canada
+ * Copyright © 2019 Bell Canada
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.onap.ccsdk.cds.sdclistener.service;
-import static java.nio.file.Files.walk;
+import static java.lang.String.format;
+import static org.onap.ccsdk.cds.sdclistener.status.SdcListenerStatus.NotificationType.SDC_LISTENER_COMPONENT;
import static org.onap.sdc.utils.DistributionStatusEnum.COMPONENT_DONE_ERROR;
import static org.onap.sdc.utils.DistributionStatusEnum.COMPONENT_DONE_OK;
import com.google.protobuf.ByteString;
import java.nio.file.Paths;
import java.util.Enumeration;
import java.util.List;
-import java.util.Optional;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.apache.commons.io.FileUtils;
import org.apache.tomcat.util.http.fileupload.IOUtils;
+import org.onap.ccsdk.cds.controllerblueprints.common.api.Status;
+import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintUploadInput;
+import org.onap.ccsdk.cds.controllerblueprints.management.api.FileChunk;
import org.onap.ccsdk.cds.sdclistener.client.SdcListenerAuthClientInterceptor;
import org.onap.ccsdk.cds.sdclistener.dto.SdcListenerDto;
import org.onap.ccsdk.cds.sdclistener.handler.BluePrintProcesssorHandler;
import org.onap.ccsdk.cds.sdclistener.status.SdcListenerStatus;
import org.onap.ccsdk.cds.sdclistener.util.FileUtil;
-import org.onap.ccsdk.cds.controllerblueprints.common.api.Status;
-import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintUploadInput;
-import org.onap.ccsdk.cds.controllerblueprints.management.api.FileChunk;
import org.onap.sdc.api.results.IDistributionClientDownloadResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Value("${listenerservice.config.grpcPort}")
private int grpcPort;
- private static final String CBA_ZIP_PATH = "Artifacts/Resources/[a-zA-Z0-9-_]+/Deployment/CONTROLLER_BLUEPRINT_ARCHIVE/[a-zA-Z0-9-_]+[.]zip";
+ private static final String CBA_ZIP_PATH = "Artifacts/[a-zA-Z0-9-_.]+/Deployment/CONTROLLER_BLUEPRINT_ARCHIVE/[a-zA-Z0-9-_.()]+[.]zip";
private static final int SUCCESS_CODE = 200;
private static final Logger LOGGER = LoggerFactory.getLogger(ListenerServiceImpl.class);
@Override
public void extractBluePrint(String csarArchivePath, String cbaArchivePath) {
+ int validPathCount = 0;
+ final String distributionId = getDistributionId();
+ final String artifactUrl = getArtifactUrl();
Path cbaStorageDir = getStorageDirectory(cbaArchivePath);
try (ZipFile zipFile = new ZipFile(csarArchivePath)) {
Enumeration<? extends ZipEntry> entries = zipFile.entries();
ZipEntry entry = entries.nextElement();
String fileName = entry.getName();
if (Pattern.matches(CBA_ZIP_PATH, fileName)) {
+ validPathCount++;
final String cbaArchiveName = Paths.get(fileName).getFileName().toString();
LOGGER.info("Storing the CBA archive {}", cbaArchiveName);
storeBluePrint(zipFile, cbaArchiveName, cbaStorageDir, entry);
}
}
+ if (validPathCount == 0) {
+ LOGGER
+ .info("CBA archive doesn't exist in the CSAR Package or it doesn't exist as per the given path {}",
+ CBA_ZIP_PATH);
+ listenerStatus.sendResponseBackToSdc(distributionId, COMPONENT_DONE_OK, null,
+ artifactUrl, SDC_LISTENER_COMPONENT);
+ }
+
} catch (Exception e) {
- LOGGER.error("Failed to extract blueprint {}", e);
+ final String errorMessage = format("Failed to extract blueprint %s", e.getMessage());
+ listenerStatus.sendResponseBackToSdc(distributionId, COMPONENT_DONE_ERROR, errorMessage,
+ artifactUrl, SDC_LISTENER_COMPONENT);
+ LOGGER.error(errorMessage);
}
}
@Override
public void saveBluePrintToCdsDatabase(Path cbaArchivePath, ManagedChannel channel) {
- Optional<List<File>> zipFiles = FileUtil.getFilesFromDisk(cbaArchivePath);
- zipFiles.ifPresent(files -> prepareRequestForCdsBackend(files, channel, cbaArchivePath.toString()));
+ List<File> zipFiles = FileUtil.getFilesFromDisk(cbaArchivePath);
+ if (!zipFiles.isEmpty()) {
+ prepareRequestForCdsBackend(zipFiles, channel, cbaArchivePath.toString());
+ }
}
@Override
- public void extractCsarAndStore(IDistributionClientDownloadResult result, String csarArchivePath) {
+ public void extractCsarAndStore(IDistributionClientDownloadResult result, Path csarArchivePath) {
// Create CSAR storage directory
- Path csarStorageDir = getStorageDirectory(csarArchivePath);
+ Path csarStorageDir = getStorageDirectory(csarArchivePath.toString());
byte[] payload = result.getArtifactPayload();
String csarFileName = result.getArtifactFilename();
Path targetLocation = csarStorageDir.resolve(csarFileName);
try (FileOutputStream outFile = new FileOutputStream(targetCsarFile)) {
outFile.write(payload, 0, payload.length);
+ if (!csarArchivePath.toFile().exists()) {
+ LOGGER.error("Could not able to store the CSAR at this location {}", csarArchivePath);
+ }
} catch (Exception e) {
- LOGGER.error("Failed to put CSAR file into target location {}, {}", targetLocation, e);
+ LOGGER.error("Fail to write the data into FileOutputStream {}, {}", targetLocation, e);
}
}
}
private void prepareRequestForCdsBackend(List<File> files, ManagedChannel managedChannel, String path) {
- final String distributionId = sdcListenerDto.getDistributionId();
+ final String distributionId = getDistributionId();
+ final String artifactUrl = getArtifactUrl();
files.forEach(zipFile -> {
try {
- final BluePrintUploadInput request = generateBluePrintUploadInputBuilder(zipFile);
+ final BluePrintUploadInput request = generateBluePrintUploadInputBuilder(zipFile, path);
// Send request to CDS Backend.
final Status responseStatus = bluePrintProcesssorHandler.sendRequest(request, managedChannel);
if (responseStatus.getCode() != SUCCESS_CODE) {
- final String errorMessage = String.format("Failed to store the CBA archive into CDS DB due to %s",
+ final String errorMessage = format("Failed to store the CBA archive into CDS DB due to %s",
responseStatus.getErrorMessage());
- listenerStatus.sendResponseStatusBackToSDC(distributionId,
- COMPONENT_DONE_ERROR, errorMessage);
+ listenerStatus.sendResponseBackToSdc(distributionId, COMPONENT_DONE_ERROR, errorMessage, artifactUrl,
+ SDC_LISTENER_COMPONENT);
LOGGER.error(errorMessage);
-
} else {
LOGGER.info(responseStatus.getMessage());
- listenerStatus.sendResponseStatusBackToSDC(distributionId,
- COMPONENT_DONE_OK, null);
+ listenerStatus.sendResponseBackToSdc(distributionId, COMPONENT_DONE_OK, null, artifactUrl,
+ SDC_LISTENER_COMPONENT);
}
} catch (Exception e) {
- final String errorMessage = String.format("Failure due to %s", e.getMessage());
- listenerStatus.sendResponseStatusBackToSDC(distributionId, COMPONENT_DONE_ERROR, errorMessage);
- LOGGER.error("Failure due to {}", e);
- } finally {
- FileUtil.deleteFile(zipFile, path);
+ final String errorMessage = format("Failure due to %s", e.getMessage());
+ listenerStatus.sendResponseBackToSdc(distributionId, COMPONENT_DONE_ERROR, errorMessage, artifactUrl,
+ SDC_LISTENER_COMPONENT);
+ LOGGER.error(errorMessage);
}
});
}
- private BluePrintUploadInput generateBluePrintUploadInputBuilder(File file) throws IOException {
+ private BluePrintUploadInput generateBluePrintUploadInputBuilder(File file, String path) throws IOException {
byte[] bytes = FileUtils.readFileToByteArray(file);
FileChunk fileChunk = FileChunk.newBuilder().setChunk(ByteString.copyFrom(bytes)).build();
-
+ FileUtil.deleteFile(file, path);
return BluePrintUploadInput.newBuilder()
.setFileChunk(fileChunk)
.build();
}
+
+ private String getDistributionId() {
+ return sdcListenerDto.getDistributionId();
+ }
+
+ private String getArtifactUrl() {
+ return sdcListenerDto.getArtifactUrl();
+ }
}
*/
package org.onap.ccsdk.cds.sdclistener.status;
-import org.onap.sdc.api.consumer.IFinalDistrStatusMessage;
+import org.onap.sdc.api.consumer.IComponentDoneStatusMessage;
+import org.onap.sdc.api.consumer.IDistributionStatusMessage;
import org.onap.sdc.utils.DistributionStatusEnum;
-public class DistributionStatusMessage implements IFinalDistrStatusMessage {
+public class ComponentStatusMessage implements IComponentDoneStatusMessage, IDistributionStatusMessage {
public String componentName;
public DistributionStatusEnum status;
+ public long timeStamp;
+
+ public String artifactUrl;
+
@Override
public String getDistributionID() {
return distributionID;
}
- @Override
- public long getTimestamp() {
- return 0;
- }
-
@Override
public DistributionStatusEnum getStatus() {
return status;
public String getComponentName() {
return componentName;
}
+
+ @Override
+ public String getArtifactURL() {
+ return artifactUrl;
+ }
+
+ @Override
+ public long getTimestamp() {
+ return timeStamp;
+ }
}
import org.onap.ccsdk.cds.sdclistener.dto.SdcListenerDto;
import org.onap.ccsdk.cds.sdclistener.util.BuilderUtil;
import org.onap.sdc.api.IDistributionClient;
-import org.onap.sdc.api.consumer.IFinalDistrStatusMessage;
+import org.onap.sdc.api.consumer.IComponentDoneStatusMessage;
+import org.onap.sdc.api.consumer.IDistributionStatusMessage;
import org.onap.sdc.api.results.IDistributionClientResult;
import org.onap.sdc.utils.DistributionStatusEnum;
import org.slf4j.Logger;
@Autowired
private SdcListenerDto sdcListenerDto;
+ public enum NotificationType {
+ DOWNLOAD, SDC_LISTENER_COMPONENT;
+ }
+
/**
- * Send the response back to SDC.
- *
+ * Send the component status back to SDC.
* @param distributionID SDC Distribution ID
* @param status Distribution status
- * @param errorReason Reason of failure
+ * @param errorReason Reason of failure if present
+ * @param url Artifact URL
+ * @param type - NotificationType(Download or Component)
*/
- public void sendResponseStatusBackToSDC(String distributionID, DistributionStatusEnum status, String errorReason) {
-
+ public void sendResponseBackToSdc(String distributionID, DistributionStatusEnum status, String errorReason,
+ String url, NotificationType type) {
final IDistributionClient distributionClient = sdcListenerDto.getDistributionClient();
- IFinalDistrStatusMessage finalDistribution = new BuilderUtil<>(new DistributionStatusMessage())
- .build(builder -> {
- builder.distributionID = distributionID;
- builder.status = status;
- builder.consumerID = consumerId;
- builder.componentName = COMPONENT_NAME;
- }).create();
+ switch (type) {
+ case SDC_LISTENER_COMPONENT:
+ IComponentDoneStatusMessage componentStatusMessage = buildStatusMessage(distributionID, status, url,
+ COMPONENT_NAME);
- if (errorReason == null) {
- checkResponseStatusFromSdc(distributionClient.sendFinalDistrStatus(finalDistribution));
- } else {
- checkResponseStatusFromSdc(distributionClient.sendFinalDistrStatus(finalDistribution, errorReason));
+ if (errorReason == null) {
+ checkResponseStatusFromSdc(distributionClient.sendComponentDoneStatus(componentStatusMessage));
+ } else {
+ checkResponseStatusFromSdc(
+ distributionClient.sendComponentDoneStatus(componentStatusMessage, errorReason));
+ }
+ break;
+
+ case DOWNLOAD:
+ IDistributionStatusMessage downloadStatusMessage = buildStatusMessage(distributionID, status, url,
+ null);
+
+ if (errorReason == null) {
+ checkResponseStatusFromSdc(distributionClient.sendDownloadStatus(downloadStatusMessage));
+ } else {
+ checkResponseStatusFromSdc(
+ distributionClient.sendDownloadStatus(downloadStatusMessage, errorReason));
+ }
+ default:
+ break;
}
}
+ private ComponentStatusMessage buildStatusMessage(String distributionId, DistributionStatusEnum status, String url,
+ String componentName) {
+ return new BuilderUtil<>(new ComponentStatusMessage()).build(builder -> {
+ builder.distributionID = distributionId;
+ builder.status = status;
+ builder.consumerID = consumerId;
+ builder.componentName = componentName;
+ builder.timeStamp = System.currentTimeMillis();
+ builder.artifactUrl = url;
+ }).create();
+ }
+
private void checkResponseStatusFromSdc(IDistributionClientResult result) {
if (!Objects.equals(result.getDistributionActionResult(), SUCCESS)) {
LOGGER.error("SDC failed to receive the response from cds-sdc listener due to {}",
/*
- * Copyright (C) 2019 Bell Canada. All rights reserved.
+ * Copyright © 2019 Bell Canada
*
- * NOTICE: All the intellectual and technical concepts contained herein are
- * proprietary to Bell Canada and are protected by trade secret or copyright law.
- * Unauthorized copying of this file, via any medium is strictly prohibited.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package org.onap.ccsdk.cds.sdclistener.util;
/*
- * Copyright (C) 2019 Bell Canada. All rights reserved.
+ * Copyright © 2019 Bell Canada
*
- * NOTICE: All the intellectual and technical concepts contained herein are
- * proprietary to Bell Canada and are protected by trade secret or copyright law.
- * Unauthorized copying of this file, via any medium is strictly prohibited.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
-
package org.onap.ccsdk.cds.sdclistener.util;
import static java.nio.file.Files.walk;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.util.ArrayList;
import java.util.List;
-import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.commons.io.FileUtils;
* @param path where files reside.
* @return list of files.
*/
- public static Optional<List<File>> getFilesFromDisk(Path path) {
+ public static List<File> getFilesFromDisk(Path path) {
+
try (Stream<Path> fileTree = walk(path)) {
// Get the list of files from the path
- return Optional.of(fileTree.filter(Files::isRegularFile)
- .map(Path::toFile)
- .collect(Collectors.toList()));
+ return fileTree.filter(Files::isRegularFile)
+ .map(Path::toFile)
+ .collect(Collectors.toList());
} catch (IOException e) {
LOGGER.error("Failed to find the file due to", e);
}
- return Optional.empty();
+ return new ArrayList<>();
}
}
package org.onap.ccsdk.cds.sdclistener.service;
import static junit.framework.TestCase.assertTrue;
+import static org.onap.ccsdk.cds.sdclistener.status.SdcListenerStatus.NotificationType.SDC_LISTENER_COMPONENT;
+import static org.onap.sdc.utils.DistributionStatusEnum.COMPONENT_DONE_OK;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoRule;
import org.onap.ccsdk.cds.sdclistener.SdcListenerConfiguration;
import org.onap.ccsdk.cds.sdclistener.client.SdcListenerAuthClientInterceptor;
import org.onap.ccsdk.cds.sdclistener.dto.SdcListenerDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {ListenerServiceImplTest.class})
public class ListenerServiceImplTest {
- private static final String CSAR_SAMPLE = "src/test/resources/service-Testsvc140.csar";
+ private static final String CSAR_SAMPLE = "src/test/resources/service-ServicePnfTest-csar.csar";
+ private static final String WRONG_CSAR_SAMPLE = "src/test/resources/wrong_csar_pattern.csar";
+ private static final String CBA_ZIP_PATH = "Artifacts/[a-zA-Z0-9-_.]+/Deployment/CONTROLLER_BLUEPRINT_ARCHIVE/[a-zA-Z0-9-_.()]+[.]zip";
private static final String ZIP_FILE = ".zip";
private static final String CSAR_FILE = ".csar";
+ private static final String DISTRIBUTION_ID = "1";
+ private static final String URL = "/sdc/v1/artifact";
+
+
private String csarArchivePath;
private Path tempDirectoryPath;
@Rule
public TemporaryFolder folder = new TemporaryFolder();
+ @Rule
+ public MockitoRule mockitoRule = MockitoJUnit.rule();
+
@Autowired
private ListenerServiceImpl listenerService;
+ @MockBean
+ SdcListenerStatus status;
+
+ @MockBean
+ SdcListenerDto listenerDto;
+
@Before
public void setup() {
+ MockitoAnnotations.initMocks(this);
csarArchivePath = folder.getRoot().toString();
tempDirectoryPath = Paths.get(csarArchivePath, "cds-sdc-listener-test");
}
+
@Test
public void extractBluePrintSuccessfully() throws IOException {
// Act
listenerService.extractBluePrint(CSAR_SAMPLE, tempDirectoryPath.toString());
- // Verify
+ // Verify.
String result = checkFileExists(tempDirectoryPath);
assertTrue(result.contains(ZIP_FILE));
}
+ @Test
+ public void extractBluePrintFailure() {
+ // Arrange
+ Mockito.when(listenerDto.getDistributionId()).thenReturn(DISTRIBUTION_ID);
+ Mockito.when(listenerDto.getArtifactUrl()).thenReturn(URL);
+ Mockito.doCallRealMethod().when(status)
+ .sendResponseBackToSdc(DISTRIBUTION_ID, COMPONENT_DONE_OK, null, URL, SDC_LISTENER_COMPONENT);
+
+ // Act
+ listenerService.extractBluePrint(WRONG_CSAR_SAMPLE, tempDirectoryPath.toString());
+
+ // Verify
+ Mockito.verify(status)
+ .sendResponseBackToSdc(DISTRIBUTION_ID, COMPONENT_DONE_OK, null, URL, SDC_LISTENER_COMPONENT);
+ }
+
@Test
public void storeCsarArtifactToFileSuccessfully() throws IOException {
// Arrange
DistributionClientDownloadResultStubImpl resultStub = new DistributionClientDownloadResultStubImpl();
// Act
- listenerService.extractCsarAndStore(resultStub, tempDirectoryPath.toString());
+ listenerService.extractCsarAndStore(resultStub, tempDirectoryPath);
// Verify
String result = checkFileExists(tempDirectoryPath);
<parent>
<groupId>org.onap.ccsdk.cds.sdclistener</groupId>
<artifactId>parent</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
<relativePath>../parent</relativePath>
</parent>
<artifactId>distribution</artifactId>
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onap.ccsdk.cds</groupId>
<artifactId>sdclistener</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
</parent>
<groupId>org.onap.ccsdk.cds.sdclistener</groupId>
<artifactId>parent</artifactId>
<grpc.version>1.18.0</grpc.version>
<protobuff.java.utils.version>3.6.1</protobuff.java.utils.version>
<eelf.version>1.0.0</eelf.version>
- <sli.version>0.4.2-SNAPSHOT</sli.version>
<guava.version>27.0.1-jre</guava.version>
<onap.logger.slf4j>1.2.2</onap.logger.slf4j>
<powermock.version>1.7.4</powermock.version>
<parent>
<groupId>org.onap.ccsdk.cds</groupId>
<artifactId>ms</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
+<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2019 Bell Canada
See the License for the specific language governing permissions and
limitations under the License.
-->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.onap.ccsdk.parent</groupId>
<artifactId>odlparent-lite</artifactId>
- <version>1.2.2-SNAPSHOT</version>
+ <version>1.3.0-SNAPSHOT</version>
<relativePath/>
</parent>
<groupId>org.onap.ccsdk.cds</groupId>
<artifactId>parent</artifactId>
- <version>0.4.2-SNAPSHOT</version>
+ <version>0.5.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>cds-parent</name>
</profile>
</profiles>
-</project>
\ No newline at end of file
+</project>
release_name=0
-sprint_number=4
-feature_revision=2
+sprint_number=5
+feature_revision=0
base_version=${release_name}.${sprint_number}.${feature_revision}