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 * as XLSX from 'xlsx';
24 import * as _ from 'underscore';
26 import { ActivatedRoute, Router } from '@angular/router';
27 import { Component, OnInit, ViewChild } from '@angular/core';
28 import { Observable } from 'rxjs/Observable';
29 import { UtilityService } from '../../shared/services/utilityService/utility.service';
31 // Common Confirm Modal
32 import { DialogService } from 'ng2-bootstrap-modal';
33 import { ParamShareService } from '../../shared/services/paramShare.service';
37 type AOA = Array<Array<any>>;
40 selector: 'ansible-server',
41 templateUrl: './ansible-server.component.html',
42 styleUrls: ['./ansible-server.component.css'],
44 export class AnsibleServerComponent implements OnInit {
46 //settings for the notifications.
49 showProgressBar: true,
56 public regionIdErrMsg;
58 public zeroTenantIdsErrorMsg;
59 public porterrorMessage;
60 public portwarningMessage;
62 public warningMessage;
63 public invalid = true;
64 public portinvalid = true;
66 public sample = {ownerid:"", regionid:"", tenantid:""};
70 private paramShareService: ParamShareService,
71 private router: Router,
72 private activeROute: ActivatedRoute,
73 private utilService: UtilityService
77 console.log("testing....");
81 this.currentUser = localStorage['userId'];
82 this.item = JSON.parse(sessionStorage.getItem("ansibleserver"));
83 this.updateIndex = parseInt(sessionStorage.getItem("updateIndex"));
84 console.log("index===>"+this.updateIndex);
85 if(!this.paramShareService.ansibleServerData) {
90 console.log("selecteditem===>"+JSON.stringify(this.item));
94 console.log("selectediteminfo===>"+JSON.stringify(this.item.info));
95 if(this.validateTenantId()) {
96 this.item.info.push(this.sample)
97 this.sample = {ownerid:"", regionid:"", tenantid:""};
98 this.zeroTenantIdsErrorMsg = "";
104 console.log("selectediteminfo===>"+index+JSON.stringify(this.item.info));
105 this.item.info.splice(index, 1);
106 console.log("selectediteminfo===>"+JSON.stringify(this.item.info));
111 // console.log("ansibleServerData===>"+ JSON.stringify(this.paramShareService.ansibleServerData))
112 // let ansibleServer = this.createAnsibleserverData(this.item);
113 // this.paramShareService.ansibleServerData["fqdn-list"].push(ansibleServer);
114 // this.router.navigate(['../admin'], {
115 // relativeTo: this.activeROute
120 console.log("ansibleServerData===>"+ JSON.stringify(this.paramShareService.ansibleServerData))
123 let ansibleServer = this.createAnsibleserverData(this.item);
124 //need to revisit to initialize paramShareService.ansibleServerData
125 if(!this.paramShareService.ansibleServerData) {
126 this.paramShareService.ansibleServerData = {"fqdn-list" : []};
128 if(this.updateIndex != this.paramShareService.ansibleServerData["fqdn-list"].length) {
129 ansibleServer["modify-username"] = this.currentUser;
130 ansibleServer["modify-date"] = this.utilService.getDate();
131 console.log("update........")
133 this.paramShareService.ansibleServerData["fqdn-list"][this.updateIndex] = ansibleServer;
134 this.router.navigate(['../admin'], {
135 relativeTo: this.activeROute
142 sessionStorage.removeItem("ansibleserver");
143 this.router.navigate(['../admin'], {
144 relativeTo: this.activeROute
148 createAnsibleserverData(displayAnsibleServer){
149 let cloudOwnerList = this.createCloudOwnerList(displayAnsibleServer);
151 "vnf-management-server-fqdn": displayAnsibleServer.server+":"+displayAnsibleServer.port,
152 "cloud-owner-list":cloudOwnerList,
153 "description":displayAnsibleServer.descr,
154 "username":displayAnsibleServer.creator,
155 "create-date":displayAnsibleServer['created-date'],
156 "modify-username":displayAnsibleServer.modifier,
157 "modify-date":displayAnsibleServer['modified-date']
163 createCloudOwnerList(displayAnsibleServer) {
164 let cloudOwnerList = [];
166 //prepare unique cloud-owner
167 for(let i=0; i<displayAnsibleServer.info.length; i++) {
168 let info = displayAnsibleServer.info[i];
170 cloudOwner["cloud-owner"] = info.ownerid;
172 cloudOwnerList.forEach(element => {
173 if(element["cloud-owner"] == info.ownerid) {
179 cloudOwnerList.push(cloudOwner);
183 console.log("cloudOwnerList===>"+JSON.stringify(cloudOwnerList));
186 cloudOwnerList.forEach(cloudOwner => {
187 let regionIdList = [];
188 for(let i=0; i<displayAnsibleServer.info.length; i++) {
189 let info = displayAnsibleServer.info[i];
190 if(cloudOwner["cloud-owner"] == info.ownerid) {
192 regionIdList.forEach(element => {
193 if(element["region-id"] == info.regionid) {
198 regionIdList.push({"region-id":info.regionid});
203 cloudOwner["region-id-list"] = regionIdList;
206 console.log("cloudOwnerList===>"+JSON.stringify(cloudOwnerList));
209 cloudOwnerList.forEach(cloudOwner => {
210 cloudOwner["region-id-list"].forEach(regionid => {
211 let teanantIdList = [];
212 for(let i=0; i<displayAnsibleServer.info.length; i++) {
213 let info = displayAnsibleServer.info[i];
214 if(cloudOwner["cloud-owner"] == info.ownerid && regionid["region-id"] == info.regionid) {
216 teanantIdList.forEach(element => {
217 if(element == info.tenantid) {
222 teanantIdList.push(info.tenantid);
227 regionid["tenant-id-list"] = teanantIdList;
230 console.log("cloudOwnerList===>"+JSON.stringify(cloudOwnerList));
231 return cloudOwnerList;
234 //validating the fdqn url
236 if (fdqn.trim().length < 1) {
237 this.errorMessage = 'Please enter Configuration Server FQDN';
238 this.warningMessage = '';
240 } else if (fdqn.startsWith(' ') || fdqn.endsWith(' ')) {
241 this.errorMessage = 'Leading and trailing spaces are not allowed';
242 this.warningMessage = '';
244 } else if (!(fdqn.startsWith('http') || fdqn.endsWith('https'))) {
245 this.warningMessage = 'FDQN can start with eighther http or https protocol';
246 this.errorMessage = '';
247 this.invalid = false;
249 // } else if (name.includes(' ')) {
250 // this.errorMessage = 'More than one space is not allowed in VNFC Type';
251 // this.invalid = true;
252 // } else if (name.length > 50) {
253 // this.errorMessage = 'VNFC Type should be of minimum one character and maximum 50 character';
254 // this.invalid = true;
257 this.invalid = false;
258 this.errorMessage = '';
259 this.warningMessage = '';
263 //validating the port
265 if (port.trim().length < 1) {
266 this.porterrorMessage = 'Please enter port';
267 this.portwarningMessage = '';
269 } else if (port.startsWith(' ') || port.endsWith(' ')) {
270 this.porterrorMessage = 'Leading and trailing spaces are not allowed';
271 this.portwarningMessage = '';
274 } else if (isNaN(port)) {
275 this.portwarningMessage = '';
276 this.porterrorMessage = 'Port should be a number';
278 port = parseInt(port);
279 } else if (!(0 <= port && port <= 65535 )) {
280 this.portwarningMessage = 'Port should be a number in range of 0 to 65535';
281 this.porterrorMessage = '';
282 this.invalid = false;
284 this.invalid = false;
285 this.porterrorMessage = '';
286 this.portwarningMessage = '';
291 this.validateFdqn(this.item.server);
292 this.validatePort(this.item.port);
293 if(this.item.info.length <= 0) {
294 this.zeroTenantIdsErrorMsg = "Please add atleast one Tenant ID.";
304 if(this.sample.ownerid.trim().length == 0) {
305 this.ownerIdErrMsg = "Enter OwnerID";
308 this.ownerIdErrMsg = "";
310 if(this.sample.regionid.trim().length == 0) {
311 this.regionIdErrMsg = "Enter RegionID";
314 this.regionIdErrMsg = "";
316 if(this.sample.tenantid.trim().length == 0) {
317 this.tenantIdErrMsg = "Enter TenantID";
320 this.tenantIdErrMsg = "";