2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.ci.tests.utils.general;
23 import com.aventstack.extentreports.Status;
24 import com.google.gson.Gson;
25 import fj.data.Either;
26 import org.apache.commons.codec.binary.Base64;
27 import org.apache.commons.lang3.tuple.Pair;
28 import org.json.JSONException;
29 import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
30 import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory;
31 import org.openecomp.sdc.be.datatypes.elements.ConsumerDataDefinition;
32 import org.openecomp.sdc.be.datatypes.enums.AssetTypeEnum;
33 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
34 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
35 import org.openecomp.sdc.be.model.*;
36 import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
37 import org.openecomp.sdc.ci.tests.api.ExtentTestActions;
38 import org.openecomp.sdc.ci.tests.api.Urls;
39 import org.openecomp.sdc.ci.tests.config.Config;
40 import org.openecomp.sdc.ci.tests.datatypes.*;
41 import org.openecomp.sdc.ci.tests.datatypes.enums.*;
42 import org.openecomp.sdc.ci.tests.datatypes.http.HttpHeaderEnum;
43 import org.openecomp.sdc.ci.tests.datatypes.http.HttpRequest;
44 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
45 import org.openecomp.sdc.ci.tests.execute.lifecycle.LCSbaseTest;
46 import org.openecomp.sdc.ci.tests.tosca.datatypes.ToscaDefinition;
47 import org.openecomp.sdc.ci.tests.utils.CsarToscaTester;
48 import org.openecomp.sdc.ci.tests.utils.DistributionUtils;
49 import org.openecomp.sdc.ci.tests.utils.ToscaParserUtils;
50 import org.openecomp.sdc.ci.tests.utils.Utils;
51 import org.openecomp.sdc.ci.tests.utils.rest.*;
52 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
53 import org.openecomp.sdc.common.util.GeneralUtility;
54 import org.testng.SkipException;
57 import java.io.IOException;
58 import java.nio.file.Files;
59 import java.nio.file.Path;
60 import java.nio.file.Paths;
61 import java.util.ArrayList;
62 import java.util.HashMap;
63 import java.util.List;
65 import java.util.Map.Entry;
66 import java.util.concurrent.TimeUnit;
68 import static org.testng.AssertJUnit.assertEquals;
69 import static org.testng.AssertJUnit.assertTrue;
71 public final class AtomicOperationUtils {
73 static final String basicAuthentication = "Basic Y2k6MTIzNDU2";
75 private AtomicOperationUtils() {
76 throw new UnsupportedOperationException();
79 // *********** RESOURCE ****************
81 * Import a vfc From tosca file
87 * @throws JSONException
89 public static Either<Resource, RestResponse> importResource(String filePath, String fileName) {
91 User designer = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER);
92 ImportReqDetails importReqDetails = ElementFactory.getDefaultImportResource(ElementFactory.getResourcePrefix());
93 importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, filePath, fileName);
94 RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, designer, null);
95 return buildResourceFromResponse(importResourceResponse);
96 } catch (Exception e) {
97 throw new AtomicOperationException(e);
101 public static Either<Resource, RestResponse> importResource(ImportReqDetails importReqDetails, String filePath, String fileName, User userRole, Boolean validateState) {
103 importReqDetails = ImportUtils.getImportResourceDetailsByPathAndName(importReqDetails, filePath, fileName);
104 RestResponse importResourceResponse = ResourceRestUtils.createImportResource(importReqDetails, userRole, null);
107 assertTrue("Import resource failed with error: " + importResourceResponse.getResponse(),importResourceResponse.getErrorCode() == ResourceRestUtils.STATUS_CODE_CREATED);
110 if (importResourceResponse.getErrorCode() == ResourceRestUtils.STATUS_CODE_CREATED) {
111 Resource resourceResponseObject = ResponseParser.convertResourceResponseToJavaObject(importResourceResponse.getResponse());
112 return Either.left(resourceResponseObject);
114 return Either.right(importResourceResponse);
115 } catch (Exception e) {
116 throw new AtomicOperationException(e);
121 public static Either<Resource, RestResponse> createResourceByType(ResourceTypeEnum resourceType, UserRoleEnum userRole, Boolean validateState) {
123 User defaultUser = ElementFactory.getDefaultUser(userRole);
124 ResourceReqDetails defaultResource = ElementFactory.getDefaultResourceByType(resourceType, defaultUser);
125 RestResponse resourceResp = ResourceRestUtils.createResource(defaultResource, defaultUser);
128 assertTrue("Create resource failed with error: " + resourceResp.getResponse(),resourceResp.getErrorCode() == ResourceRestUtils.STATUS_CODE_CREATED);
131 if (resourceResp.getErrorCode() == ResourceRestUtils.STATUS_CODE_CREATED) {
132 Resource resourceResponseObject = ResponseParser.convertResourceResponseToJavaObject(resourceResp.getResponse());
133 return Either.left(resourceResponseObject);
135 return Either.right(resourceResp);
136 } catch (Exception e) {
137 throw new AtomicOperationException(e);
141 public static Either<Resource, RestResponse> createResourceByResourceDetails(ResourceReqDetails resourceDetails, UserRoleEnum userRole, Boolean validateState) {
143 User defaultUser = ElementFactory.getDefaultUser(userRole);
144 RestResponse resourceResp = ResourceRestUtils.createResource(resourceDetails, defaultUser);
147 assertTrue("Create resource failed with error: " + resourceResp.getResponse(),resourceResp.getErrorCode() == ResourceRestUtils.STATUS_CODE_CREATED);
150 if (resourceResp.getErrorCode() == ResourceRestUtils.STATUS_CODE_CREATED) {
151 Resource resourceResponseObject = ResponseParser.convertResourceResponseToJavaObject(resourceResp.getResponse());
152 return Either.left(resourceResponseObject);
154 return Either.right(resourceResp);
155 } catch (Exception e) {
156 throw new AtomicOperationException(e);
160 public static Either<Resource, RestResponse> createResourcesByTypeNormTypeAndCatregory(ResourceTypeEnum resourceType, NormativeTypesEnum normativeTypes, ResourceCategoryEnum resourceCategory, UserRoleEnum userRole, Boolean validateState)
162 User defaultUser = ElementFactory.getDefaultUser(userRole);
163 ResourceReqDetails defaultResource = ElementFactory.getDefaultResourceByTypeNormTypeAndCatregory(resourceType, normativeTypes, resourceCategory, defaultUser);
164 RestResponse resourceResp = ResourceRestUtils.createResource(defaultResource, defaultUser);
167 assertTrue("Actual Response Code is: " + resourceResp.getErrorCode(), resourceResp.getErrorCode() == ResourceRestUtils.STATUS_CODE_CREATED);
170 if (resourceResp.getErrorCode() == ResourceRestUtils.STATUS_CODE_CREATED) {
171 // Resource resourceResponseObject = ResponseParser
172 // .convertResourceResponseToJavaObject(resourceResp.getResponse());
173 Resource resourceResponseObject = ResponseParser.parseToObjectUsingMapper(resourceResp.getResponse(), Resource.class);
174 return Either.left(resourceResponseObject);
176 return Either.right(resourceResp);
179 public static Either<Resource, RestResponse> createResourcesByCustomNormativeTypeAndCatregory(ResourceTypeEnum resourceType, Resource resourceNormativeType, ResourceCategoryEnum resourceCategory, UserRoleEnum userRole, Boolean validateState)
181 User defaultUser = ElementFactory.getDefaultUser(userRole);
182 ResourceReqDetails defaultResource = ElementFactory.getDefaultResourceByTypeNormTypeAndCatregory(resourceType, resourceNormativeType, resourceCategory, defaultUser);
183 RestResponse resourceResp = ResourceRestUtils.createResource(defaultResource, defaultUser);
186 assertTrue("Create resource failed with error: " + resourceResp.getResponse(), resourceResp.getErrorCode() == ResourceRestUtils.STATUS_CODE_CREATED);
189 if (resourceResp.getErrorCode() == ResourceRestUtils.STATUS_CODE_CREATED) {
190 // Resource resourceResponseObject = ResponseParser
191 // .convertResourceResponseToJavaObject(resourceResp.getResponse());
192 Resource resourceResponseObject = ResponseParser.parseToObjectUsingMapper(resourceResp.getResponse(), Resource.class);
193 return Either.left(resourceResponseObject);
195 return Either.right(resourceResp);
198 public static Either<Resource, RestResponse> updateResource(ResourceReqDetails resourceReqDetails, User defaultUser, Boolean validateState) {
201 RestResponse resourceResp = ResourceRestUtils.updateResource(resourceReqDetails, defaultUser, resourceReqDetails.getUniqueId());
204 assertTrue("Update resource failed with error: " + resourceResp.getResponse(),resourceResp.getErrorCode() == ResourceRestUtils.STATUS_CODE_SUCCESS);
207 if (resourceResp.getErrorCode() == ResourceRestUtils.STATUS_CODE_SUCCESS) {
208 Resource resourceResponseObject = ResponseParser.convertResourceResponseToJavaObject(resourceResp.getResponse());
209 return Either.left(resourceResponseObject);
211 return Either.right(resourceResp);
212 } catch (Exception e) {
213 throw new AtomicOperationException(e);
217 // *********** SERVICE ****************
219 public static Either<Service, RestResponse> createDefaultService(UserRoleEnum userRole, Boolean validateState) throws Exception {
220 User defaultUser = ElementFactory.getDefaultUser(userRole);
221 ServiceReqDetails serviceDetails = ElementFactory.getDefaultService(defaultUser);
222 RestResponse createServiceResp = ServiceRestUtils.createService(serviceDetails, defaultUser);
225 assertTrue("Create service failed with error: " + createServiceResp.getResponse(),createServiceResp.getErrorCode() == ServiceRestUtils.STATUS_CODE_CREATED);
228 if (createServiceResp.getErrorCode() == ResourceRestUtils.STATUS_CODE_CREATED) {
229 Service serviceResponseObject = ResponseParser.convertServiceResponseToJavaObject(createServiceResp.getResponse());
230 return Either.left(serviceResponseObject);
232 return Either.right(createServiceResp);
235 public static Either<Service, RestResponse> createServiceByCategory(ServiceCategoriesEnum category, UserRoleEnum userRole, Boolean validateState) throws Exception {
236 User defaultUser = ElementFactory.getDefaultUser(userRole);
237 ServiceReqDetails serviceDetails = ElementFactory.getDefaultService(category, defaultUser);
238 RestResponse createServiceResp = ServiceRestUtils.createService(serviceDetails, defaultUser);
241 assertTrue("Create service failed with error: " + createServiceResp.getResponse(),createServiceResp.getErrorCode() == ServiceRestUtils.STATUS_CODE_CREATED);
244 if (createServiceResp.getErrorCode() == ResourceRestUtils.STATUS_CODE_CREATED) {
245 Service serviceResponseObject = ResponseParser.convertServiceResponseToJavaObject(createServiceResp.getResponse());
246 return Either.left(serviceResponseObject);
248 return Either.right(createServiceResp);
251 public static Either<Service, RestResponse> createCustomService(ServiceReqDetails serviceDetails, UserRoleEnum userRole, Boolean validateState) throws Exception {
252 User defaultUser = ElementFactory.getDefaultUser(userRole);
253 RestResponse createServiceResp = ServiceRestUtils.createService(serviceDetails, defaultUser);
256 assertTrue("Create service failed with error: " + createServiceResp.getResponse(),createServiceResp.getErrorCode() == ServiceRestUtils.STATUS_CODE_CREATED);
259 if (createServiceResp.getErrorCode() == ResourceRestUtils.STATUS_CODE_CREATED) {
260 Service serviceResponseObject = ResponseParser.convertServiceResponseToJavaObject(createServiceResp.getResponse());
261 return Either.left(serviceResponseObject);
263 return Either.right(createServiceResp);
265 // *********** PRODUCT ****************
267 public static Either<Product, RestResponse> createDefaultProduct(UserRoleEnum userRole, Boolean validateState) throws Exception {
268 User defaultUser = ElementFactory.getDefaultUser(userRole);
269 ProductReqDetails defaultProduct = ElementFactory.getDefaultProduct();
270 RestResponse createProductResp = ProductRestUtils.createProduct(defaultProduct, defaultUser);
273 assertTrue(createProductResp.getErrorCode() == ProductRestUtils.STATUS_CODE_CREATED);
276 if (createProductResp.getErrorCode() == ProductRestUtils.STATUS_CODE_CREATED) {
277 Product productResponseJavaObject = ResponseParser.convertProductResponseToJavaObject(createProductResp.getResponse());
278 return Either.left(productResponseJavaObject);
280 return Either.right(createProductResp);
283 // public static ComponentReqDetails
284 // convertCompoentToComponentReqDetails(Component component){
286 // ComponentReqDetails componentReqDetails =
287 // ElementFactory.getDefaultService();
288 // componentReqDetails.setName(component.getName());
289 // componentReqDetails.setDescription(component.getDescription());
290 // componentReqDetails.setTags(component.getTags());
291 // componentReqDetails.setContactId(component.getContactId());
292 // componentReqDetails.setIcon(component.getIcon());
293 // componentReqDetails.setUniqueId(component.getUniqueId());
294 // componentReqDetails.setCreatorUserId(component.getCreatorUserId());
295 // componentReqDetails.setCreatorFullName(component.getCreatorFullName());
296 // componentReqDetails.setLastUpdaterUserId(component.getLastUpdaterUserId());
297 // componentReqDetails.setLastUpdaterFullName(component.getLastUpdaterFullName());
298 // componentReqDetails.setCreationDate(component.getCreationDate());
299 // componentReqDetails.setLastUpdateDate(component.getLastUpdateDate());
300 // componentReqDetails.setLifecycleState(component.getLifecycleState());
301 // componentReqDetails.setVersion(component.getVersion());
302 // componentReqDetails.setUuid(component.getUUID());
303 // componentReqDetails.setCategories(component.getCategories());
304 // componentReqDetails.setProjectCode(component.getProjectCode());
306 // return componentReqDetails;
309 // *********** LIFECYCLE ***************
311 public static Pair<Component, RestResponse> changeComponentState(Component component, UserRoleEnum userRole, LifeCycleStatesEnum targetState, Boolean validateState) throws Exception {
313 Boolean isValidationFailed = false;
314 RestResponse lifeCycleStatesResponse = null;
317 LifeCycleStatesEnum currentCompState = LifeCycleStatesEnum.findByCompState(component.getLifecycleState().toString());
319 if (currentCompState == targetState) {
320 component = getComponentObject(component, userRole);
321 return Pair.of(component, null);
323 String componentType = component.getComponentType().getValue();
324 ArrayList<String> lifeCycleStatesEnumList = new ArrayList<>();
325 if (currentCompState.equals(LifeCycleStatesEnum.CHECKIN) && targetState.equals(LifeCycleStatesEnum.CHECKOUT)) {
326 lifeCycleStatesEnumList.add(LifeCycleStatesEnum.CHECKIN.toString());
327 lifeCycleStatesEnumList.add(LifeCycleStatesEnum.CHECKOUT.toString());
328 // TODO Andrey added component type condition
330 if (componentType.equals("Resource")) {
331 lifeCycleStatesEnumList.add(LifeCycleStatesEnum.CHECKOUT.toString());
332 lifeCycleStatesEnumList.add(LifeCycleStatesEnum.CHECKIN.toString());
333 lifeCycleStatesEnumList.add(LifeCycleStatesEnum.CERTIFY.toString());
335 lifeCycleStatesEnumList.add(LifeCycleStatesEnum.CHECKOUT.toString());
336 lifeCycleStatesEnumList.add(LifeCycleStatesEnum.CHECKIN.toString());
337 lifeCycleStatesEnumList.add(LifeCycleStatesEnum.CERTIFICATIONREQUEST.toString());
338 lifeCycleStatesEnumList.add(LifeCycleStatesEnum.STARTCERTIFICATION.toString());
339 lifeCycleStatesEnumList.add(LifeCycleStatesEnum.CERTIFY.toString());
342 for (int i = 0; i < lifeCycleStatesEnumList.size(); i++) {
343 if (lifeCycleStatesEnumList.get(i).equals(currentCompState.name())) {
345 a = (i == lifeCycleStatesEnumList.size() - 1) ? 0 : i + 1;
346 for (int n = a; n < lifeCycleStatesEnumList.size(); n++) {
347 if ((lifeCycleStatesEnumList.get(n).equals(LifeCycleStatesEnum.STARTCERTIFICATION.name()) || lifeCycleStatesEnumList.get(n).equals(LifeCycleStatesEnum.CERTIFY.name())) && !componentType.equals("Resource")) {
348 defaultUser = ElementFactory.getDefaultUser(UserRoleEnum.TESTER);
350 defaultUser = ElementFactory.getDefaultUser(userRole);
352 lifeCycleStatesResponse = LifecycleRestUtils.changeComponentState(component, defaultUser, LifeCycleStatesEnum.findByState(lifeCycleStatesEnumList.get(n)));
353 if (lifeCycleStatesResponse.getErrorCode() != LifecycleRestUtils.STATUS_CODE_SUCCESS)
354 isValidationFailed = true;
355 if (lifeCycleStatesEnumList.get(n).equals(targetState.toString()) || isValidationFailed) {
361 Component componentJavaObject = getComponentObject(component, userRole);
363 if (validateState && isValidationFailed) {
364 assertTrue("change state to [" + targetState.getState() + "] failed" + lifeCycleStatesResponse.getResponse(), false);
366 return Pair.of(componentJavaObject, lifeCycleStatesResponse);
369 if (isValidationFailed) {
370 return Pair.of(componentJavaObject, lifeCycleStatesResponse);
373 return Pair.of(componentJavaObject, lifeCycleStatesResponse);
376 public static RestResponse distributeService(Component component, Boolean validateState) throws Exception {
378 Service service = (Service) component;
380 User opsUser = ElementFactory.getDefaultUser(UserRoleEnum.OPS);
381 User governotUser = ElementFactory.getDefaultUser(UserRoleEnum.GOVERNOR);
383 ServiceReqDetails serviceDetails = new ServiceReqDetails(service);
384 RestResponse distributionService = null;
386 RestResponse approveDistribution = LifecycleRestUtils.changeDistributionStatus(serviceDetails, null, governotUser, "approveService", DistributionStatusEnum.DISTRIBUTION_APPROVED);
387 if (approveDistribution.getErrorCode() == BaseRestUtils.STATUS_CODE_SUCCESS) {
388 distributionService = LifecycleRestUtils.changeDistributionStatus(serviceDetails, null, opsUser, "approveService", DistributionStatusEnum.DISTRIBUTED);
392 assertTrue("Distribution approve failed with error: " + approveDistribution.getResponse(),approveDistribution.getErrorCode() == ProductRestUtils.STATUS_CODE_SUCCESS);
393 assertTrue("Distribute service failed with error: " + distributionService.getResponse(),distributionService.getErrorCode() == ProductRestUtils.STATUS_CODE_SUCCESS);
394 return distributionService;
397 return distributionService;
400 public static void toscaValidation(Component component, String vnfFile) throws Exception {
402 ISdcCsarHelper fdntCsarHelper;
403 SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance();
404 File csarFile = AssetRestUtils.getToscaModelCsarFile(AssetTypeEnum.SERVICES, component.getUUID() , vnfFile);
405 ExtentTestActions.log(Status.INFO, "Tosca parser is going to convert service csar file to ISdcCsarHelper object...");
406 fdntCsarHelper = factory.getSdcCsarHelper(csarFile.getAbsolutePath());
407 CsarToscaTester.processCsar(fdntCsarHelper);
408 ExtentTestActions.log(Status.INFO, String.format("Tosca parser successfully parsed service CSAR"));
412 // *********** ARTIFACTS *****************
414 public static Either<ArtifactDefinition, RestResponse> uploadArtifactByType(ArtifactTypeEnum artifactType, Component component, UserRoleEnum userRole, Boolean deploymentTrue, Boolean validateState) throws Exception {
416 User defaultUser = ElementFactory.getDefaultUser(userRole);
417 ArtifactReqDetails artifactDetails = ElementFactory.getArtifactByType(null, artifactType, deploymentTrue);
419 artifactDetails.setArtifactGroupType(ArtifactGroupTypeEnum.INFORMATIONAL.getType());
420 RestResponse uploadArtifactResp = ArtifactRestUtils.uploadArtifact(artifactDetails, component, defaultUser);
423 assertTrue("artifact upload failed: " + artifactDetails.getArtifactName(), uploadArtifactResp.getErrorCode() == BaseRestUtils.STATUS_CODE_SUCCESS);
426 if (uploadArtifactResp.getErrorCode() == BaseRestUtils.STATUS_CODE_SUCCESS) {
427 ArtifactDefinition artifactJavaObject = ResponseParser.convertArtifactDefinitionResponseToJavaObject(uploadArtifactResp.getResponse());
428 return Either.left(artifactJavaObject);
430 return Either.right(uploadArtifactResp);
433 // *********** CONTAINERS *****************
435 * Adds Component instance to Component
437 * @param compInstParent
438 * @param compContainer
441 public static Either<ComponentInstance, RestResponse> addComponentInstanceToComponentContainer(Component compInstParent, Component compContainer) {
442 return addComponentInstanceToComponentContainer(compInstParent, compContainer, UserRoleEnum.DESIGNER, false);
445 public static Either<ComponentInstance, RestResponse> addComponentInstanceToComponentContainer(Component compInstParent, Component compContainer, UserRoleEnum userRole, Boolean validateState) {
447 User defaultUser = ElementFactory.getDefaultUser(userRole);
448 ComponentInstanceReqDetails componentInstanceDetails = ElementFactory.getComponentInstance(compInstParent);
449 RestResponse createComponentInstance = ComponentInstanceRestUtils.createComponentInstance(componentInstanceDetails, defaultUser, compContainer);
452 if (createComponentInstance.getErrorCode() == ServiceRestUtils.STATUS_CODE_NOT_FOUND)
454 throw new SkipException("Open bug DE262001");
457 assertTrue("error - " + createComponentInstance.getErrorCode() + "instead - " + ServiceRestUtils.STATUS_CODE_CREATED, createComponentInstance.getErrorCode() == ServiceRestUtils.STATUS_CODE_CREATED);
461 if (createComponentInstance.getErrorCode() == ResourceRestUtils.STATUS_CODE_CREATED) {
462 ComponentInstance componentInstance = ResponseParser.convertComponentInstanceResponseToJavaObject(createComponentInstance.getResponse());
463 return Either.left(componentInstance);
465 return Either.right(createComponentInstance);
466 } catch (Exception e) {
467 throw new AtomicOperationException(e);
471 public static Either<ComponentInstance, RestResponse> addComponentInstanceToComponentContainer(Component compInstParent, Component compContainer, UserRoleEnum userRole, Boolean validateState, String positionX, String positionY) {
473 User defaultUser = ElementFactory.getDefaultUser(userRole);
474 ComponentInstanceReqDetails componentInstanceDetails = ElementFactory.getComponentInstance(compInstParent);
475 componentInstanceDetails.setPosX(positionX);
476 componentInstanceDetails.setPosY(positionY);
477 RestResponse createComponentInstance = ComponentInstanceRestUtils.createComponentInstance(componentInstanceDetails, defaultUser, compContainer);
480 if (createComponentInstance.getErrorCode() == ServiceRestUtils.STATUS_CODE_NOT_FOUND)
482 throw new SkipException("Open bug DE262001");
485 assertTrue("error - " + createComponentInstance.getErrorCode() + "instead - " + ServiceRestUtils.STATUS_CODE_CREATED, createComponentInstance.getErrorCode() == ServiceRestUtils.STATUS_CODE_CREATED);
489 if (createComponentInstance.getErrorCode() == ResourceRestUtils.STATUS_CODE_CREATED) {
490 ComponentInstance componentInstance = ResponseParser.convertComponentInstanceResponseToJavaObject(createComponentInstance.getResponse());
491 return Either.left(componentInstance);
493 return Either.right(createComponentInstance);
494 } catch (Exception e) {
495 throw new AtomicOperationException(e);
499 public static Resource getResourceObject(Component containerDetails, UserRoleEnum userRole) throws Exception {
500 // User defaultUser = ElementFactory.getDefaultUser(userRole);
501 RestResponse restResponse = ResourceRestUtils.getResource(containerDetails.getUniqueId());
502 return ResponseParser.convertResourceResponseToJavaObject(restResponse.getResponse());
505 public static Resource getResourceObject(String uniqueId) throws Exception {
506 RestResponse restResponse = ResourceRestUtils.getResource(uniqueId);
507 return ResponseParser.convertResourceResponseToJavaObject(restResponse.getResponse());
510 public static Resource getResourceObjectByNameAndVersion(UserRoleEnum sdncModifierDetails, String resourceName, String resourceVersion) throws Exception {
511 User defaultUser = ElementFactory.getDefaultUser(sdncModifierDetails);
512 RestResponse resourceResponse = ResourceRestUtils.getResourceByNameAndVersion(defaultUser.getUserId(), resourceName, resourceVersion);
513 return ResponseParser.convertResourceResponseToJavaObject(resourceResponse.getResponse());
516 public static Service getServiceObject(Component containerDetails, UserRoleEnum userRole) throws Exception {
517 User defaultUser = ElementFactory.getDefaultUser(userRole);
518 RestResponse serviceResponse = ServiceRestUtils.getService(containerDetails.getUniqueId(), defaultUser);
519 return ResponseParser.convertServiceResponseToJavaObject(serviceResponse.getResponse());
522 public static Service getServiceObjectByNameAndVersion(UserRoleEnum sdncModifierDetails, String serviceName, String serviceVersion) throws Exception {
523 User defaultUser = ElementFactory.getDefaultUser(sdncModifierDetails);
524 RestResponse serviceResponse = ServiceRestUtils.getServiceByNameAndVersion(defaultUser, serviceName, serviceVersion);
525 return ResponseParser.convertServiceResponseToJavaObject(serviceResponse.getResponse());
528 public static Service getServiceObject(String uniqueId) throws Exception {
529 RestResponse serviceResponse = ServiceRestUtils.getService(uniqueId);
530 return ResponseParser.convertServiceResponseToJavaObject(serviceResponse.getResponse());
533 public static Product getProductObject(Component containerDetails, UserRoleEnum userRole) throws Exception {
534 User defaultUser = ElementFactory.getDefaultUser(userRole);
535 RestResponse productRest = ProductRestUtils.getProduct(containerDetails.getUniqueId(), defaultUser.getUserId());
536 return ResponseParser.convertProductResponseToJavaObject(productRest.getResponse());
539 public static Component getComponentObject(Component containerDetails, UserRoleEnum userRole) throws Exception {
540 User defaultUser = ElementFactory.getDefaultUser(userRole);
542 switch (containerDetails.getComponentType()) {
544 RestResponse restResponse = ResourceRestUtils.getResource(containerDetails.getUniqueId());
545 containerDetails = ResponseParser.convertResourceResponseToJavaObject(restResponse.getResponse());
548 RestResponse serviceResponse = ServiceRestUtils.getService(containerDetails.getUniqueId(), defaultUser);
549 containerDetails = ResponseParser.convertServiceResponseToJavaObject(serviceResponse.getResponse());
552 RestResponse productRest = ProductRestUtils.getProduct(containerDetails.getUniqueId(), defaultUser.getUserId());
553 containerDetails = ResponseParser.convertProductResponseToJavaObject(productRest.getResponse());
558 return containerDetails;
561 public static Component convertReposnseToComponentObject(Component containerDetails, RestResponse restresponse) {
563 switch (containerDetails.getComponentType()) {
565 containerDetails = ResponseParser.convertResourceResponseToJavaObject(restresponse.getResponse());
568 containerDetails = ResponseParser.convertServiceResponseToJavaObject(restresponse.getResponse());
571 containerDetails = ResponseParser.convertProductResponseToJavaObject(restresponse.getResponse());
576 return containerDetails;
579 public static Either<Component, RestResponse> associate2ResourceInstances(Component containerDetails, ComponentInstance fromNode, ComponentInstance toNode, String assocType, UserRoleEnum userRole, Boolean validateState) throws Exception {
581 User defaultUser = ElementFactory.getDefaultUser(userRole);
582 RestResponse associate2ResourceInstancesResponse = ResourceRestUtils.associate2ResourceInstances(containerDetails, fromNode, toNode, assocType, defaultUser);
585 assertTrue(associate2ResourceInstancesResponse.getErrorCode() == ServiceRestUtils.STATUS_CODE_SUCCESS);
588 if (associate2ResourceInstancesResponse.getErrorCode() == ResourceRestUtils.STATUS_CODE_SUCCESS) {
590 switch (containerDetails.getComponentType()) {
592 containerDetails = ResponseParser.convertResourceResponseToJavaObject(associate2ResourceInstancesResponse.getResponse());
595 containerDetails = ResponseParser.convertServiceResponseToJavaObject(associate2ResourceInstancesResponse.getResponse());
598 containerDetails = ResponseParser.convertProductResponseToJavaObject(associate2ResourceInstancesResponse.getResponse());
604 return Either.left(containerDetails);
606 return Either.right(associate2ResourceInstancesResponse);
610 public static Either<Pair<Component, ComponentInstance>, RestResponse> changeComponentInstanceVersion(Component containerDetails, ComponentInstance componentInstanceToReplace, Component newInstance, UserRoleEnum userRole, Boolean validateState)
612 User defaultUser = ElementFactory.getDefaultUser(userRole);
614 RestResponse changeComponentInstanceVersionResp = ComponentInstanceRestUtils.changeComponentInstanceVersion(containerDetails, componentInstanceToReplace, newInstance, defaultUser);
616 assertTrue("change ComponentInstance version failed: " + changeComponentInstanceVersionResp.getResponseMessage(), changeComponentInstanceVersionResp.getErrorCode() == BaseRestUtils.STATUS_CODE_SUCCESS);
619 if (changeComponentInstanceVersionResp.getErrorCode() == BaseRestUtils.STATUS_CODE_SUCCESS) {
621 Component compoenntObject = AtomicOperationUtils.getComponentObject(containerDetails, userRole);
622 ComponentInstance componentInstanceJavaObject = ResponseParser.convertComponentInstanceResponseToJavaObject(changeComponentInstanceVersionResp.getResponse());
624 return Either.left(Pair.of(compoenntObject, componentInstanceJavaObject));
627 return Either.right(changeComponentInstanceVersionResp);
630 // *********** PROPERTIES *****************
632 public static Either<ComponentInstanceProperty, RestResponse> addCustomPropertyToResource(PropertyReqDetails propDetails, Resource resourceDetails, UserRoleEnum userRole, Boolean validateState) throws Exception {
634 User defaultUser = ElementFactory.getDefaultUser(userRole);
635 Map<String, PropertyReqDetails> propertyToSend = new HashMap<>();
636 propertyToSend.put(propDetails.getName(), propDetails);
637 Gson gson = new Gson();
638 RestResponse addPropertyResponse = PropertyRestUtils.createProperty(resourceDetails.getUniqueId(), gson.toJson(propertyToSend), defaultUser);
641 assertTrue("add property to resource failed: " + addPropertyResponse.getErrorCode(), addPropertyResponse.getErrorCode() == BaseRestUtils.STATUS_CODE_CREATED);
644 if (addPropertyResponse.getErrorCode() == BaseRestUtils.STATUS_CODE_CREATED) {
645 ComponentInstanceProperty compInstProp = null;
646 String property = ResponseParser.getJsonObjectValueByKey(addPropertyResponse.getResponse(), propDetails.getName());
647 compInstProp = (ResponseParser.convertPropertyResponseToJavaObject(property));
648 return Either.left(compInstProp);
650 return Either.right(addPropertyResponse);
654 public static Either<ComponentInstanceProperty, RestResponse> updatePropertyOfResource(PropertyReqDetails propDetails, Resource resourceDetails, String propertyUniqueId, UserRoleEnum userRole, Boolean validateState) throws Exception {
656 User defaultUser = ElementFactory.getDefaultUser(userRole);
657 Map<String, PropertyReqDetails> propertyToSend = new HashMap<>();
658 propertyToSend.put(propDetails.getName(), propDetails);
659 Gson gson = new Gson();
660 RestResponse addPropertyResponse = PropertyRestUtils.updateProperty(resourceDetails.getUniqueId(), propertyUniqueId, gson.toJson(propertyToSend), defaultUser);
663 assertTrue("add property to resource failed: " + addPropertyResponse.getResponseMessage(), addPropertyResponse.getErrorCode() == BaseRestUtils.STATUS_CODE_SUCCESS);
666 if (addPropertyResponse.getErrorCode() == BaseRestUtils.STATUS_CODE_SUCCESS) {
667 ComponentInstanceProperty compInstProp = null;
668 String property = ResponseParser.getJsonObjectValueByKey(addPropertyResponse.getResponse(), propDetails.getName());
669 compInstProp = (ResponseParser.convertPropertyResponseToJavaObject(property));
670 return Either.left(compInstProp);
672 return Either.right(addPropertyResponse);
675 public static RestResponse deletePropertyOfResource(String resourceId, String propertyId, UserRoleEnum userRole) throws Exception {
676 User defaultUser = ElementFactory.getDefaultUser(userRole);
677 return PropertyRestUtils.deleteProperty(resourceId, propertyId, defaultUser);
680 public static Either<ComponentInstanceProperty, RestResponse> addDefaultPropertyToResource(PropertyTypeEnum propertyType, Resource resourceDetails, UserRoleEnum userRole, Boolean validateState) throws Exception {
682 User defaultUser = ElementFactory.getDefaultUser(userRole);
683 PropertyReqDetails propDetails = ElementFactory.getPropertyDetails(propertyType);
684 Map<String, PropertyReqDetails> propertyToSend = new HashMap<>();
685 propertyToSend.put(propDetails.getName(), propDetails);
686 Gson gson = new Gson();
687 RestResponse addPropertyResponse = PropertyRestUtils.createProperty(resourceDetails.getUniqueId(), gson.toJson(propertyToSend), defaultUser);
690 assertTrue("add property to resource failed: " + addPropertyResponse.getResponseMessage(), addPropertyResponse.getErrorCode() == BaseRestUtils.STATUS_CODE_CREATED);
693 if (addPropertyResponse.getErrorCode() == BaseRestUtils.STATUS_CODE_CREATED) {
694 ComponentInstanceProperty compInstProp = null;
695 String property = ResponseParser.getJsonObjectValueByKey(addPropertyResponse.getResponse(), propDetails.getName());
696 compInstProp = (ResponseParser.convertPropertyResponseToJavaObject(property));
698 return Either.left(compInstProp);
700 return Either.right(addPropertyResponse);
703 public static Either<GroupDefinition, RestResponse> updateGroupPropertyOnResource(String maxVFModuleInstacesValue, Resource resource, String groupId, User user, Boolean validateState) throws Exception {
705 // Gson gson = new Gson();
706 // Json group property object
707 String propertyObjectJson = "[{\"defaultValue\":null,\"description\":\"The maximum instances of this VF-Module\",\"name\":\"max_vf_module_instances\",\"parentUniqueId\":\"org.openecomp.groups.VfModule.1.0.grouptype.max_vf_module_instances\",\"password\":false,\"required\":false,\"schema\":{\"property\":{}},\"type\":\"integer\",\"uniqueId\":\"org.openecomp.groups.VfModule.1.0.grouptype.max_vf_module_instances.property.3\",\"value\":\"" + maxVFModuleInstacesValue + "\",\"definition\":false,\"getInputValues\":null,\"constraints\":null,\"valueUniqueUid\":null,\"ownerId\":\"org.openecomp.groups.VfModule.1.0.grouptype.max_vf_module_instances\"}]";
708 // GroupProperty property = gson.fromJson(propertyObjectJson, GroupProperty.class);
709 RestResponse updateGroupPropertyResponse = PropertyRestUtils.updateGroupProperty(resource, groupId, propertyObjectJson, user);
712 assertTrue("update group property to resource failed: " + updateGroupPropertyResponse.getResponseMessage(), updateGroupPropertyResponse.getErrorCode() == BaseRestUtils.STATUS_CODE_SUCCESS);
715 if (updateGroupPropertyResponse.getErrorCode() == BaseRestUtils.STATUS_CODE_SUCCESS) {
716 GroupDefinition responseGroupDefinition = ResponseParser.convertPropertyResponseToObject(updateGroupPropertyResponse.getResponse());
717 return Either.left(responseGroupDefinition);
719 return Either.right(updateGroupPropertyResponse);
723 public static RestResponse createDefaultConsumer(Boolean validateState) {
725 ConsumerDataDefinition defaultConsumerDefinition = ElementFactory.getDefaultConsumerDetails();
726 RestResponse createResponse = ConsumerRestUtils.createConsumer(defaultConsumerDefinition, ElementFactory.getDefaultUser(UserRoleEnum.ADMIN));
727 BaseRestUtils.checkCreateResponse(createResponse);
730 assertTrue(createResponse.getErrorCode() == ResourceRestUtils.STATUS_CODE_CREATED);
732 return createResponse;
733 } catch (Exception e) {
734 throw new AtomicOperationException(e);
739 * Builds Resource From rest response
741 * @param resourceResp
744 public static Either<Resource, RestResponse> buildResourceFromResponse(RestResponse resourceResp) {
745 Either<Resource, RestResponse> result;
746 if (resourceResp.getErrorCode() == ResourceRestUtils.STATUS_CODE_CREATED) {
747 Resource resourceResponseObject = ResponseParser.convertResourceResponseToJavaObject(resourceResp.getResponse());
748 result = Either.left(resourceResponseObject);
750 result = Either.right(resourceResp);
755 private static class AtomicOperationException extends RuntimeException {
756 private AtomicOperationException(Exception e) {
760 private static final long serialVersionUID = 1L;
764 * Import resource from CSAR
766 * @param resourceType
773 public static Resource importResourceFromCsar(ResourceTypeEnum resourceType, UserRoleEnum userRole, String fileName, String... filePath) throws Exception {
774 // Get the CSARs path
775 String realFilePath = System.getProperty("user.dir") + File.separator + "src" + File.separator + "test" + File.separator + "resources" + File.separator + "CI" + File.separator + "csars" ;
776 if (filePath != null && filePath.length > 0) {
777 StringBuffer result = new StringBuffer();
778 for(String currStr: filePath){
779 result.append(currStr);
781 // realFilePath = Arrays.toString(filePath);
782 realFilePath = result.toString();
785 // Create default import resource & user
786 return importResourceFromCsarFile(resourceType, userRole, fileName, realFilePath);
789 public static Resource importResourceFromCsarFile(ResourceTypeEnum resourceType, UserRoleEnum userRole, String csarFileName, String csarFilePath) throws Exception{
790 RestResponse createResource = getCreateResourceRestResponse(resourceType, userRole, csarFileName, csarFilePath);
791 BaseRestUtils.checkCreateResponse(createResource);
792 return ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
795 public static Resource importCertifiedResourceFromCsar(ResourceTypeEnum resourceType, UserRoleEnum userRole, String csarFileName, String csarFilePath) throws Exception{
796 RestResponse createResource = getCreateCertifiedResourceRestResponse(resourceType, userRole, csarFileName, csarFilePath);
797 BaseRestUtils.checkSuccess(createResource);
798 return ResponseParser.parseToObjectUsingMapper(createResource.getResponse(), Resource.class);
800 public static RestResponse getCreateResourceRestResponse(ResourceTypeEnum resourceType, UserRoleEnum userRole,
801 String csarFileName, String csarFilePath) throws IOException, Exception {
803 ImportReqDetails resourceDetails = buildImportReqDetails(resourceType, csarFileName, csarFilePath);
804 User sdncModifierDetails = ElementFactory.getDefaultUser(userRole);
805 RestResponse createResource = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
806 return createResource;
809 public static RestResponse getCreateCertifiedResourceRestResponse(ResourceTypeEnum resourceType, UserRoleEnum userRole,
810 String csarFileName, String csarFilePath) throws IOException, Exception {
812 ImportReqDetails resourceDetails = buildImportReqDetails(resourceType, csarFileName, csarFilePath);
813 User sdncModifierDetails = ElementFactory.getDefaultUser(userRole);
814 RestResponse response = ResourceRestUtils.createResource(resourceDetails, sdncModifierDetails);
815 BaseRestUtils.checkCreateResponse(response);
816 return LCSbaseTest.certifyResource(resourceDetails, sdncModifierDetails);
819 private static ImportReqDetails buildImportReqDetails(ResourceTypeEnum resourceType, String csarFileName, String csarFilePath) throws IOException {
820 ImportReqDetails resourceDetails = ElementFactory.getDefaultImportResource();
821 Path path = Paths.get(csarFilePath + File.separator + csarFileName);
822 byte[] data = Files.readAllBytes(path);
823 String payloadName = csarFileName;
824 String payloadData = Base64.encodeBase64String(data);
825 resourceDetails.setPayloadData(payloadData);
826 resourceDetails.setCsarUUID(payloadName);
827 resourceDetails.setPayloadName(payloadName);
828 resourceDetails.setResourceType(resourceType.name());
829 return resourceDetails;
832 public static Resource updateResourceFromCsar(Resource resource, UserRoleEnum userRole, String csarFileName, String csarFilePath) throws Exception{
833 User sdncModifierDetails = ElementFactory.getDefaultUser(userRole);
836 Path path = Paths.get(csarFilePath + File.separator + csarFileName);
837 data = Files.readAllBytes(path);
838 String payloadName = csarFileName;
839 String payloadData = Base64.encodeBase64String(data);
840 ImportReqDetails resourceDetails = new ImportReqDetails(resource, payloadName, payloadData);
841 resourceDetails.setPayloadData(payloadData);
842 resourceDetails.setCsarUUID(payloadName);
843 resourceDetails.setPayloadName(payloadName);
845 String userId = sdncModifierDetails.getUserId();
846 Config config = Utils.getConfig();
847 String url = String.format(Urls.UPDATE_RESOURCE, config.getCatalogBeHost(), config.getCatalogBePort(), resource.getUniqueId());
849 Map<String, String> headersMap = ResourceRestUtils.prepareHeadersMap(userId);
851 Gson gson = new Gson();
852 String userBodyJson = gson.toJson(resourceDetails);
853 String calculateMD5 = GeneralUtility.calculateMD5Base64EncodedByString(userBodyJson);
854 headersMap.put(HttpHeaderEnum.Content_MD5.getValue(), calculateMD5);
855 HttpRequest http = new HttpRequest();
856 RestResponse updateResourceResponse = http.httpSendPut(url, userBodyJson, headersMap);
857 BaseRestUtils.checkSuccess(updateResourceResponse);
858 return ResponseParser.parseToObjectUsingMapper(updateResourceResponse.getResponse(), Resource.class);
861 public static Either<Resource, RestResponse> importResourceByFileName(ResourceTypeEnum resourceType, UserRoleEnum userRole, String fileName, Boolean validateState, String... filePath) throws IOException {
863 String realFilePath = System.getProperty("user.dir") + File.separator + "src" + File.separator + "test" + File.separator + "resources" + File.separator + "CI" + File.separator + "csars" ;
864 if (filePath != null && filePath.length > 0) {
865 realFilePath = filePath.toString();
869 User defaultUser = ElementFactory.getDefaultUser(userRole);
870 ResourceReqDetails defaultResource = ElementFactory.getDefaultResource(defaultUser);
871 ImportReqDetails defaultImportResource = ElementFactory.getDefaultImportResource(defaultResource);
872 ImportUtils.getImportResourceDetailsByPathAndName(defaultImportResource, realFilePath, fileName);
873 RestResponse resourceResp = ResourceRestUtils.createResource(defaultImportResource, defaultUser);
876 assertTrue(resourceResp.getErrorCode() == ResourceRestUtils.STATUS_CODE_CREATED);
879 if (resourceResp.getErrorCode() == ResourceRestUtils.STATUS_CODE_CREATED) {
880 Resource resourceResponseObject = ResponseParser.convertResourceResponseToJavaObject(resourceResp.getResponse());
881 return Either.left(resourceResponseObject);
883 return Either.right(resourceResp);
884 } catch (Exception e) {
885 throw new AtomicOperationException(e);
889 public static Either<String, RestResponse> getComponenetArtifactPayload(Component component, String artifactType) throws Exception {
892 Config config = Utils.getConfig();
893 if(component.getComponentType().toString().toUpperCase().equals(ComponentTypeEnum.SERVICE.getValue().toUpperCase())){
894 url = String.format(Urls.UI_DOWNLOAD_SERVICE_ARTIFACT, config.getCatalogBeHost(), config.getCatalogBePort(), component.getUniqueId(), component.getToscaArtifacts().get(artifactType).getUniqueId());
896 url = String.format(Urls.UI_DOWNLOAD_RESOURCE_ARTIFACT, config.getCatalogBeHost(), config.getCatalogBePort(), component.getUniqueId(), component.getToscaArtifacts().get(artifactType).getUniqueId());
898 String userId = component.getLastUpdaterUserId();
899 Map<String, String> headersMap = new HashMap<>();
900 headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), BaseRestUtils.contentTypeHeaderData);
901 headersMap.put(HttpHeaderEnum.CACHE_CONTROL.getValue(), BaseRestUtils.cacheControlHeader);
902 headersMap.put(HttpHeaderEnum.AUTHORIZATION.getValue(), basicAuthentication);
903 headersMap.put(HttpHeaderEnum.X_ECOMP_INSTANCE_ID.getValue(), BaseRestUtils.xEcompInstanceId);
904 if (userId != null) {
905 headersMap.put(HttpHeaderEnum.USER_ID.getValue(), userId);
907 HttpRequest http = new HttpRequest();
908 RestResponse response = http.httpSendGet(url, headersMap);
909 if (response.getErrorCode() != BaseRestUtils.STATUS_CODE_SUCCESS && response.getResponse().getBytes() == null && response.getResponse().getBytes().length == 0) {
910 return Either.right(response);
912 return Either.left(response.getResponse());
916 public static RestResponse getDistributionStatusByDistributionId(String distributionId, Boolean validateState) {
919 User defaultUser = ElementFactory.getDefaultUser(UserRoleEnum.OPS);
920 RestResponse response = DistributionUtils.getDistributionStatus(defaultUser, distributionId);
923 assertTrue(response.getErrorCode() == ResourceRestUtils.STATUS_CODE_SUCCESS);
927 } catch (Exception e) {
928 throw new AtomicOperationException(e);
932 public static Either <RestResponse, Map<String, List<DistributionMonitorObject>>> getSortedDistributionStatusMap(Service service, Boolean validateState) {
935 ServiceDistributionStatus serviceDistributionObject = DistributionUtils.getLatestServiceDistributionObject(service);
936 RestResponse response = getDistributionStatusByDistributionId(serviceDistributionObject.getDistributionID(), true);
938 assertTrue(response.getErrorCode() == ResourceRestUtils.STATUS_CODE_SUCCESS);
940 if(response.getErrorCode() == ResourceRestUtils.STATUS_CODE_SUCCESS){
941 Map<String, List<DistributionMonitorObject>> parsedDistributionStatus = DistributionUtils.getSortedDistributionStatus(response);
942 return Either.right(parsedDistributionStatus);
944 return Either.left(response);
945 } catch (Exception e) {
946 throw new AtomicOperationException(e);
954 * @param pollingCount
955 * @param pollingInterval
956 * Recommended values for service distribution for pollingCount is 4 and for pollingInterval is 15000ms
959 public static Boolean distributeAndValidateService(Service service, int pollingCount, int pollingInterval) throws Exception {
960 int firstPollingInterval = 30000; //this value define first be polling topic time, should change if DC configuration changed
961 Boolean statusFlag = true;
962 AtomicOperationUtils.distributeService(service, true);
963 TimeUnit.MILLISECONDS.sleep(firstPollingInterval);
964 int timeOut = pollingCount * pollingInterval;
965 com.clearspring.analytics.util.Pair<Boolean,Map<String,List<String>>> verifyDistributionStatus = null;
967 while (timeOut > 0) {
968 Map<String,List<DistributionMonitorObject>> sortedDistributionStatusMap = AtomicOperationUtils.getSortedDistributionStatusMap(service, true).right().value();
969 verifyDistributionStatus = DistributionUtils.verifyDistributionStatus(sortedDistributionStatusMap);
970 if(verifyDistributionStatus.left.equals(false)){
971 TimeUnit.MILLISECONDS.sleep(pollingInterval);
972 timeOut-=pollingInterval;
978 if((verifyDistributionStatus.right != null && ! verifyDistributionStatus.right.isEmpty())){
979 for(Entry<String, List<String>> entry : verifyDistributionStatus.right.entrySet()){
980 if(ComponentBaseTest.getExtendTest() != null){
981 ComponentBaseTest.getExtendTest().log(Status.INFO, "Consumer: " + entry.getKey() + " failed on following: "+ entry.getValue());
983 System.out.println("Consumer: [" + entry.getKey() + "] failed on following: "+ entry.getValue());
991 public static Boolean distributeAndValidateService(Service service) throws Exception {
992 return distributeAndValidateService(service, 10, 10000);
996 * @param resource to download csar file via API
997 * @return Tosca definition object from main yaml file
999 public static ToscaDefinition downloadAndGetToscaMainYamlObjectApi(Resource resource, File filesFolder) throws Exception {
1000 File vfCsarFileName = new File(File.separator + "VfCsar_" + ElementFactory.generateUUIDforSufix() + ".csar");
1001 OnboardingUtillViaApis.downloadToscaCsarToDirectory(resource, new File(filesFolder.getPath() + vfCsarFileName));
1002 return ToscaParserUtils.parseToscaMainYamlToJavaObjectByCsarLocation(new File(filesFolder.getPath() + vfCsarFileName));
1006 public static ComponentInstance getServiceComponentInstanceByName(Service service, String name, Boolean validateState){
1007 List<ComponentInstance> compInstances = service.getComponentInstances();
1008 for (ComponentInstance instance: compInstances){
1009 String compName = instance.getName();
1010 if (compName.equals(name))
1013 if (validateState) {
1014 assertEquals("Component instance name " + name + " not found", name, null);