blob: 74fe86a4bf858a7e5a580efff2fd5c3bb6b1eaf5 [file] [log] [blame]
asgaraf56b682019-03-08 19:52:33 +05301/*
2============LICENSE_START==========================================
3===================================================================
4Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
5===================================================================
6
7Unless otherwise specified, all software contained herein is licensed
8under the Apache License, Version 2.0 (the License);
9you may not use this software except in compliance with the License.
10You may obtain a copy of the License at
11
12 http://www.apache.org/licenses/LICENSE-2.0
13
14Unless required by applicable law or agreed to in writing, software
15distributed under the License is distributed on an "AS IS" BASIS,
16WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17See the License for the specific language governing permissions and
18limitations under the License.
19
20============LICENSE_END============================================
21*/
22
23import { Component, OnInit } from '@angular/core';
24import { ActivatedRoute, Router } from '@angular/router';
25import { HttpUtilService } from '../shared/services/httpUtil/http-util.service';
26import { MappingEditorService } from '../shared/services/mapping-editor.service';
27import { ParamShareService } from '../shared/services/paramShare.service';
28import { environment } from '../../environments/environment';
29import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
30import { NgProgress } from 'ngx-progressbar';
31import { APIService } from "../shared/services/cdt.apicall";
32import { UtilityService } from '../shared/services/utilityService/utility.service';
33import { NotificationsService } from 'angular2-notifications';
34
35
36@Component({ selector: 'admin', templateUrl: './admin.component.html', styleUrls: ['./admin.component.css']})
37export class AdminComponent implements OnInit {
38 displayAnsibleServerData: Array<Object> = [];
39 ansibleServerData;
40 sortOrder = false;
41 noData = false;
42 sortBy: string;
43 filter: Object = {};
44 noDataMsg: string;
45 errorMessage = '';
46 invalid = true;
47 currentUser;
48 fileName = "ansible_admin_FQDN_Artifact_0.0.1V.json";
49
50 options = {
51 timeOut: 4000,
52 showProgressBar: true,
53 pauseOnHover: true,
54 clickToClose: true,
55 maxLength: 200
56 };
57
58 constructor (
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
69 ) {
70 }
71
72 ngOnInit() {
73 const apiToken = localStorage['apiToken'];
74 this.currentUser = localStorage['userId'];
75
76 if(this.paramShareService.ansibleServerData) {
77 this.ansibleServerData = this.paramShareService.ansibleServerData;
78 console.log("cached ansibleServerData===>"+JSON.stringify(this.ansibleServerData));
79 this.formatRawData();
80 } else {
81 //testing
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();
85 this.getArtifacts();
86 }
87
88 }
89
90 getArtifacts() {
91
92 const input = {
93 "input":{
94 "design-request":{
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\"}"
98 }
99 }
100 };
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));
105
106 this.ngProgress.start();
107
108 this.apiService.callGetArtifactsApi(input).subscribe(data => {
109
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();
117 }
118 this.ngProgress.done();
119 },
120 error => {
121
122 this.nService.error('Error',
123 'Error in connecting to APPC Server', this.options );
124 });
125
126
127 }
128
129 formatRawData(){
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];
144 }
145 let clouditem = "";
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"];
149 let cloudrow;
150 let ownerid = cloud;
151
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}))
165 }
166
167 }
168
169 }
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"];
178
179 }
180 }
181
182
183
184 viewAnbsibleServer(selectedConfig, updateIndex) {
185 sessionStorage.setItem('updateIndex', updateIndex);
186 sessionStorage.setItem('ansibleserver', JSON.stringify(selectedConfig));
187
188 this
189 .router
190 .navigate(['../ansible-server'], {
191 relativeTo: this.activeROute
192 });
193 }
194
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));
198
199 if(this.ansibleServerData) {
200 sessionStorage.setItem('updateIndex', this.ansibleServerData["fqdn-list"].length);
201 } else {
202 sessionStorage.setItem('updateIndex', '0');
203 }
204
205 this
206 .router
207 .navigate(['../ansible-server'], {
208 relativeTo: this.activeROute
209 });
210 }
211
212
213 saveToAppc() {
214 let artifactContent = this.utilService.appendSlashes(JSON.stringify(this.paramShareService.ansibleServerData));
215 let input = {
216 "input": {
217 "design-request": {
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+"\"}",
221 }
222 }
223 }
224 let response = this.apiService.callGetArtifactsApi(input);
225 response.subscribe(response => {
226 this.utilService.processApiSubscribe(response, this.utilService.putAction, "admin artifact");
227 //this.clearCache();
228 },
229 error => this.utilService.processApiError());
230 }
231
232 // ngOnDestroy() {
233 // console.log("destry....")
234 // }
235
236 clearCache() {
237 this.paramShareService.ansibleServerData = undefined;
238 sessionStorage.removeItem('ansibleserver');
239 }
240
241 download() {
242 if(this.ansibleServerData){
243 this.utilService.downloadArtifactToPc(JSON.stringify(this.ansibleServerData, null, '\t'), "json", this.fileName, 100)
244 }
245 }
246
247}