2 ============LICENSE_START==========================================
3 ===================================================================
4 Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
5 ===================================================================
7 Unless otherwise specified, all software contained herein is licensed
8 under the Apache License, Version 2.0 (the License);
9 you may not use this software except in compliance with the License.
10 You may obtain a copy of the License at
12 http://www.apache.org/licenses/LICENSE-2.0
14 Unless required by applicable law or agreed to in writing, software
15 distributed under the License is distributed on an "AS IS" BASIS,
16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 See the License for the specific language governing permissions and
18 limitations under the License.
20 ============LICENSE_END============================================
23 import { Component, OnInit } from '@angular/core';
24 import { ActivatedRoute, Router } from '@angular/router';
25 import { HttpUtilService } from '../shared/services/httpUtil/http-util.service';
26 import { MappingEditorService } from '../shared/services/mapping-editor.service';
27 import { ParamShareService } from '../shared/services/paramShare.service';
28 import { environment } from '../../environments/environment';
29 import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
30 import { NgProgress } from 'ngx-progressbar';
31 import { APIService } from "../shared/services/cdt.apicall";
32 import { UtilityService } from '../shared/services/utilityService/utility.service';
33 import { NotificationsService } from 'angular2-notifications';
36 @Component({ selector: 'admin', templateUrl: './admin.component.html', styleUrls: ['./admin.component.css']})
37 export class AdminComponent implements OnInit {
38 displayAnsibleServerData: Array<Object> = [];
48 fileName = "ansible_admin_FQDN_Artifact_0.0.1V.json";
52 showProgressBar: true,
59 private paramShareService: ParamShareService,
60 private ngProgress: NgProgress,
61 private httpUtil: HttpUtilService,
62 private router: Router,
63 private activeROute: ActivatedRoute,
64 private mappingEditorService: MappingEditorService,
65 private modalService: NgbModal,
66 private apiService:APIService,
67 private utilService: UtilityService,
68 private nService: NotificationsService
73 const apiToken = localStorage['apiToken'];
74 this.currentUser = localStorage['userId'];
76 if(this.paramShareService.ansibleServerData) {
77 this.ansibleServerData = this.paramShareService.ansibleServerData;
78 console.log("cached ansibleServerData===>"+JSON.stringify(this.ansibleServerData));
82 //this.ansibleServerData = "{\"fqdn-list\":[{\"vnf-management-server-fqdn\": \"fqdn-value1:url\:port\",\"cloud-owner-list\":[{\"cloud-owner\": \"owner1\",\"region-id-list\": [{\"region-id\": \"regiodnid1\",\"tenant-id-list\": [\"tenantid1\",\"tenantid2\"]},{\"region-id\": \"regiondid2\",\"tenant-id-list\": [\"tenantid1\",\"tenantid2\"]}]},{\"cloud-owner\": \"owner2\",\"region-id-list\": [{\"region-id\": \"regionid1\",\"tenant-id-list\": [\"tenantid1\",\"tenantid2\"]}]}],\"description\": \"fqdn for east zone vUSP Production\",\"username\": \"albino attuid\",\"create-date\": \"\",\"modify-username\": \"Asgar\",\"modify-date\": \"10/26/2018\"}]}";
83 //this.ansibleServerData = JSON.parse(this.ansibleServerData);
84 //this.formatRawData();
95 "request-id":localStorage['apiToken'],
96 "action":"getArtifact",
97 "payload":"{\"vnf-type\":\"NULL\",\"vnfc-type\":\"NULL\",\"protocol\":\"\",\"incart\":\"N\",\"action\":\"NULL\",\"artifact-name\":\""+this.fileName+"\",\"artifact-type\":\"APPC-CONFIG\",\"userID\":\"admin\"}"
101 //const x = JSON.parse(data.input['design-request']['payload']);
102 //x.userID = localStorage['userId'];
103 //data.input['design-request']['payload'] = JSON.stringify(x);
104 console.log("input to payload====", JSON.stringify(input));
106 this.ngProgress.start();
108 this.apiService.callGetArtifactsApi(input).subscribe(data => {
110 if( this.utilService.checkResult(data)) {
111 console.log("response===>"+JSON.stringify(data));
112 this.ansibleServerData = JSON.parse(data.output.data.block).artifactInfo[0]["artifact-content"];
113 this.ansibleServerData = JSON.parse(this.ansibleServerData);
114 console.log("ansibleServerData===>"+JSON.stringify(this.ansibleServerData))
115 this.paramShareService.ansibleServerData = this.ansibleServerData;
116 this.formatRawData();
118 this.ngProgress.done();
122 this.nService.error('Error',
123 'Error in connecting to APPC Server', this.options );
130 this.displayAnsibleServerData = [this.ansibleServerData["fqdn-list"].length];
131 console.log("length==>"+this.ansibleServerData["fqdn-list"].length)
132 for(let i=0;i<this.ansibleServerData["fqdn-list"].length;i++) {
133 let fqdl = this.ansibleServerData["fqdn-list"][i];
134 this.displayAnsibleServerData[i] = {};
135 let cloudInfoArray = [];
136 let serverAndPort = fqdl["vnf-management-server-fqdn"];
137 this.displayAnsibleServerData[i]['serverandport'] = serverAndPort;
138 let splitArray = serverAndPort.split(":");
139 let regEx = new RegExp(":"+splitArray[splitArray.length-1]+"$", "g");
140 this.displayAnsibleServerData[i]['server'] = serverAndPort.replace(regEx, "");
141 this.displayAnsibleServerData[i]['port'] = "";
142 if(splitArray.length > 1) {
143 this.displayAnsibleServerData[i]['port'] = splitArray[splitArray.length-1];
146 for(let j=0; j<fqdl["cloud-owner-list"].length;j++) {
147 let cloudOwnerItem = fqdl["cloud-owner-list"][j];
148 let cloud = cloudOwnerItem["cloud-owner"];
152 for(let k=0; k<cloudOwnerItem["region-id-list"].length; k++) {
153 let regionItem = cloudOwnerItem["region-id-list"][k];
154 let regionrow = cloud + " / " + regionItem["region-id"];
155 let regionid = regionItem["region-id"];
156 console.log("regionrow : "+regionrow);
157 for(let m=0; m<regionItem["tenant-id-list"].length; m++) {
158 cloudrow = regionrow + " / " + regionItem["tenant-id-list"][m]+"\n";
159 console.log("cloudrow : "+cloudrow);
160 clouditem = clouditem + cloudrow;
161 console.log("clouditem : "+clouditem);
162 let tenantid = regionItem["tenant-id-list"][m];
163 cloudInfoArray.push({"ownerid": ownerid, "regionid": regionid, "tenantid": tenantid});
164 console.log("info===>"+JSON.stringify({"ownerid": ownerid, "regionid": regionid, "tenantid": tenantid}))
170 console.log("info array==>"+JSON.stringify(cloudInfoArray))
171 this.displayAnsibleServerData[i]["info"] = cloudInfoArray;
172 this.displayAnsibleServerData[i]["cloud"] = clouditem;
173 this.displayAnsibleServerData[i]["descr"] = fqdl["description"];
174 this.displayAnsibleServerData[i]["creator"] = fqdl["username"];
175 this.displayAnsibleServerData[i]["created-date"] = fqdl["create-date"];
176 this.displayAnsibleServerData[i]["modifier"] = fqdl["modify-username"];
177 this.displayAnsibleServerData[i]["modified-date"] = fqdl["modify-date"];
184 viewAnbsibleServer(selectedConfig, updateIndex) {
185 sessionStorage.setItem('updateIndex', updateIndex);
186 sessionStorage.setItem('ansibleserver', JSON.stringify(selectedConfig));
190 .navigate(['../ansible-server'], {
191 relativeTo: this.activeROute
195 createAnsibleServer() {
196 let newServer = {"server":"","port":"","info":[],"cloud":"","descr":"","creator":this.currentUser,"created-date":this.utilService.getDate(),"modifier":"","modified-date":""};
197 sessionStorage.setItem('ansibleserver', JSON.stringify(newServer));
199 if(this.ansibleServerData) {
200 sessionStorage.setItem('updateIndex', this.ansibleServerData["fqdn-list"].length);
202 sessionStorage.setItem('updateIndex', '0');
207 .navigate(['../ansible-server'], {
208 relativeTo: this.activeROute
214 let artifactContent = this.utilService.appendSlashes(JSON.stringify(this.paramShareService.ansibleServerData));
218 "request-id": localStorage['apiToken'],
219 "action": "uploadAdminArtifact",
220 "payload": "{\"userID\": \"admin\",\"vnf-type\" : \"NULL \",\"action\" : \"NULL\",\"artifact-name\" : \""+this.fileName+"\",\"artifact-type\" : \"APPC-CONFIG\",\"artifact-version\" : \"0.1\",\"artifact-contents\":\""+artifactContent+"\"}",
224 let response = this.apiService.callGetArtifactsApi(input);
225 response.subscribe(response => {
226 this.utilService.processApiSubscribe(response, this.utilService.putAction, "admin artifact");
229 error => this.utilService.processApiError());
233 // console.log("destry....")
237 this.paramShareService.ansibleServerData = undefined;
238 sessionStorage.removeItem('ansibleserver');
242 if(this.ansibleServerData){
243 this.utilService.downloadArtifactToPc(JSON.stringify(this.ansibleServerData, null, '\t'), "json", this.fileName, 100)