From c5f38f5de2f49d3f2fa7f03808f9f063f1cb2ed9 Mon Sep 17 00:00:00 2001 From: "Hockla, Ali (ah999m)" Date: Wed, 13 Sep 2017 09:24:43 -0500 Subject: Added changes for vDNS Use Case -Renamed remaining MSO classes and packages to SO and modified drl accordingly -Connected SO Interface to SO Simulator -Added vDNS Control Loop junit -Modified SOActorServiceProvider to reflect AAI class changes (POLICY-103) Issue-ID: POLICY-102 Change-Id: Iea5d3f096c4ccfedde68e79d7593d66331127aaf Signed-off-by: Hockla, Ali (ah999m) --- controlloop/common/actors/actor.mso/pom.xml | 50 -- .../actor/mso/MSOActorServiceProvider.java | 715 --------------------- ...licy.controlloop.actorServiceProvider.spi.Actor | 1 - controlloop/common/actors/actor.so/pom.xml | 50 ++ .../actor/so/SOActorServiceProvider.java | 715 +++++++++++++++++++++ ...licy.controlloop.actorServiceProvider.spi.Actor | 1 + controlloop/common/actors/pom.xml | 2 +- controlloop/common/eventmanager/pom.xml | 4 +- .../eventmanager/ControlLoopOperationManager.java | 6 +- controlloop/common/model-impl/mso/pom.xml | 57 -- .../org/onap/policy/mso/SOAsyncRequestStatus.java | 63 -- .../org/onap/policy/mso/SOCloudConfiguration.java | 44 -- .../org/onap/policy/mso/SOInstanceReferences.java | 44 -- .../main/java/org/onap/policy/mso/SOManager.java | 168 ----- .../main/java/org/onap/policy/mso/SOModelInfo.java | 59 -- .../org/onap/policy/mso/SOPolicyException.java | 43 -- .../org/onap/policy/mso/SORelatedInstance.java | 49 -- .../policy/mso/SORelatedInstanceListElement.java | 42 -- .../main/java/org/onap/policy/mso/SORequest.java | 60 -- .../java/org/onap/policy/mso/SORequestDetails.java | 124 ---- .../java/org/onap/policy/mso/SORequestError.java | 59 -- .../java/org/onap/policy/mso/SORequestInfo.java | 66 -- .../org/onap/policy/mso/SORequestParameters.java | 47 -- .../org/onap/policy/mso/SORequestReferences.java | 38 -- .../java/org/onap/policy/mso/SORequestStatus.java | 51 -- .../main/java/org/onap/policy/mso/SOResponse.java | 49 -- .../org/onap/policy/mso/SOServiceException.java | 48 -- .../java/org/onap/policy/mso/SOSubscriberInfo.java | 47 -- .../org/onap/policy/mso/util/Serialization.java | 32 - .../test/java/org/onap/policy/mso/TestDemo.java | 167 ----- controlloop/common/model-impl/pom.xml | 2 +- controlloop/common/model-impl/so/pom.xml | 57 ++ .../org/onap/policy/so/SOAsyncRequestStatus.java | 63 ++ .../org/onap/policy/so/SOCloudConfiguration.java | 44 ++ .../org/onap/policy/so/SOInstanceReferences.java | 44 ++ .../main/java/org/onap/policy/so/SOManager.java | 168 +++++ .../main/java/org/onap/policy/so/SOModelInfo.java | 59 ++ .../java/org/onap/policy/so/SOPolicyException.java | 43 ++ .../java/org/onap/policy/so/SORelatedInstance.java | 49 ++ .../policy/so/SORelatedInstanceListElement.java | 42 ++ .../main/java/org/onap/policy/so/SORequest.java | 61 ++ .../java/org/onap/policy/so/SORequestDetails.java | 124 ++++ .../java/org/onap/policy/so/SORequestError.java | 59 ++ .../java/org/onap/policy/so/SORequestInfo.java | 66 ++ .../org/onap/policy/so/SORequestParameters.java | 47 ++ .../org/onap/policy/so/SORequestReferences.java | 38 ++ .../java/org/onap/policy/so/SORequestStatus.java | 51 ++ .../main/java/org/onap/policy/so/SOResponse.java | 49 ++ .../org/onap/policy/so/SOServiceException.java | 48 ++ .../java/org/onap/policy/so/SOSubscriberInfo.java | 47 ++ .../org/onap/policy/so/util/Serialization.java | 32 + .../src/test/java/org/onap/policy/so/TestDemo.java | 167 +++++ controlloop/common/simulators/pom.xml | 9 +- .../onap/policy/simulators/MsoSimulatorJaxRs.java | 37 -- .../onap/policy/simulators/SoSimulatorJaxRs.java | 44 ++ .../main/java/org/onap/policy/simulators/Util.java | 6 +- .../onap/policy/simulators/MsoSimulatorTest.java | 59 -- .../onap/policy/simulators/SoSimulatorTest.java | 133 ++++ .../policy/template/demo/TestFirewallDemo.java | 2 +- controlloop/templates/template.demo/pom.xml | 4 +- .../resources/ControlLoop_Template_xacml_guard.drl | 33 +- .../java/org/onap/policy/template/demo/TestSO.java | 7 +- .../java/org/onap/policy/template/demo/Util.java | 16 +- .../policy/template/demo/VDNSControlLoopTest.java | 304 +++++++++ 64 files changed, 2650 insertions(+), 2265 deletions(-) delete mode 100644 controlloop/common/actors/actor.mso/pom.xml delete mode 100644 controlloop/common/actors/actor.mso/src/main/java/org/onap/policy/controlloop/actor/mso/MSOActorServiceProvider.java delete mode 100644 controlloop/common/actors/actor.mso/src/main/resources/META-INF/services/org.onap.policy.controlloop.actorServiceProvider.spi.Actor create mode 100644 controlloop/common/actors/actor.so/pom.xml create mode 100644 controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java create mode 100644 controlloop/common/actors/actor.so/src/main/resources/META-INF/services/org.onap.policy.controlloop.actorServiceProvider.spi.Actor delete mode 100644 controlloop/common/model-impl/mso/pom.xml delete mode 100644 controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOAsyncRequestStatus.java delete mode 100644 controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOCloudConfiguration.java delete mode 100644 controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOInstanceReferences.java delete mode 100644 controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOManager.java delete mode 100644 controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOModelInfo.java delete mode 100644 controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOPolicyException.java delete mode 100644 controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORelatedInstance.java delete mode 100644 controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORelatedInstanceListElement.java delete mode 100644 controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORequest.java delete mode 100644 controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORequestDetails.java delete mode 100644 controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORequestError.java delete mode 100644 controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORequestInfo.java delete mode 100644 controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORequestParameters.java delete mode 100644 controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORequestReferences.java delete mode 100644 controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORequestStatus.java delete mode 100644 controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOResponse.java delete mode 100644 controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOServiceException.java delete mode 100644 controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOSubscriberInfo.java delete mode 100644 controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/util/Serialization.java delete mode 100644 controlloop/common/model-impl/mso/src/test/java/org/onap/policy/mso/TestDemo.java create mode 100644 controlloop/common/model-impl/so/pom.xml create mode 100644 controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOAsyncRequestStatus.java create mode 100644 controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOCloudConfiguration.java create mode 100644 controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOInstanceReferences.java create mode 100644 controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOManager.java create mode 100644 controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOModelInfo.java create mode 100644 controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOPolicyException.java create mode 100644 controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORelatedInstance.java create mode 100644 controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORelatedInstanceListElement.java create mode 100644 controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequest.java create mode 100644 controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestDetails.java create mode 100644 controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestError.java create mode 100644 controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestInfo.java create mode 100644 controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestParameters.java create mode 100644 controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestReferences.java create mode 100644 controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestStatus.java create mode 100644 controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOResponse.java create mode 100644 controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOServiceException.java create mode 100644 controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOSubscriberInfo.java create mode 100644 controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/util/Serialization.java create mode 100644 controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestDemo.java delete mode 100644 controlloop/common/simulators/src/main/java/org/onap/policy/simulators/MsoSimulatorJaxRs.java create mode 100644 controlloop/common/simulators/src/main/java/org/onap/policy/simulators/SoSimulatorJaxRs.java delete mode 100644 controlloop/common/simulators/src/test/java/org/onap/policy/simulators/MsoSimulatorTest.java create mode 100644 controlloop/common/simulators/src/test/java/org/onap/policy/simulators/SoSimulatorTest.java create mode 100644 controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VDNSControlLoopTest.java (limited to 'controlloop') diff --git a/controlloop/common/actors/actor.mso/pom.xml b/controlloop/common/actors/actor.mso/pom.xml deleted file mode 100644 index 5b0f908fe..000000000 --- a/controlloop/common/actors/actor.mso/pom.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - 4.0.0 - - org.onap.policy.drools-applications - actors - 1.1.0-SNAPSHOT - - actor.mso - - - org.onap.policy.drools-applications - actorServiceProvider - 1.1.0-SNAPSHOT - provided - - - org.onap.policy.drools-applications - aai - 1.1.0-SNAPSHOT - provided - - - org.onap.policy.drools-applications - events - 1.1.0-SNAPSHOT - provided - - - org.onap.policy.drools-applications - mso - 1.1.0-SNAPSHOT - provided - - - org.drools - drools-core - 6.5.0.Final - provided - - - com.google.code.gson - gson - 2.5 - provided - - - diff --git a/controlloop/common/actors/actor.mso/src/main/java/org/onap/policy/controlloop/actor/mso/MSOActorServiceProvider.java b/controlloop/common/actors/actor.mso/src/main/java/org/onap/policy/controlloop/actor/mso/MSOActorServiceProvider.java deleted file mode 100644 index 64e0c616b..000000000 --- a/controlloop/common/actors/actor.mso/src/main/java/org/onap/policy/controlloop/actor/mso/MSOActorServiceProvider.java +++ /dev/null @@ -1,715 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * MSOActorServiceProvider - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= - */ - -package org.onap.policy.controlloop.actor.mso; - -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.drools.core.WorkingMemory; -import org.onap.policy.aai.AAINQF199.AAINQF199InstanceFilters; -import org.onap.policy.aai.AAINQF199.AAINQF199InventoryResponseItem; -import org.onap.policy.aai.AAINQF199.AAINQF199Manager; -import org.onap.policy.aai.AAINQF199.AAINQF199NamedQuery; -import org.onap.policy.aai.AAINQF199.AAINQF199QueryParameters; -import org.onap.policy.aai.AAINQF199.AAINQF199Request; -import org.onap.policy.aai.AAINQF199.AAINQF199RequestWrapper; -import org.onap.policy.aai.AAINQF199.AAINQF199Response; -import org.onap.policy.aai.AAINQF199.AAINQF199ResponseWrapper; -import org.onap.policy.controlloop.ControlLoopNotificationType; -import org.onap.policy.controlloop.ControlLoopOperation; -import org.onap.policy.controlloop.VirtualControlLoopEvent; -import org.onap.policy.controlloop.VirtualControlLoopNotification; -import org.onap.policy.controlloop.actorServiceProvider.spi.Actor; -import org.onap.policy.controlloop.policy.Policy; -import org.onap.policy.mso.SOCloudConfiguration; -import org.onap.policy.mso.SOManager; -import org.onap.policy.mso.SOModelInfo; -import org.onap.policy.mso.SORelatedInstance; -import org.onap.policy.mso.SORelatedInstanceListElement; -import org.onap.policy.mso.SORequest; -import org.onap.policy.mso.SORequestDetails; -import org.onap.policy.mso.SORequestInfo; -import org.onap.policy.mso.SORequestParameters; -import org.onap.policy.mso.util.Serialization; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - -public class MSOActorServiceProvider implements Actor { - - private static final Logger logger = LoggerFactory.getLogger(MSOActorServiceProvider.class); - - private static String vnfItemVnfId; - - private String vnfItemVnfType; - - private String vnfItemModelInvariantId; - - private String vnfItemModelVersionId; - - private String vnfItemModelName; - - private String vnfItemModelVersion; - - private String vnfItemModelNameVersionId; - - private static String serviceItemServiceInstanceId; - - private String serviceItemPersonaModelId; - - private String serviceItemModelName; - - private String serviceItemModelType; - - private String serviceItemModelVersion; - - private String serviceItemModelNameVersionId; - - private String vfModuleItemVfModuleName; - - private String vfModuleItemPersonaModelId; - - private String vfModuleItemPersonaModelVersion; - - private String vfModuleItemModelName; - - private String vfModuleItemModelNameVersionId; - - private String tenantItemTenantId; - - private String cloudRegionItemCloudRegionId; - - private static final ImmutableList recipes = ImmutableList.of( - "VF Module Create"); - private static final ImmutableMap> targets = new ImmutableMap.Builder>() - .put("VF Module Create", ImmutableList.of("VFC")) - .build(); - - @Override - public String actor() { - return "SO"; - } - - @Override - public List recipes() { - return ImmutableList.copyOf(recipes); - } - - @Override - public List recipeTargets(String recipe) { - return ImmutableList.copyOf(targets.getOrDefault(recipe, Collections.emptyList())); - } - - @Override - public List recipePayloads(String recipe) { - return Collections.emptyList(); - } - - /** - * MSOActorServiceProvider Constructor - * - */ - public MSOActorServiceProvider() { - - } - - /** - * Constructs and sends an AAI vserver Named Query - * - * @param eventRequestID - * @returns the response to the AAI Named Query - */ - private AAINQF199ResponseWrapper AaiNamedQueryRequest(VirtualControlLoopEvent onset) { - - // create AAI named-query request with UUID started with "F199" - AAINQF199Request aainqf199request = new AAINQF199Request(); - AAINQF199QueryParameters aainqf199queryparam = new AAINQF199QueryParameters(); - AAINQF199NamedQuery aainqf199namedquery = new AAINQF199NamedQuery(); - AAINQF199InstanceFilters aainqf199instancefilter = new AAINQF199InstanceFilters(); - - // queryParameters - aainqf199namedquery.namedQueryUUID = UUID.fromString("4ff56a54-9e3f-46b7-a337-07a1d3c6b469"); // UUID.fromString($params.getAaiNamedQueryUUID()) TO DO: AaiNamedQueryUUID - aainqf199queryparam.namedQuery = aainqf199namedquery; - aainqf199request.queryParameters = aainqf199queryparam; - // - // instanceFilters - // - Map> aainqf199instancefiltermap = new HashMap<>(); - Map aainqf199instancefiltermapitem = new HashMap<>(); - aainqf199instancefiltermapitem.put("vserver-name", onset.AAI.get("vserver.vserver-name")); // TO DO: get vserver.vname from dcae onset.AAI.get("vserver.vserver-name") - aainqf199instancefiltermap.put("vserver", aainqf199instancefiltermapitem); - aainqf199instancefilter.instanceFilter.add(aainqf199instancefiltermap); - aainqf199request.instanceFilters = aainqf199instancefilter; - // - // print aainqf199request for debug - // - logger.debug("AAI Request sent:"); - logger.debug(Serialization.gsonPretty.toJson(aainqf199request)); - // - // Create AAINQF199RequestWrapper - // - AAINQF199RequestWrapper aainqf199RequestWrapper = new AAINQF199RequestWrapper(onset.requestID, aainqf199request); - // - // insert aainqf199request into memory - // -// insert(aainqf199RequestWrapper); - - String url = "http://localhost:6666"; - String username = "testUser"; - String password = "testPass"; - - //***** send the request *****\\ - AAINQF199Response aainqf199response = AAINQF199Manager.postQuery(url, username, password, // TO DO: get AAI URL, username, and password - aainqf199RequestWrapper.aainqf199request, onset.requestID); - - // Check AAI response - if (aainqf199response == null) { - System.err.println("Failed to get AAI response"); - - // Fail and retract everything - return null; - } else { - // Create AAINQF199ResponseWrapper - AAINQF199ResponseWrapper aainqf199ResponseWrapper = new AAINQF199ResponseWrapper(onset.requestID, aainqf199response); - - // insert aainqf199ResponseWrapper to memory -- Is this needed? -// insert(aainqf199ResponseWrapper); - - // - extractSOFieldsFromNamedQuery(aainqf199ResponseWrapper, onset); - return aainqf199ResponseWrapper; - } - } - - /** - * Extract the required fields from the named query response - * @param namedQueryResponseWrapper - * @param onset - */ - private void extractSOFieldsFromNamedQuery(AAINQF199ResponseWrapper namedQueryResponseWrapper, VirtualControlLoopEvent onset) { - - try { - // vnfItem - setVnfItemVnfId(namedQueryResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.vnfID); - setVnfItemVnfType(namedQueryResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.vnfType); - setVnfItemVnfType(vnfItemVnfType.substring(vnfItemVnfType.lastIndexOf("/")+1)); - setVnfItemModelInvariantId(namedQueryResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.personaModelId); - setVnfItemModelVersionId(namedQueryResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.personaModelVersion); - setVnfItemModelName(namedQueryResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(0).propertyValue); - setVnfItemModelVersion(namedQueryResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(2).propertyValue); - setVnfItemModelNameVersionId(namedQueryResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(4).propertyValue); - - // serviceItem - setServiceItemServiceInstanceId(namedQueryResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).serviceInstance.serviceInstanceID); - setServiceItemPersonaModelId(namedQueryResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).serviceInstance.personaModelId); - setServiceItemModelName(namedQueryResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(0).propertyValue); - setServiceItemModelType(namedQueryResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(1).propertyValue); - setServiceItemModelVersion(namedQueryResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).serviceInstance.personaModelVersion); - setServiceItemModelNameVersionId(namedQueryResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(4).propertyValue); - - // Find the index for base vf module and non-base vf module - int baseIndex = -1; - int nonBaseIndex = -1; - List inventoryItems = namedQueryResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems; - for (AAINQF199InventoryResponseItem m : inventoryItems) { - if (m.vfModule != null && m.vfModule.isBaseVfModule == true) { - baseIndex = inventoryItems.indexOf(m); - } else if (m.vfModule != null && m.vfModule.isBaseVfModule == false && m.vfModule.orchestrationStatus == null) { - nonBaseIndex = inventoryItems.indexOf(m); - } - // - if (baseIndex != -1 && nonBaseIndex != -1) { - break; - } - } - - // Report the error if either base vf module or non-base vf module is not found - if (baseIndex == -1 || nonBaseIndex == -1) { - logger.error("Either base or non-base vf module is not found from AAI response."); - return; - } - - // This comes from the base module - setVfModuleItemVfModuleName(namedQueryResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(baseIndex).vfModule.vfModuleName); - setVfModuleItemVfModuleName(vfModuleItemVfModuleName.replace("Vfmodule", "vDNS")); - - // vfModuleItem - NOT the base module - setVfModuleItemPersonaModelId(namedQueryResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(nonBaseIndex).vfModule.personaModelId); - setVfModuleItemPersonaModelVersion(namedQueryResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(nonBaseIndex).vfModule.personaModelVersion); - setVfModuleItemModelName(namedQueryResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(nonBaseIndex).extraProperties.extraProperty.get(0).propertyValue); - setVfModuleItemModelNameVersionId(namedQueryResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(nonBaseIndex).extraProperties.extraProperty.get(4).propertyValue); - - // tenantItem - setTenantItemTenantId(namedQueryResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(1).tenant.tenantId); - - // cloudRegionItem - setCloudRegionItemCloudRegionId(namedQueryResponseWrapper.aainqf199response.inventoryResponseItems.get(0).items.inventoryResponseItems.get(1).items.inventoryResponseItems.get(0).cloudRegion.cloudRegionId); - - } catch (Exception e) { - logger.error(e.getMessage(), e); - VirtualControlLoopNotification notification = new VirtualControlLoopNotification(onset); - notification.notification = ControlLoopNotificationType.REJECTED; - notification.message = "Exception occurred " + e.getMessage(); - notification.policyName = onset.policyName; - notification.policyScope = onset.policyScope; - notification.policyVersion = onset.policyVersion; - // - try { - logger.debug(Serialization.gsonPretty.toJson(notification)); - } catch (Exception e1) { - logger.error("Can't deliver notification: " + notification); - logger.error(e1.getMessage(), e1); - } - // - notification.notification = ControlLoopNotificationType.FINAL_FAILURE; - notification.message = "Invalid named-query response from AAI"; - // - try { - logger.debug(Serialization.gsonPretty.toJson(notification)); - } catch (Exception e1) { - logger.error("Can't deliver notification: " + notification); - logger.error(e1.getMessage(), e1); - } - // Retract everything - return; - } - - // Extracted fields should not be null - if (checkExtractedFields() == false) { - System.err.println("some fields are missing from AAI response."); - return; - } - } - - /** - * Checks whether extracted fields from AAI Named Query are null or not - * @return false if some extracted fields are missing, true otherwise - */ - private boolean checkExtractedFields() { - - if ((getVnfItemVnfId() == null) || (getVnfItemVnfType() == null) || - (getVnfItemModelInvariantId() == null) || (getVnfItemModelName() == null) || - (getVnfItemModelVersion() == null) || (getVnfItemModelNameVersionId() == null) || - (getServiceItemServiceInstanceId() == null) || (getServiceItemModelName() == null) || - (getServiceItemModelType() == null) || (getServiceItemModelVersion() == null) || - (getServiceItemModelNameVersionId() == null) || (getVfModuleItemVfModuleName() == null) || - (getVfModuleItemPersonaModelId() == null) || (getVfModuleItemPersonaModelVersion() == null) || - (getVfModuleItemModelName() == null) || (getVfModuleItemModelNameVersionId() == null) || - (getTenantItemTenantId() == null) || (getCloudRegionItemCloudRegionId() == null)) { - return false; - } - return true; - } - - /** - * Construct SO Request - * - * @param onset - * @param operation - * @param policy - * @return MSORequest - */ - public SORequest constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation, Policy policy) { - - if (policy.getActor().equals("SO") && policy.getRecipe().equals("VF Module Create")) { - // perform named query request and handle response - AaiNamedQueryRequest(onset); - } else { - // for future extension - return null; - }; - - // check if the fields extracted from named query response are - // not null so we can proceed with SO request - if (checkExtractedFields() == false) { - - System.err.println("AAI response is missing some required fields. Cannot proceed with SO Request construction."); - return null; - - } else { - - // Construct SO Request - SORequest request = new SORequest(); - request.requestDetails = new SORequestDetails(); - request.requestDetails.modelInfo = new SOModelInfo(); - request.requestDetails.cloudConfiguration = new SOCloudConfiguration(); - request.requestDetails.requestInfo = new SORequestInfo(); - request.requestDetails.requestParameters = new SORequestParameters(); - request.requestDetails.requestParameters.userParams = null; - // - // cloudConfiguration - // - request.requestDetails.cloudConfiguration.lcpCloudRegionId = getCloudRegionItemCloudRegionId(); - request.requestDetails.cloudConfiguration.tenantId = getTenantItemTenantId(); - // - // modelInfo - // - request.requestDetails.modelInfo.modelType = "vfModule"; - request.requestDetails.modelInfo.modelInvariantId = getVfModuleItemPersonaModelId(); - request.requestDetails.modelInfo.modelNameVersionId = getVfModuleItemModelNameVersionId(); - request.requestDetails.modelInfo.modelName = getVfModuleItemModelName(); - request.requestDetails.modelInfo.modelVersion = getVfModuleItemPersonaModelVersion(); - // - // requestInfo - // - request.requestDetails.requestInfo.instanceName = getVfModuleItemVfModuleName(); - request.requestDetails.requestInfo.source = "POLICY"; - request.requestDetails.requestInfo.suppressRollback = false; - // - // relatedInstanceList - // - SORelatedInstanceListElement relatedInstanceListElement1 = new SORelatedInstanceListElement(); - SORelatedInstanceListElement relatedInstanceListElement2 = new SORelatedInstanceListElement(); - relatedInstanceListElement1.relatedInstance = new SORelatedInstance(); - relatedInstanceListElement2.relatedInstance = new SORelatedInstance(); - // - relatedInstanceListElement1.relatedInstance.instanceId = getServiceItemServiceInstanceId(); - relatedInstanceListElement1.relatedInstance.modelInfo = new SOModelInfo(); - relatedInstanceListElement1.relatedInstance.modelInfo.modelType = "service"; - relatedInstanceListElement1.relatedInstance.modelInfo.modelInvariantId = getServiceItemPersonaModelId(); - relatedInstanceListElement1.relatedInstance.modelInfo.modelNameVersionId = getServiceItemModelNameVersionId(); - relatedInstanceListElement1.relatedInstance.modelInfo.modelName = getServiceItemModelName(); - relatedInstanceListElement1.relatedInstance.modelInfo.modelVersion = getServiceItemModelVersion(); - // - relatedInstanceListElement2.relatedInstance.instanceId = getVnfItemVnfId(); - relatedInstanceListElement2.relatedInstance.modelInfo = new SOModelInfo(); - relatedInstanceListElement2.relatedInstance.modelInfo.modelType = "vnf"; - relatedInstanceListElement2.relatedInstance.modelInfo.modelInvariantId = getVnfItemModelInvariantId(); - relatedInstanceListElement2.relatedInstance.modelInfo.modelNameVersionId = getVnfItemModelNameVersionId(); - relatedInstanceListElement2.relatedInstance.modelInfo.modelName = getVnfItemModelName(); - relatedInstanceListElement2.relatedInstance.modelInfo.modelVersion = getVnfItemModelVersion(); - relatedInstanceListElement2.relatedInstance.modelInfo.modelCustomizationName = getVnfItemVnfType(); - // - request.requestDetails.relatedInstanceList.add(relatedInstanceListElement1); - request.requestDetails.relatedInstanceList.add(relatedInstanceListElement2); - // - // print MSO request for debug - // - logger.debug("MSO request sent:"); - logger.debug(Serialization.gsonPretty.toJson(request)); - - return request; - } - } - - /** - * This method is needed to get the serviceInstanceId and vnfInstanceId which is used - * in the asyncMSORestCall - * - * @param wm - * @param request - */ - public static void sendRequest(WorkingMemory wm, Object request) { - SOManager Mm = new SOManager(); - Mm.asyncMSORestCall(wm, getServiceItemServiceInstanceId(), getVnfItemVnfId(), (SORequest)request); - } - - /** - * @return the vnfItemVnfId - */ - public static String getVnfItemVnfId() { - return vnfItemVnfId; - } - - /** - * @param vnfItemVnfId the vnfItemVnfId to set - */ - private void setVnfItemVnfId(String vnfItemVnfId) { - MSOActorServiceProvider.vnfItemVnfId = vnfItemVnfId; - } - - /** - * @return the vnfItemVnfType - */ - public String getVnfItemVnfType() { - return this.vnfItemVnfType; - } - - /** - * @param vnfItemVnfType the vnfItemVnfType to set - */ - private void setVnfItemVnfType(String vnfItemVnfType) { - this.vnfItemVnfType = vnfItemVnfType; - } - - /** - * @return the vnfItemPersonaModelId - */ - public String getVnfItemModelInvariantId() { - return this.vnfItemModelInvariantId; - } - - /** - * @param vnfItemPersonaModelId the vnfItemPersonaModelId to set - */ - private void setVnfItemModelInvariantId(String vnfItemModelInvariantId) { - this.vnfItemModelInvariantId = vnfItemModelInvariantId; - } - - /** - * @return the vnfItemModelVersionId - */ - public String getVnfItemModelVersionId() { - return this.vnfItemModelVersionId; - } - - /** - * @param vnfItemModelVersionId the vnfItemModelVersionId to set - */ - private void setVnfItemModelVersionId(String vnfItemModelVersionId) { - this.vnfItemModelVersionId = vnfItemModelVersionId; - } - - /** - * @return the vnfItemModelName - */ - public String getVnfItemModelName() { - return this.vnfItemModelName; - } - - /** - * @param vnfItemModelName the vnfItemModelName to set - */ - private void setVnfItemModelName(String vnfItemModelName) { - this.vnfItemModelName = vnfItemModelName; - } - - /** - * @return the vnfItemModelVersion - */ - public String getVnfItemModelVersion() { - return this.vnfItemModelVersion; - } - - /** - * @param vnfItemModelVersion the vnfItemModelVersion to set - */ - private void setVnfItemModelVersion(String vnfItemModelVersion) { - this.vnfItemModelVersion = vnfItemModelVersion; - } - - /** - * @return the vnfItemModelNameVersionId - */ - public String getVnfItemModelNameVersionId() { - return this.vnfItemModelNameVersionId; - } - - /** - * @param vnfItemModelNameVersionId the vnfItemModelNameVersionId to set - */ - private void setVnfItemModelNameVersionId(String vnfItemModelNameVersionId) { - this.vnfItemModelNameVersionId = vnfItemModelNameVersionId; - } - - /** - * @return the serviceItemServiceInstanceId - */ - public static String getServiceItemServiceInstanceId() { - return serviceItemServiceInstanceId; - } - - /** - * @param serviceItemServiceInstanceId the serviceItemServiceInstanceId to set - */ - private void setServiceItemServiceInstanceId( - String serviceItemServiceInstanceId) { - MSOActorServiceProvider.serviceItemServiceInstanceId = serviceItemServiceInstanceId; - } - - /** - * @return the serviceItemPersonaModelId - */ - public String getServiceItemPersonaModelId() { - return this.serviceItemPersonaModelId; - } - - /** - * @param serviceItemPersonaModelId the serviceItemPersonaModelId to set - */ - private void setServiceItemPersonaModelId(String serviceItemPersonaModelId) { - this.serviceItemPersonaModelId = serviceItemPersonaModelId; - } - - /** - * @return the serviceItemModelName - */ - public String getServiceItemModelName() { - return this.serviceItemModelName; - } - - /** - * @param serviceItemModelName the serviceItemModelName to set - */ - private void setServiceItemModelName(String serviceItemModelName) { - this.serviceItemModelName = serviceItemModelName; - } - - /** - * @return the serviceItemModelType - */ - public String getServiceItemModelType() { - return this.serviceItemModelType; - } - - /** - * @param serviceItemModelType the serviceItemModelType to set - */ - private void setServiceItemModelType(String serviceItemModelType) { - this.serviceItemModelType = serviceItemModelType; - } - - /** - * @return the serviceItemModelVersion - */ - public String getServiceItemModelVersion() { - return this.serviceItemModelVersion; - } - - /** - * @param serviceItemModelVersion the serviceItemModelVersion to set - */ - private void setServiceItemModelVersion(String serviceItemModelVersion) { - this.serviceItemModelVersion = serviceItemModelVersion; - } - - /** - * @return the serviceItemModelNameVersionId - */ - public String getServiceItemModelNameVersionId() { - return this.serviceItemModelNameVersionId; - } - - /** - * @param serviceItemModelNameVersionId the serviceItemModelNameVersionId to set - */ - private void setServiceItemModelNameVersionId( - String serviceItemModelNameVersionId) { - this.serviceItemModelNameVersionId = serviceItemModelNameVersionId; - } - - /** - * @return the vfModuleItemVfModuleName - */ - public String getVfModuleItemVfModuleName() { - return this.vfModuleItemVfModuleName; - } - - /** - * @param vfModuleItemVfModuleName the vfModuleItemVfModuleName to set - */ - private void setVfModuleItemVfModuleName(String vfModuleItemVfModuleName) { - this.vfModuleItemVfModuleName = vfModuleItemVfModuleName; - } - - /** - * @return the vfModuleItemPersonaModelId - */ - public String getVfModuleItemPersonaModelId() { - return this.vfModuleItemPersonaModelId; - } - - /** - * @param vfModuleItemPersonaModelId the vfModuleItemPersonaModelId to set - */ - private void setVfModuleItemPersonaModelId(String vfModuleItemPersonaModelId) { - this.vfModuleItemPersonaModelId = vfModuleItemPersonaModelId; - } - - /** - * @return the vfModuleItemPersonaModelVersion - */ - public String getVfModuleItemPersonaModelVersion() { - return this.vfModuleItemPersonaModelVersion; - } - - /** - * @param vfModuleItemPersonaModelVersion the vfModuleItemPersonaModelVersion to set - */ - private void setVfModuleItemPersonaModelVersion( - String vfModuleItemPersonaModelVersion) { - this.vfModuleItemPersonaModelVersion = vfModuleItemPersonaModelVersion; - } - - /** - * @return the vfModuleItemModelName - */ - public String getVfModuleItemModelName() { - return this.vfModuleItemModelName; - } - - /** - * @param vfModuleItemModelName the vfModuleItemModelName to set - */ - private void setVfModuleItemModelName(String vfModuleItemModelName) { - this.vfModuleItemModelName = vfModuleItemModelName; - } - - /** - * @return the vfModuleItemModelNameVersionId - */ - public String getVfModuleItemModelNameVersionId() { - return this.vfModuleItemModelNameVersionId; - } - - /** - * @param vfModuleItemModelNameVersionId the vfModuleItemModelNameVersionId to set - */ - private void setVfModuleItemModelNameVersionId( - String vfModuleItemModelNameVersionId) { - this.vfModuleItemModelNameVersionId = vfModuleItemModelNameVersionId; - } - - /** - * @return the tenantItemTenantId - */ - public String getTenantItemTenantId() { - return this.tenantItemTenantId; - } - - /** - * @param tenantItemTenantId the tenantItemTenantId to set - */ - private void setTenantItemTenantId(String tenantItemTenantId) { - this.tenantItemTenantId = tenantItemTenantId; - } - - /** - * @return the cloudRegionItemCloudRegionId - */ - public String getCloudRegionItemCloudRegionId() { - return this.cloudRegionItemCloudRegionId; - } - - /** - * @param cloudRegionItemCloudRegionId the cloudRegionItemCloudRegionId to set - */ - private void setCloudRegionItemCloudRegionId( - String cloudRegionItemCloudRegionId) { - this.cloudRegionItemCloudRegionId = cloudRegionItemCloudRegionId; - } - -} diff --git a/controlloop/common/actors/actor.mso/src/main/resources/META-INF/services/org.onap.policy.controlloop.actorServiceProvider.spi.Actor b/controlloop/common/actors/actor.mso/src/main/resources/META-INF/services/org.onap.policy.controlloop.actorServiceProvider.spi.Actor deleted file mode 100644 index 90d6c7f0e..000000000 --- a/controlloop/common/actors/actor.mso/src/main/resources/META-INF/services/org.onap.policy.controlloop.actorServiceProvider.spi.Actor +++ /dev/null @@ -1 +0,0 @@ -org.onap.policy.controlloop.actor.mso.MSOActorServiceProvider \ No newline at end of file diff --git a/controlloop/common/actors/actor.so/pom.xml b/controlloop/common/actors/actor.so/pom.xml new file mode 100644 index 000000000..ff5b12167 --- /dev/null +++ b/controlloop/common/actors/actor.so/pom.xml @@ -0,0 +1,50 @@ + + + 4.0.0 + + org.onap.policy.drools-applications + actors + 1.1.0-SNAPSHOT + + actor.so + + + org.onap.policy.drools-applications + actorServiceProvider + 1.1.0-SNAPSHOT + provided + + + org.onap.policy.drools-applications + aai + 1.1.0-SNAPSHOT + provided + + + org.onap.policy.drools-applications + events + 1.1.0-SNAPSHOT + provided + + + org.onap.policy.drools-applications + so + 1.1.0-SNAPSHOT + provided + + + org.drools + drools-core + 6.5.0.Final + provided + + + com.google.code.gson + gson + 2.5 + provided + + + diff --git a/controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java b/controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java new file mode 100644 index 000000000..905de98a6 --- /dev/null +++ b/controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java @@ -0,0 +1,715 @@ +/*- + * ============LICENSE_START======================================================= + * SOActorServiceProvider + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= + */ + +package org.onap.policy.controlloop.actor.so; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.drools.core.WorkingMemory; +import org.onap.policy.aai.AAINQInstanceFilters; +import org.onap.policy.aai.AAINQInventoryResponseItem; +import org.onap.policy.aai.AAIManager; +import org.onap.policy.aai.AAINQNamedQuery; +import org.onap.policy.aai.AAINQQueryParameters; +import org.onap.policy.aai.AAINQRequest; +import org.onap.policy.aai.AAINQResponse; +import org.onap.policy.aai.AAINQResponseWrapper; +import org.onap.policy.controlloop.ControlLoopNotificationType; +import org.onap.policy.controlloop.ControlLoopOperation; +import org.onap.policy.controlloop.VirtualControlLoopEvent; +import org.onap.policy.controlloop.VirtualControlLoopNotification; +import org.onap.policy.controlloop.actorServiceProvider.spi.Actor; +import org.onap.policy.controlloop.policy.Policy; +import org.onap.policy.so.SOCloudConfiguration; +import org.onap.policy.so.SOManager; +import org.onap.policy.so.SOModelInfo; +import org.onap.policy.so.SORelatedInstance; +import org.onap.policy.so.SORelatedInstanceListElement; +import org.onap.policy.so.SORequest; +import org.onap.policy.so.SORequestDetails; +import org.onap.policy.so.SORequestInfo; +import org.onap.policy.so.SORequestParameters; +import org.onap.policy.so.util.Serialization; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; + +public class SOActorServiceProvider implements Actor { + + private static final Logger logger = LoggerFactory.getLogger(SOActorServiceProvider.class); + + private static String vnfItemVnfId; + + private String vnfItemVnfType; + + private String vnfItemModelInvariantId; + + private String vnfItemModelVersionId; + + private String vnfItemModelName; + + private String vnfItemModelVersion; + + private String vnfItemModelNameVersionId; + + private static String serviceItemServiceInstanceId; + + private String serviceItemPersonaModelId; + + private String serviceItemModelName; + + private String serviceItemModelType; + + private String serviceItemModelVersion; + + private String serviceItemModelNameVersionId; + + private String vfModuleItemVfModuleName; + + private String vfModuleItemPersonaModelId; + + private String vfModuleItemPersonaModelVersion; + + private String vfModuleItemModelName; + + private String vfModuleItemModelNameVersionId; + + private String tenantItemTenantId; + + private String cloudRegionItemCloudRegionId; + + private static final ImmutableList recipes = ImmutableList.of( + "VF Module Create"); + private static final ImmutableMap> targets = new ImmutableMap.Builder>() + .put("VF Module Create", ImmutableList.of("VFC")) + .build(); + + @Override + public String actor() { + return "SO"; + } + + @Override + public List recipes() { + return ImmutableList.copyOf(recipes); + } + + @Override + public List recipeTargets(String recipe) { + return ImmutableList.copyOf(targets.getOrDefault(recipe, Collections.emptyList())); + } + + @Override + public List recipePayloads(String recipe) { + return Collections.emptyList(); + } + + /** + * SOActorServiceProvider Constructor + * + */ + public SOActorServiceProvider() { + + } + + /** + * Constructs and sends an AAI vserver Named Query + * + * @param eventRequestID + * @returns the response to the AAI Named Query + */ + private AAINQResponseWrapper AaiNamedQueryRequest(VirtualControlLoopEvent onset) { + + // create AAI named-query request with UUID started with "" + AAINQRequest aainqrequest = new AAINQRequest(); + AAINQQueryParameters aainqqueryparam = new AAINQQueryParameters(); + AAINQNamedQuery aainqnamedquery = new AAINQNamedQuery(); + AAINQInstanceFilters aainqinstancefilter = new AAINQInstanceFilters(); + + // queryParameters + aainqnamedquery.namedQueryUUID = UUID.fromString("4ff56a54-9e3f-46b7-a337-07a1d3c6b469"); // UUID.fromString($params.getAaiNamedQueryUUID()) TO DO: AaiNamedQueryUUID + aainqqueryparam.namedQuery = aainqnamedquery; + aainqrequest.queryParameters = aainqqueryparam; + // + // instanceFilters + // + Map> aainqinstancefiltermap = new HashMap<>(); + Map aainqinstancefiltermapitem = new HashMap<>(); + aainqinstancefiltermapitem.put("vserver-name", onset.AAI.get("vserver.vserver-name")); // TO DO: get vserver.vname from dcae onset.AAI.get("vserver.vserver-name") + aainqinstancefiltermap.put("vserver", aainqinstancefiltermapitem); + aainqinstancefilter.instanceFilter.add(aainqinstancefiltermap); + aainqrequest.instanceFilters = aainqinstancefilter; + // + // print aainqrequest for debug + // + logger.debug("AAI Request sent:"); + logger.debug(Serialization.gsonPretty.toJson(aainqrequest)); + // + // Create AAINQRequestWrapper + // +// AAINQRequestWrapper aainqRequestWrapper = new AAINQRequestWrapper(onset.requestID, aainqrequest); + // + // insert aainqrequest into memory + // +// insert(aainqRequestWrapper); + + String url = "http://localhost:6666"; + String username = "testUser"; + String password = "testPass"; + + //***** send the request *****\\ + AAINQResponse aainqresponse = AAIManager.postQuery(url, username, password, // TO DO: get AAI URL, username, and password + aainqrequest, onset.requestID); + + // Check AAI response + if (aainqresponse == null) { + System.err.println("Failed to get AAI response"); + + // Fail and retract everything + return null; + } else { + // Create AAINQResponseWrapper + AAINQResponseWrapper aainqResponseWrapper = new AAINQResponseWrapper(onset.requestID, aainqresponse); + + // insert aainqResponseWrapper to memory -- Is this needed? +// insert(aainqResponseWrapper); + + // + extractSOFieldsFromNamedQuery(aainqResponseWrapper, onset); + return aainqResponseWrapper; + } + } + + /** + * Extract the required fields from the named query response + * @param namedQueryResponseWrapper + * @param onset + */ + private void extractSOFieldsFromNamedQuery(AAINQResponseWrapper namedQueryResponseWrapper, VirtualControlLoopEvent onset) { + + try { + // vnfItem + setVnfItemVnfId(namedQueryResponseWrapper.aainqresponse.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.vnfID); + setVnfItemVnfType(namedQueryResponseWrapper.aainqresponse.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.vnfType); + setVnfItemVnfType(vnfItemVnfType.substring(vnfItemVnfType.lastIndexOf("/")+1)); + setVnfItemModelInvariantId(namedQueryResponseWrapper.aainqresponse.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.modelInvariantId); + setVnfItemModelVersionId(namedQueryResponseWrapper.aainqresponse.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).genericVNF.personaModelVersion); + setVnfItemModelName(namedQueryResponseWrapper.aainqresponse.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(0).propertyValue); + setVnfItemModelVersion(namedQueryResponseWrapper.aainqresponse.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(2).propertyValue); + setVnfItemModelNameVersionId(namedQueryResponseWrapper.aainqresponse.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(4).propertyValue); + + // serviceItem + setServiceItemServiceInstanceId(namedQueryResponseWrapper.aainqresponse.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).serviceInstance.serviceInstanceID); + setServiceItemPersonaModelId(namedQueryResponseWrapper.aainqresponse.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).serviceInstance.personaModelId); + setServiceItemModelName(namedQueryResponseWrapper.aainqresponse.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(0).propertyValue); + setServiceItemModelType(namedQueryResponseWrapper.aainqresponse.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(1).propertyValue); + setServiceItemModelVersion(namedQueryResponseWrapper.aainqresponse.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).serviceInstance.personaModelVersion); + setServiceItemModelNameVersionId(namedQueryResponseWrapper.aainqresponse.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).extraProperties.extraProperty.get(4).propertyValue); + + // Find the index for base vf module and non-base vf module + int baseIndex = -1; + int nonBaseIndex = -1; + List inventoryItems = namedQueryResponseWrapper.aainqresponse.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems; + for (AAINQInventoryResponseItem m : inventoryItems) { + if (m.vfModule != null && m.vfModule.isBaseVfModule == true) { + baseIndex = inventoryItems.indexOf(m); + } else if (m.vfModule != null && m.vfModule.isBaseVfModule == false && m.vfModule.orchestrationStatus == null) { + nonBaseIndex = inventoryItems.indexOf(m); + } + // + if (baseIndex != -1 && nonBaseIndex != -1) { + break; + } + } + + // Report the error if either base vf module or non-base vf module is not found + if (baseIndex == -1 || nonBaseIndex == -1) { + logger.error("Either base or non-base vf module is not found from AAI response."); + return; + } + + // This comes from the base module + setVfModuleItemVfModuleName(namedQueryResponseWrapper.aainqresponse.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(baseIndex).vfModule.vfModuleName); + setVfModuleItemVfModuleName(vfModuleItemVfModuleName.replace("Vfmodule", "vDNS")); + + // vfModuleItem - NOT the base module + setVfModuleItemPersonaModelId(namedQueryResponseWrapper.aainqresponse.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(nonBaseIndex).vfModule.personaModelId); + setVfModuleItemPersonaModelVersion(namedQueryResponseWrapper.aainqresponse.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(nonBaseIndex).vfModule.personaModelVersion); + setVfModuleItemModelName(namedQueryResponseWrapper.aainqresponse.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(nonBaseIndex).extraProperties.extraProperty.get(0).propertyValue); + setVfModuleItemModelNameVersionId(namedQueryResponseWrapper.aainqresponse.inventoryResponseItems.get(0).items.inventoryResponseItems.get(0).items.inventoryResponseItems.get(nonBaseIndex).extraProperties.extraProperty.get(4).propertyValue); + + // tenantItem + setTenantItemTenantId(namedQueryResponseWrapper.aainqresponse.inventoryResponseItems.get(0).items.inventoryResponseItems.get(1).tenant.tenantId); + + // cloudRegionItem + setCloudRegionItemCloudRegionId(namedQueryResponseWrapper.aainqresponse.inventoryResponseItems.get(0).items.inventoryResponseItems.get(1).items.inventoryResponseItems.get(0).cloudRegion.cloudRegionId); + + } catch (Exception e) { + logger.error(e.getMessage(), e); + VirtualControlLoopNotification notification = new VirtualControlLoopNotification(onset); + notification.notification = ControlLoopNotificationType.REJECTED; + notification.message = "Exception occurred " + e.getMessage(); + notification.policyName = onset.policyName; + notification.policyScope = onset.policyScope; + notification.policyVersion = onset.policyVersion; + // + try { + logger.debug(Serialization.gsonPretty.toJson(notification)); + } catch (Exception e1) { + logger.error("Can't deliver notification: " + notification); + logger.error(e1.getMessage(), e1); + } + // + notification.notification = ControlLoopNotificationType.FINAL_FAILURE; + notification.message = "Invalid named-query response from AAI"; + // + try { + logger.debug(Serialization.gsonPretty.toJson(notification)); + } catch (Exception e1) { + logger.error("Can't deliver notification: " + notification); + logger.error(e1.getMessage(), e1); + } + // Retract everything + return; + } + + // Extracted fields should not be null + if (checkExtractedFields() == false) { + System.err.println("some fields are missing from AAI response."); + return; + } + } + + /** + * Checks whether extracted fields from AAI Named Query are null or not + * @return false if some extracted fields are missing, true otherwise + */ + private boolean checkExtractedFields() { + + if ((getVnfItemVnfId() == null) || (getVnfItemVnfType() == null) || + (getVnfItemModelInvariantId() == null) || (getVnfItemModelName() == null) || + (getVnfItemModelVersion() == null) || (getVnfItemModelNameVersionId() == null) || + (getServiceItemServiceInstanceId() == null) || (getServiceItemModelName() == null) || + (getServiceItemModelType() == null) || (getServiceItemModelVersion() == null) || + (getServiceItemModelNameVersionId() == null) || (getVfModuleItemVfModuleName() == null) || + (getVfModuleItemPersonaModelId() == null) || (getVfModuleItemPersonaModelVersion() == null) || + (getVfModuleItemModelName() == null) || (getVfModuleItemModelNameVersionId() == null) || + (getTenantItemTenantId() == null) || (getCloudRegionItemCloudRegionId() == null)) { + return false; + } + return true; + } + + /** + * Construct SO Request + * + * @param onset + * @param operation + * @param policy + * @return SORequest + */ + public SORequest constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation, Policy policy) { + + if (policy.getActor().equals("SO") && policy.getRecipe().equals("VF Module Create")) { + // perform named query request and handle response + AaiNamedQueryRequest(onset); + } else { + // for future extension + return null; + }; + + // check if the fields extracted from named query response are + // not null so we can proceed with SO request + if (checkExtractedFields() == false) { + + System.err.println("AAI response is missing some required fields. Cannot proceed with SO Request construction."); + return null; + + } else { + + // Construct SO Request + SORequest request = new SORequest(); + request.requestId = onset.requestID; + request.requestDetails = new SORequestDetails(); + request.requestDetails.modelInfo = new SOModelInfo(); + request.requestDetails.cloudConfiguration = new SOCloudConfiguration(); + request.requestDetails.requestInfo = new SORequestInfo(); + request.requestDetails.requestParameters = new SORequestParameters(); + request.requestDetails.requestParameters.userParams = null; + // + // cloudConfiguration + // + request.requestDetails.cloudConfiguration.lcpCloudRegionId = getCloudRegionItemCloudRegionId(); + request.requestDetails.cloudConfiguration.tenantId = getTenantItemTenantId(); + // + // modelInfo + // + request.requestDetails.modelInfo.modelType = "vfModule"; + request.requestDetails.modelInfo.modelInvariantId = getVfModuleItemPersonaModelId(); + request.requestDetails.modelInfo.modelNameVersionId = getVfModuleItemModelNameVersionId(); + request.requestDetails.modelInfo.modelName = getVfModuleItemModelName(); + request.requestDetails.modelInfo.modelVersion = getVfModuleItemPersonaModelVersion(); + // + // requestInfo + // + request.requestDetails.requestInfo.instanceName = getVfModuleItemVfModuleName(); + request.requestDetails.requestInfo.source = "POLICY"; + request.requestDetails.requestInfo.suppressRollback = false; + // + // relatedInstanceList + // + SORelatedInstanceListElement relatedInstanceListElement1 = new SORelatedInstanceListElement(); + SORelatedInstanceListElement relatedInstanceListElement2 = new SORelatedInstanceListElement(); + relatedInstanceListElement1.relatedInstance = new SORelatedInstance(); + relatedInstanceListElement2.relatedInstance = new SORelatedInstance(); + // + relatedInstanceListElement1.relatedInstance.instanceId = getServiceItemServiceInstanceId(); + relatedInstanceListElement1.relatedInstance.modelInfo = new SOModelInfo(); + relatedInstanceListElement1.relatedInstance.modelInfo.modelType = "service"; + relatedInstanceListElement1.relatedInstance.modelInfo.modelInvariantId = getServiceItemPersonaModelId(); + relatedInstanceListElement1.relatedInstance.modelInfo.modelNameVersionId = getServiceItemModelNameVersionId(); + relatedInstanceListElement1.relatedInstance.modelInfo.modelName = getServiceItemModelName(); + relatedInstanceListElement1.relatedInstance.modelInfo.modelVersion = getServiceItemModelVersion(); + // + relatedInstanceListElement2.relatedInstance.instanceId = getVnfItemVnfId(); + relatedInstanceListElement2.relatedInstance.modelInfo = new SOModelInfo(); + relatedInstanceListElement2.relatedInstance.modelInfo.modelType = "vnf"; + relatedInstanceListElement2.relatedInstance.modelInfo.modelInvariantId = getVnfItemModelInvariantId(); + relatedInstanceListElement2.relatedInstance.modelInfo.modelNameVersionId = getVnfItemModelNameVersionId(); + relatedInstanceListElement2.relatedInstance.modelInfo.modelName = getVnfItemModelName(); + relatedInstanceListElement2.relatedInstance.modelInfo.modelVersion = getVnfItemModelVersion(); + relatedInstanceListElement2.relatedInstance.modelInfo.modelCustomizationName = getVnfItemVnfType(); + // + request.requestDetails.relatedInstanceList.add(relatedInstanceListElement1); + request.requestDetails.relatedInstanceList.add(relatedInstanceListElement2); + // + // print SO request for debug + // + logger.debug("SO request sent:"); + logger.debug(Serialization.gsonPretty.toJson(request)); + + return request; + } + } + + /** + * This method is needed to get the serviceInstanceId and vnfInstanceId which is used + * in the asyncSORestCall + * + * @param wm + * @param request + */ + public static void sendRequest(WorkingMemory wm, Object request) { + SOManager Mm = new SOManager(); + Mm.asyncSORestCall(wm, getServiceItemServiceInstanceId(), getVnfItemVnfId(), (SORequest)request); + } + + /** + * @return the vnfItemVnfId + */ + public static String getVnfItemVnfId() { + return vnfItemVnfId; + } + + /** + * @param vnfItemVnfId the vnfItemVnfId to set + */ + private void setVnfItemVnfId(String vnfItemVnfId) { + SOActorServiceProvider.vnfItemVnfId = vnfItemVnfId; + } + + /** + * @return the vnfItemVnfType + */ + public String getVnfItemVnfType() { + return this.vnfItemVnfType; + } + + /** + * @param vnfItemVnfType the vnfItemVnfType to set + */ + private void setVnfItemVnfType(String vnfItemVnfType) { + this.vnfItemVnfType = vnfItemVnfType; + } + + /** + * @return the vnfItemPersonaModelId + */ + public String getVnfItemModelInvariantId() { + return this.vnfItemModelInvariantId; + } + + /** + * @param vnfItemPersonaModelId the vnfItemPersonaModelId to set + */ + private void setVnfItemModelInvariantId(String vnfItemModelInvariantId) { + this.vnfItemModelInvariantId = vnfItemModelInvariantId; + } + + /** + * @return the vnfItemModelVersionId + */ + public String getVnfItemModelVersionId() { + return this.vnfItemModelVersionId; + } + + /** + * @param vnfItemModelVersionId the vnfItemModelVersionId to set + */ + private void setVnfItemModelVersionId(String vnfItemModelVersionId) { + this.vnfItemModelVersionId = vnfItemModelVersionId; + } + + /** + * @return the vnfItemModelName + */ + public String getVnfItemModelName() { + return this.vnfItemModelName; + } + + /** + * @param vnfItemModelName the vnfItemModelName to set + */ + private void setVnfItemModelName(String vnfItemModelName) { + this.vnfItemModelName = vnfItemModelName; + } + + /** + * @return the vnfItemModelVersion + */ + public String getVnfItemModelVersion() { + return this.vnfItemModelVersion; + } + + /** + * @param vnfItemModelVersion the vnfItemModelVersion to set + */ + private void setVnfItemModelVersion(String vnfItemModelVersion) { + this.vnfItemModelVersion = vnfItemModelVersion; + } + + /** + * @return the vnfItemModelNameVersionId + */ + public String getVnfItemModelNameVersionId() { + return this.vnfItemModelNameVersionId; + } + + /** + * @param vnfItemModelNameVersionId the vnfItemModelNameVersionId to set + */ + private void setVnfItemModelNameVersionId(String vnfItemModelNameVersionId) { + this.vnfItemModelNameVersionId = vnfItemModelNameVersionId; + } + + /** + * @return the serviceItemServiceInstanceId + */ + public static String getServiceItemServiceInstanceId() { + return serviceItemServiceInstanceId; + } + + /** + * @param serviceItemServiceInstanceId the serviceItemServiceInstanceId to set + */ + private void setServiceItemServiceInstanceId( + String serviceItemServiceInstanceId) { + SOActorServiceProvider.serviceItemServiceInstanceId = serviceItemServiceInstanceId; + } + + /** + * @return the serviceItemPersonaModelId + */ + public String getServiceItemPersonaModelId() { + return this.serviceItemPersonaModelId; + } + + /** + * @param serviceItemPersonaModelId the serviceItemPersonaModelId to set + */ + private void setServiceItemPersonaModelId(String serviceItemPersonaModelId) { + this.serviceItemPersonaModelId = serviceItemPersonaModelId; + } + + /** + * @return the serviceItemModelName + */ + public String getServiceItemModelName() { + return this.serviceItemModelName; + } + + /** + * @param serviceItemModelName the serviceItemModelName to set + */ + private void setServiceItemModelName(String serviceItemModelName) { + this.serviceItemModelName = serviceItemModelName; + } + + /** + * @return the serviceItemModelType + */ + public String getServiceItemModelType() { + return this.serviceItemModelType; + } + + /** + * @param serviceItemModelType the serviceItemModelType to set + */ + private void setServiceItemModelType(String serviceItemModelType) { + this.serviceItemModelType = serviceItemModelType; + } + + /** + * @return the serviceItemModelVersion + */ + public String getServiceItemModelVersion() { + return this.serviceItemModelVersion; + } + + /** + * @param serviceItemModelVersion the serviceItemModelVersion to set + */ + private void setServiceItemModelVersion(String serviceItemModelVersion) { + this.serviceItemModelVersion = serviceItemModelVersion; + } + + /** + * @return the serviceItemModelNameVersionId + */ + public String getServiceItemModelNameVersionId() { + return this.serviceItemModelNameVersionId; + } + + /** + * @param serviceItemModelNameVersionId the serviceItemModelNameVersionId to set + */ + private void setServiceItemModelNameVersionId( + String serviceItemModelNameVersionId) { + this.serviceItemModelNameVersionId = serviceItemModelNameVersionId; + } + + /** + * @return the vfModuleItemVfModuleName + */ + public String getVfModuleItemVfModuleName() { + return this.vfModuleItemVfModuleName; + } + + /** + * @param vfModuleItemVfModuleName the vfModuleItemVfModuleName to set + */ + private void setVfModuleItemVfModuleName(String vfModuleItemVfModuleName) { + this.vfModuleItemVfModuleName = vfModuleItemVfModuleName; + } + + /** + * @return the vfModuleItemPersonaModelId + */ + public String getVfModuleItemPersonaModelId() { + return this.vfModuleItemPersonaModelId; + } + + /** + * @param vfModuleItemPersonaModelId the vfModuleItemPersonaModelId to set + */ + private void setVfModuleItemPersonaModelId(String vfModuleItemPersonaModelId) { + this.vfModuleItemPersonaModelId = vfModuleItemPersonaModelId; + } + + /** + * @return the vfModuleItemPersonaModelVersion + */ + public String getVfModuleItemPersonaModelVersion() { + return this.vfModuleItemPersonaModelVersion; + } + + /** + * @param vfModuleItemPersonaModelVersion the vfModuleItemPersonaModelVersion to set + */ + private void setVfModuleItemPersonaModelVersion( + String vfModuleItemPersonaModelVersion) { + this.vfModuleItemPersonaModelVersion = vfModuleItemPersonaModelVersion; + } + + /** + * @return the vfModuleItemModelName + */ + public String getVfModuleItemModelName() { + return this.vfModuleItemModelName; + } + + /** + * @param vfModuleItemModelName the vfModuleItemModelName to set + */ + private void setVfModuleItemModelName(String vfModuleItemModelName) { + this.vfModuleItemModelName = vfModuleItemModelName; + } + + /** + * @return the vfModuleItemModelNameVersionId + */ + public String getVfModuleItemModelNameVersionId() { + return this.vfModuleItemModelNameVersionId; + } + + /** + * @param vfModuleItemModelNameVersionId the vfModuleItemModelNameVersionId to set + */ + private void setVfModuleItemModelNameVersionId( + String vfModuleItemModelNameVersionId) { + this.vfModuleItemModelNameVersionId = vfModuleItemModelNameVersionId; + } + + /** + * @return the tenantItemTenantId + */ + public String getTenantItemTenantId() { + return this.tenantItemTenantId; + } + + /** + * @param tenantItemTenantId the tenantItemTenantId to set + */ + private void setTenantItemTenantId(String tenantItemTenantId) { + this.tenantItemTenantId = tenantItemTenantId; + } + + /** + * @return the cloudRegionItemCloudRegionId + */ + public String getCloudRegionItemCloudRegionId() { + return this.cloudRegionItemCloudRegionId; + } + + /** + * @param cloudRegionItemCloudRegionId the cloudRegionItemCloudRegionId to set + */ + private void setCloudRegionItemCloudRegionId( + String cloudRegionItemCloudRegionId) { + this.cloudRegionItemCloudRegionId = cloudRegionItemCloudRegionId; + } + +} diff --git a/controlloop/common/actors/actor.so/src/main/resources/META-INF/services/org.onap.policy.controlloop.actorServiceProvider.spi.Actor b/controlloop/common/actors/actor.so/src/main/resources/META-INF/services/org.onap.policy.controlloop.actorServiceProvider.spi.Actor new file mode 100644 index 000000000..ad136e98f --- /dev/null +++ b/controlloop/common/actors/actor.so/src/main/resources/META-INF/services/org.onap.policy.controlloop.actorServiceProvider.spi.Actor @@ -0,0 +1 @@ +org.onap.policy.controlloop.actor.so.SOActorServiceProvider \ No newline at end of file diff --git a/controlloop/common/actors/pom.xml b/controlloop/common/actors/pom.xml index 1f38e90b1..48335de75 100644 --- a/controlloop/common/actors/pom.xml +++ b/controlloop/common/actors/pom.xml @@ -16,7 +16,7 @@ actor.appc actor.vfc actor.appclcm - actor.mso + actor.so actor.test diff --git a/controlloop/common/eventmanager/pom.xml b/controlloop/common/eventmanager/pom.xml index 69d858a07..a3227cbc1 100644 --- a/controlloop/common/eventmanager/pom.xml +++ b/controlloop/common/eventmanager/pom.xml @@ -54,7 +54,7 @@ org.onap.policy.drools-applications - actor.mso + actor.so 1.1.0-SNAPSHOT provided @@ -132,7 +132,7 @@ org.onap.policy.drools-applications - mso + so 1.1.0-SNAPSHOT provided diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java index a1ae9f0d5..7751a4108 100644 --- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java +++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java @@ -40,8 +40,8 @@ import org.onap.policy.controlloop.actor.appc.APPCActorServiceProvider; import org.onap.policy.controlloop.actor.vfc.VFCActorServiceProvider; import org.onap.policy.controlloop.policy.Policy; import org.onap.policy.controlloop.policy.PolicyResult; -import org.onap.policy.controlloop.actor.mso.MSOActorServiceProvider; -import org.onap.policy.mso.SOResponse; +import org.onap.policy.controlloop.actor.so.SOActorServiceProvider; +import org.onap.policy.so.SOResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.onap.policy.controlloop.actor.appclcm.AppcLcmActorServiceProvider; @@ -214,7 +214,7 @@ public class ControlLoopOperationManager implements Serializable { this.currentOperation = operation; return operationRequest; case "SO": - MSOActorServiceProvider SOAsp = new MSOActorServiceProvider(); + SOActorServiceProvider SOAsp = new SOActorServiceProvider(); this.operationRequest = SOAsp.constructRequest((VirtualControlLoopEvent)onset, operation.operation, this.policy); // Save the operation diff --git a/controlloop/common/model-impl/mso/pom.xml b/controlloop/common/model-impl/mso/pom.xml deleted file mode 100644 index 5d386688d..000000000 --- a/controlloop/common/model-impl/mso/pom.xml +++ /dev/null @@ -1,57 +0,0 @@ - - - - 4.0.0 - - mso - - - org.onap.policy.drools-applications - model-impl - 1.1.0-SNAPSHOT - - - - - junit - junit - 4.12 - provided - - - com.google.code.gson - gson - 2.5 - provided - - - org.drools - drools-core - 6.5.0.Final - provided - - - org.onap.policy.drools-applications - rest - ${project.version} - - - diff --git a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOAsyncRequestStatus.java b/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOAsyncRequestStatus.java deleted file mode 100644 index 600816304..000000000 --- a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOAsyncRequestStatus.java +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * mso - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= - */ - -package org.onap.policy.mso; - -import java.io.Serializable; -import java.time.LocalDateTime; - -import com.google.gson.annotations.SerializedName; - -public class SOAsyncRequestStatus implements Serializable { - - /** - * - */ - private static final long serialVersionUID = -3283942659786236032L; - - @SerializedName("correlator") - public String correlator; - - @SerializedName("requestId") - public String requestId; - - @SerializedName("instanceReferences") - public SOInstanceReferences instanceReferences; - - @SerializedName("startTime") - public LocalDateTime startTime; - - @SerializedName("finishTime") - public LocalDateTime finishTime; - - @SerializedName("requestScope") - public String requestScope; - - @SerializedName("requestType") - public String requestType; - - @SerializedName("requestStatus") - public SORequestStatus requestStatus; - - - public SOAsyncRequestStatus() { - } - -} diff --git a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOCloudConfiguration.java b/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOCloudConfiguration.java deleted file mode 100644 index 7e4951166..000000000 --- a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOCloudConfiguration.java +++ /dev/null @@ -1,44 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * mso - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= - */ - -package org.onap.policy.mso; - -import java.io.Serializable; - - -import com.google.gson.annotations.SerializedName; - -public class SOCloudConfiguration implements Serializable { - - /** - * - */ - private static final long serialVersionUID = -3283942659786236032L; - - @SerializedName("lcpCloudRegionId") - public String lcpCloudRegionId; - - @SerializedName("tenantId") - public String tenantId; - - public SOCloudConfiguration() { - } - -} diff --git a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOInstanceReferences.java b/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOInstanceReferences.java deleted file mode 100644 index 894b17ade..000000000 --- a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOInstanceReferences.java +++ /dev/null @@ -1,44 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * mso - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= - */ - -package org.onap.policy.mso; - -import java.io.Serializable; - - -import com.google.gson.annotations.SerializedName; - -public class SOInstanceReferences implements Serializable { - - /** - * - */ - private static final long serialVersionUID = -3283942659786236032L; - - @SerializedName("requestId") - public String requestId; - - @SerializedName("instanceId") - public String instanceId; - - public SOInstanceReferences() { - } - -} diff --git a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOManager.java b/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOManager.java deleted file mode 100644 index ea9146d24..000000000 --- a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOManager.java +++ /dev/null @@ -1,168 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * mso - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= - */ - -package org.onap.policy.mso; - -import java.util.Base64; -import java.util.HashMap; -import java.util.Map; - -import org.onap.policy.mso.util.Serialization; -import org.onap.policy.rest.RESTManager; -import org.onap.policy.rest.RESTManager.Pair; -import org.drools.core.WorkingMemory; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonSyntaxException; - -public final class SOManager { - - private static final Logger logger = LoggerFactory.getLogger(SOManager.class); - private static ExecutorService executors = Executors.newCachedThreadPool(); - - public static SOResponse createModuleInstance(String url, String urlBase, String username, String password, SORequest request) { - - // - // Call REST - // - Map headers = new HashMap(); - //headers.put("X-FromAppId", "POLICY"); - //headers.put("X-TransactionId", requestID.toString()); - headers.put("Accept", "application/json"); - - // - // 201 - CREATED - you are done just return - // - - Pair httpDetails = RESTManager.post(url, username, password, headers, "application/json", Serialization.gsonPretty.toJson(request)); - - if (httpDetails == null) { - return null; - } - - if (httpDetails.a == 202) { - try { - SOResponse response = Serialization.gsonPretty.fromJson(httpDetails.b, SOResponse.class); - - String body = Serialization.gsonPretty.toJson(response); - logger.debug("***** Response to post:"); - logger.debug(body); - - String requestId = response.requestReferences.requestId; - int attemptsLeft = 20; - - //String getUrl = "/orchestrationRequests/v2/"+requestId; - String urlGet = urlBase + "/orchestrationRequests/v2/"+requestId; - SOResponse responseGet = null; - - while(attemptsLeft-- > 0){ - - Pair httpDetailsGet = RESTManager.get(urlGet, username, password, headers); - responseGet = Serialization.gsonPretty.fromJson(httpDetailsGet.b, SOResponse.class); - body = Serialization.gsonPretty.toJson(responseGet); - logger.debug("***** Response to get:"); - logger.debug(body); - - if(httpDetailsGet.a == 200){ - if(responseGet.request.requestStatus.requestState.equalsIgnoreCase("COMPLETE") || - responseGet.request.requestStatus.requestState.equalsIgnoreCase("FAILED")){ - logger.debug("***** ######## VF Module Creation "+responseGet.request.requestStatus.requestState); - return responseGet; - } - } - Thread.sleep(20000); - } - - if (responseGet != null - && responseGet.request != null - && responseGet.request.requestStatus != null - && responseGet.request.requestStatus.requestState != null) { - logger.warn("***** ######## VF Module Creation timeout. Status: ( {})", responseGet.request.requestStatus.requestState); - } - - return responseGet; - } catch (JsonSyntaxException e) { - logger.error("Failed to deserialize into SOResponse: ", e); - } catch (InterruptedException e) { - logger.error("Interrupted exception: ", e); - } - } - - - - - return null; - } - - /** - * - * @param wm - * @param url - * @param urlBase - * @param username - * @param password - * @param request - * - * This method makes an asynchronous Rest call to MSO and inserts the response into the Drools working memory - */ - public void asyncMSORestCall(WorkingMemory wm, String serviceInstanceId, String vnfInstanceId, SORequest request) { - executors.submit(new Runnable() - { - @Override - public void run() - { - String serverRoot = ""; // TODO - String username = ""; // TODO - String password = ""; // TODO - String url = serverRoot + "/serviceInstances/v5/" + serviceInstanceId + "/vnfs/" + vnfInstanceId + "/vfModules"; - - String auth = username + ":" + password; - - Map headers = new HashMap(); - byte[] encodedBytes = Base64.getEncoder().encode(auth.getBytes()); - headers.put("Accept", "application/json"); - headers.put("Authorization", "Basic " + new String(encodedBytes)); - - Gson gsonPretty = new GsonBuilder().disableHtmlEscaping() - .setPrettyPrinting() - .create(); - - String msoJson = gsonPretty.toJson(request); - - SOResponse mso = new SOResponse(); - Pair httpResponse = RESTManager.post(url, "policy", "policy", headers, "application/json", msoJson); - if (httpResponse != null) { - Gson gson = new Gson(); - mso = gson.fromJson(httpResponse.b, SOResponse.class); - mso.httpResponseCode = httpResponse.a; - } - -// logger.info("MSOResponse inserted " + mso.toString()); - wm.insert(mso); - } - }); - } - -} diff --git a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOModelInfo.java b/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOModelInfo.java deleted file mode 100644 index cba763daf..000000000 --- a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOModelInfo.java +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * mso - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= - */ - -package org.onap.policy.mso; - -import java.io.Serializable; - - -import com.google.gson.annotations.SerializedName; - -public class SOModelInfo implements Serializable { - - /** - * - */ - private static final long serialVersionUID = -3283942659786236032L; - - @SerializedName("modelType") - public String modelType; - - @SerializedName("modelInvariantId") - public String modelInvariantId; - - @SerializedName("modelNameVersionId") - public String modelNameVersionId; - - @SerializedName("modelName") - public String modelName; - - @SerializedName("modelVersion") - public String modelVersion; - - @SerializedName("modelCustomizationName") - public String modelCustomizationName; - - @SerializedName("modelCustomizationId") - public String modelCustomizationId; - - public SOModelInfo() { - } - -} diff --git a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOPolicyException.java b/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOPolicyException.java deleted file mode 100644 index a2c9f81aa..000000000 --- a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOPolicyException.java +++ /dev/null @@ -1,43 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * mso - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= - */ - -package org.onap.policy.mso; - -import java.io.Serializable; - -import com.google.gson.annotations.SerializedName; - -public class SOPolicyException implements Serializable { - - /** - * - */ - private static final long serialVersionUID = -3283942659786236032L; - - @SerializedName("messageId") - public String messageId; - - @SerializedName("text") - public String text; - - public SOPolicyException() { - } - -} diff --git a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORelatedInstance.java b/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORelatedInstance.java deleted file mode 100644 index d9d634a57..000000000 --- a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORelatedInstance.java +++ /dev/null @@ -1,49 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * mso - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= - */ - -package org.onap.policy.mso; - -import java.io.Serializable; - - - -import com.google.gson.annotations.SerializedName; - -public class SORelatedInstance implements Serializable { - - /** - * - */ - private static final long serialVersionUID = -3283942659786236032L; - - @SerializedName("instanceId") - public String instanceId; - - @SerializedName("instanceName") - public String instanceName; - - @SerializedName("modelInfo") - public SOModelInfo modelInfo; - - - public SORelatedInstance() { - } - -} diff --git a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORelatedInstanceListElement.java b/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORelatedInstanceListElement.java deleted file mode 100644 index f32f7ccb1..000000000 --- a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORelatedInstanceListElement.java +++ /dev/null @@ -1,42 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * mso - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= - */ - -package org.onap.policy.mso; - -import java.io.Serializable; - - -import com.google.gson.annotations.SerializedName; - -public class SORelatedInstanceListElement implements Serializable { - - /** - * - */ - private static final long serialVersionUID = -3283942659786236032L; - - @SerializedName("relatedInstance") - public SORelatedInstance relatedInstance; - - - public SORelatedInstanceListElement() { - } - -} diff --git a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORequest.java b/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORequest.java deleted file mode 100644 index 83a761377..000000000 --- a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORequest.java +++ /dev/null @@ -1,60 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * mso - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= - */ - -package org.onap.policy.mso; - -import java.io.Serializable; -import java.time.LocalDateTime; - -import com.google.gson.annotations.SerializedName; - -public class SORequest implements Serializable { - - /** - * - */ - private static final long serialVersionUID = -3283942659786236032L; - - @SerializedName("requestId") - public String requestId; - - @SerializedName("startTime") - //public LocalDateTime startTime; - public String startTime; - - @SerializedName("finishTime") - public LocalDateTime finishTime; - - @SerializedName("requestScope") - public String requestScope; - - @SerializedName("requestType") - public String requestType; - - @SerializedName("requestDetails") - public SORequestDetails requestDetails; - - @SerializedName("requestStatus") - public SORequestStatus requestStatus; - - public SORequest() { - } - -} diff --git a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORequestDetails.java b/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORequestDetails.java deleted file mode 100644 index 4b4b8217e..000000000 --- a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORequestDetails.java +++ /dev/null @@ -1,124 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * mso - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= - */ - -package org.onap.policy.mso; - -import java.io.Serializable; -import java.util.LinkedList; -import java.util.List; - -import com.google.gson.annotations.SerializedName; - -public class SORequestDetails implements Serializable { - - /** - * - */ - private static final long serialVersionUID = -3283942659786236032L; - - @SerializedName("modelInfo") - public SOModelInfo modelInfo; - - @SerializedName("cloudConfiguration") - public SOCloudConfiguration cloudConfiguration; - - @SerializedName("requestInfo") - public SORequestInfo requestInfo; - - @SerializedName("subscriberInfo") - public SOSubscriberInfo subscriberInfo; - - @SerializedName("relatedInstanceList") - public List relatedInstanceList= new LinkedList(); - - @SerializedName("requestParameters") - public SORequestParameters requestParameters; - - public SORequestDetails() { - - } - - public SORequestDetails(SORequestDetails soRequestDetails) { - this.modelInfo = soRequestDetails.modelInfo; - this.cloudConfiguration = soRequestDetails.cloudConfiguration; - this.requestInfo = soRequestDetails.requestInfo; - this.relatedInstanceList = soRequestDetails.relatedInstanceList; - this.requestParameters = soRequestDetails.requestParameters; - } - - @Override - public String toString() { - return "SORequestDetails [modelInfo=" + modelInfo - + ", cloudConfiguration=" + cloudConfiguration - + ", requestInfo=" + requestInfo + ", relatedInstanceList=" - + relatedInstanceList + ", requestParameters=" - + requestParameters + "]"; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((cloudConfiguration == null) ? 0 : cloudConfiguration.hashCode()); - result = prime * result + ((modelInfo == null) ? 0 : modelInfo.hashCode()); - result = prime * result + ((relatedInstanceList == null) ? 0 : relatedInstanceList.hashCode()); - result = prime * result + ((requestInfo == null) ? 0 : requestInfo.hashCode()); - result = prime * result + ((requestParameters == null) ? 0 : requestParameters.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - SORequestDetails other = (SORequestDetails) obj; - if (cloudConfiguration == null) { - if (other.cloudConfiguration != null) - return false; - } else if (!cloudConfiguration.equals(other.cloudConfiguration)) - return false; - if (modelInfo == null) { - if (other.modelInfo != null) - return false; - } else if (!modelInfo.equals(other.modelInfo)) - return false; - if (relatedInstanceList == null) { - if (other.relatedInstanceList != null) - return false; - } else if (!relatedInstanceList.equals(other.relatedInstanceList)) - return false; - if (requestInfo == null) { - if (other.requestInfo != null) - return false; - } else if (!requestInfo.equals(other.requestInfo)) - return false; - if (requestParameters == null) { - if (other.requestParameters != null) - return false; - } else if (!requestParameters.equals(other.requestParameters)) - return false; - return true; - } - -} diff --git a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORequestError.java b/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORequestError.java deleted file mode 100644 index 76b62bfa0..000000000 --- a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORequestError.java +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * mso - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= - */ - -package org.onap.policy.mso; - -import java.io.Serializable; - -import com.google.gson.annotations.SerializedName; - -public class SORequestError implements Serializable { - - /** - * - */ - private static final long serialVersionUID = -3283942659786236032L; - - - @SerializedName("policyException") - public SOPolicyException policyException; - - - @SerializedName("serviceException") - public SOServiceException serviceException; - - /* - @SerializedName("messageId") - public String messageId; - - @SerializedName("text") - public String text; - - @SerializedName("url") - public String url; - - @SerializedName("variables") - public String variables; - */ - - public SORequestError() { - } - -} diff --git a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORequestInfo.java b/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORequestInfo.java deleted file mode 100644 index 9e5b93ccb..000000000 --- a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORequestInfo.java +++ /dev/null @@ -1,66 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * mso - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= - */ - -package org.onap.policy.mso; - -import java.io.Serializable; - - -import com.google.gson.annotations.SerializedName; - -public class SORequestInfo implements Serializable { - - /** - * - */ - private static final long serialVersionUID = -3283942659786236032L; - - @SerializedName("instanceName") - public String instanceName; - - @SerializedName("source") - public String source; - - @SerializedName("productFamilyId") - public String productFamilyId; - - @SerializedName("suppressRollback") - public boolean suppressRollback; - - @SerializedName("billingAccountNumber") - public String billingAccountNumber; - - @SerializedName("callbackUrl") - public String callbackUrl; - - @SerializedName("correlator") - public String correlator; - - @SerializedName("orderNumber") - public String orderNumber; - - @SerializedName("orderVersion") - public Integer orderVersion; - - - public SORequestInfo() { - } - -} diff --git a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORequestParameters.java b/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORequestParameters.java deleted file mode 100644 index 6e45afe83..000000000 --- a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORequestParameters.java +++ /dev/null @@ -1,47 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * mso - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= - */ - -package org.onap.policy.mso; - -import java.io.Serializable; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - - -import com.google.gson.annotations.SerializedName; - -public class SORequestParameters implements Serializable { - - /** - * - */ - private static final long serialVersionUID = -3283942659786236032L; - - @SerializedName("subscriptionServiceType") - public String subscriptionServiceType; - - @SerializedName("userParams") - public List> userParams = new LinkedList>(); - - public SORequestParameters() { - } - -} diff --git a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORequestReferences.java b/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORequestReferences.java deleted file mode 100644 index ea8ebc64a..000000000 --- a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORequestReferences.java +++ /dev/null @@ -1,38 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * mso - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= - */ - -package org.onap.policy.mso; - -import java.io.Serializable; - - -import com.google.gson.annotations.SerializedName; - -public class SORequestReferences implements Serializable { - - private static final long serialVersionUID = -3283942659786236032L; - - @SerializedName("instanceId") - public String instanceId; - - @SerializedName("requestId") - public String requestId; - -} diff --git a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORequestStatus.java b/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORequestStatus.java deleted file mode 100644 index d5174328e..000000000 --- a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SORequestStatus.java +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * mso - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= - */ - -package org.onap.policy.mso; - -import java.io.Serializable; - -import com.google.gson.annotations.SerializedName; - -public class SORequestStatus implements Serializable { - - /** - * - */ - private static final long serialVersionUID = -3283942659786236032L; - - @SerializedName("percentProgress") - public int percentProgress; - - @SerializedName("requestState") - public String requestState; - - @SerializedName("timestamp") - //public LocalDateTime timestamp; - public String timestamp; - - @SerializedName("wasRolledBack") - public boolean wasRolledBack; - - - public SORequestStatus() { - } - -} diff --git a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOResponse.java b/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOResponse.java deleted file mode 100644 index ddf937593..000000000 --- a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOResponse.java +++ /dev/null @@ -1,49 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * mso - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= - */ - -package org.onap.policy.mso; - -import java.io.Serializable; - -import com.google.gson.annotations.SerializedName; - -public class SOResponse implements Serializable { - - /** - * - */ - private static final long serialVersionUID = -3283942659786236032L; - - @SerializedName("requestReferences") - public SORequestReferences requestReferences; - - @SerializedName("requestError") - public SORequestError requestError; - - @SerializedName("request") - public SORequest request; - - public int httpResponseCode; - - - public SOResponse() { - } - -} diff --git a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOServiceException.java b/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOServiceException.java deleted file mode 100644 index 4a806ced4..000000000 --- a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOServiceException.java +++ /dev/null @@ -1,48 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * mso - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= - */ - -package org.onap.policy.mso; - -import java.io.Serializable; -import java.util.LinkedList; -import java.util.List; - -import com.google.gson.annotations.SerializedName; - -public class SOServiceException implements Serializable { - - /** - * - */ - private static final long serialVersionUID = -3283942659786236032L; - - @SerializedName("messageId") - public String messageId; - - @SerializedName("text") - public String text; - - @SerializedName("variables") - public List variables = new LinkedList(); - - public SOServiceException() { - } - -} diff --git a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOSubscriberInfo.java b/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOSubscriberInfo.java deleted file mode 100644 index 97d620f5c..000000000 --- a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/SOSubscriberInfo.java +++ /dev/null @@ -1,47 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * mso - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= - */ - -package org.onap.policy.mso; - -import java.io.Serializable; - - -import com.google.gson.annotations.SerializedName; - -public class SOSubscriberInfo implements Serializable { - - /** - * - */ - private static final long serialVersionUID = -3283942659786236032L; - - @SerializedName("globalSubscriberId") - public String globalSubscriberId; - - @SerializedName("subscriberCommonSiteId") - public String subscriberCommonSiteId; - - @SerializedName("subscriberName") - public String subscriberName; - - public SOSubscriberInfo() { - } - -} diff --git a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/util/Serialization.java b/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/util/Serialization.java deleted file mode 100644 index 24eb2951a..000000000 --- a/controlloop/common/model-impl/mso/src/main/java/org/onap/policy/mso/util/Serialization.java +++ /dev/null @@ -1,32 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * mso - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= - */ - -package org.onap.policy.mso.util; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - -public final class Serialization { - - final static public Gson gsonPretty = new GsonBuilder().disableHtmlEscaping() - .setPrettyPrinting() - .create(); - -} diff --git a/controlloop/common/model-impl/mso/src/test/java/org/onap/policy/mso/TestDemo.java b/controlloop/common/model-impl/mso/src/test/java/org/onap/policy/mso/TestDemo.java deleted file mode 100644 index bfbbf0b57..000000000 --- a/controlloop/common/model-impl/mso/src/test/java/org/onap/policy/mso/TestDemo.java +++ /dev/null @@ -1,167 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * mso - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= - */ - -package org.onap.policy.mso; - -import java.util.HashMap; -import java.util.Map; - -import org.junit.Test; -import org.onap.policy.mso.SOCloudConfiguration; -import org.onap.policy.mso.SOModelInfo; -import org.onap.policy.mso.SORelatedInstance; -import org.onap.policy.mso.SORelatedInstanceListElement; -import org.onap.policy.mso.SORequest; -import org.onap.policy.mso.SORequestDetails; -import org.onap.policy.mso.SORequestInfo; -import org.onap.policy.mso.SORequestParameters; -import org.onap.policy.mso.util.Serialization; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class TestDemo { - private static final Logger logger = LoggerFactory.getLogger(TestDemo.class); - @Test - public void test() { - - SORequest request = new SORequest(); - request.requestDetails = new SORequestDetails(); - request.requestDetails.modelInfo = new SOModelInfo(); - request.requestDetails.cloudConfiguration = new SOCloudConfiguration(); - request.requestDetails.requestInfo = new SORequestInfo(); - request.requestDetails.requestParameters = new SORequestParameters(); - - request.requestDetails.modelInfo.modelType = "vfModule"; - request.requestDetails.modelInfo.modelInvariantId = "ff5256d2-5a33-55df-13ab-12abad84e7ff"; - request.requestDetails.modelInfo.modelNameVersionId = "fe6478e5-ea33-3346-ac12-ab121484a3fe"; - request.requestDetails.modelInfo.modelName = "vSAMP12..base..module-0"; - request.requestDetails.modelInfo.modelVersion = "1"; - - request.requestDetails.cloudConfiguration.lcpCloudRegionId = "mdt1"; - request.requestDetails.cloudConfiguration.tenantId = "88a6ca3ee0394ade9403f075db23167e"; - - request.requestDetails.requestInfo.instanceName = "SOTEST103a-vSAMP12_base_module-0"; - request.requestDetails.requestInfo.source = "VID"; - request.requestDetails.requestInfo.suppressRollback = true; - - SORelatedInstanceListElement relatedInstanceListElement1 = new SORelatedInstanceListElement(); - SORelatedInstanceListElement relatedInstanceListElement2 = new SORelatedInstanceListElement(); - SORelatedInstanceListElement relatedInstanceListElement3 = new SORelatedInstanceListElement(); - relatedInstanceListElement1.relatedInstance = new SORelatedInstance(); - relatedInstanceListElement2.relatedInstance = new SORelatedInstance(); - relatedInstanceListElement3.relatedInstance = new SORelatedInstance(); - - relatedInstanceListElement1.relatedInstance.instanceId = "17ef4658-bd1f-4ef0-9ca0-ea76e2bf122c"; - relatedInstanceListElement1.relatedInstance.instanceName = "SOTESTVOL103a-vSAMP12_base_module-0_vol"; - relatedInstanceListElement1.relatedInstance.modelInfo = new SOModelInfo(); - relatedInstanceListElement1.relatedInstance.modelInfo.modelType = "volumeGroup"; - - relatedInstanceListElement2.relatedInstance.instanceId = "serviceInstanceId"; - relatedInstanceListElement2.relatedInstance.modelInfo = new SOModelInfo(); - relatedInstanceListElement2.relatedInstance.modelInfo.modelType = "service"; - relatedInstanceListElement2.relatedInstance.modelInfo.modelInvariantId = "ff3514e3-5a33-55df-13ab-12abad84e7ff"; - relatedInstanceListElement2.relatedInstance.modelInfo.modelNameVersionId = "fe6985cd-ea33-3346-ac12-ab121484a3fe"; - relatedInstanceListElement2.relatedInstance.modelInfo.modelName = "parent service model name"; - relatedInstanceListElement2.relatedInstance.modelInfo.modelVersion = "1.0"; - - relatedInstanceListElement3.relatedInstance.instanceId = "vnfInstanceId"; - relatedInstanceListElement3.relatedInstance.modelInfo = new SOModelInfo(); - relatedInstanceListElement3.relatedInstance.modelInfo.modelType = "vnf"; - relatedInstanceListElement3.relatedInstance.modelInfo.modelInvariantId = "ff5256d1-5a33-55df-13ab-12abad84e7ff"; - relatedInstanceListElement3.relatedInstance.modelInfo.modelNameVersionId = "fe6478e4-ea33-3346-ac12-ab121484a3fe"; - relatedInstanceListElement3.relatedInstance.modelInfo.modelName = "vSAMP12"; - relatedInstanceListElement3.relatedInstance.modelInfo.modelVersion = "1.0"; - relatedInstanceListElement3.relatedInstance.modelInfo.modelCustomizationName = "vSAMP12 1"; - - request.requestDetails.relatedInstanceList.add(relatedInstanceListElement1); - request.requestDetails.relatedInstanceList.add(relatedInstanceListElement2); - request.requestDetails.relatedInstanceList.add(relatedInstanceListElement3); - - Map userParam1 = new HashMap<>(); - userParam1.put("name1", "value1"); - - Map userParam2 = new HashMap<>(); - userParam2.put("name2", "value2"); - - request.requestDetails.requestParameters.userParams.add(userParam1); - request.requestDetails.requestParameters.userParams.add(userParam2); - - logger.debug(Serialization.gsonPretty.toJson(request)); - - } - - @Test - public void testHack() { - - logger.debug("** HACK **"); - - SORequest request = new SORequest(); - // - request.requestDetails = new SORequestDetails(); - request.requestDetails.modelInfo = new SOModelInfo(); - request.requestDetails.cloudConfiguration = new SOCloudConfiguration(); - request.requestDetails.requestInfo = new SORequestInfo(); - request.requestDetails.requestParameters = new SORequestParameters(); - request.requestDetails.requestParameters.userParams = null; - - request.requestDetails.modelInfo.modelType = "vfModule"; - request.requestDetails.modelInfo.modelInvariantId = "a9c4a35a-de48-451a-9e4e-343f2ac52928"; - request.requestDetails.modelInfo.modelNameVersionId = "e0d98ad1-238d-4555-b439-023d3f9079f6"; - request.requestDetails.modelInfo.modelName = "0d9e0d9d352749f4B3cb..dnsscaling..module-0"; - request.requestDetails.modelInfo.modelVersion = "2.0"; - - request.requestDetails.cloudConfiguration.lcpCloudRegionId = "DFW"; - request.requestDetails.cloudConfiguration.tenantId = "1015548"; - - request.requestDetails.requestInfo.instanceName = "Vfmodule_Ete_Name1eScaling63928f-ccdc-4b34-bdef-9bf64109026e"; - request.requestDetails.requestInfo.source = "POLICY"; - request.requestDetails.requestInfo.suppressRollback = false; - - SORelatedInstanceListElement relatedInstanceListElement1 = new SORelatedInstanceListElement(); - SORelatedInstanceListElement relatedInstanceListElement2 = new SORelatedInstanceListElement(); - relatedInstanceListElement1.relatedInstance = new SORelatedInstance(); - relatedInstanceListElement2.relatedInstance = new SORelatedInstance(); - - String serviceInstanceId = "98af39ce-6408-466b-921f-c2c7a8f59ed6"; - relatedInstanceListElement1.relatedInstance.instanceId = serviceInstanceId; - relatedInstanceListElement1.relatedInstance.modelInfo = new SOModelInfo(); - relatedInstanceListElement1.relatedInstance.modelInfo.modelType = "service"; - relatedInstanceListElement1.relatedInstance.modelInfo.modelInvariantId = "24329a0c-1d57-4210-b1af-a65df64e9d59"; - relatedInstanceListElement1.relatedInstance.modelInfo.modelNameVersionId = "ac642881-8e7e-4217-bd64-16ad41c42e30"; - relatedInstanceListElement1.relatedInstance.modelInfo.modelName = "5116d67e-0b4f-46bf-a46f"; - relatedInstanceListElement1.relatedInstance.modelInfo.modelVersion = "2.0"; - - String vnfInstanceId = "8eb411b8-a936-412f-b01f-9a9a435c0e93"; - relatedInstanceListElement2.relatedInstance.instanceId = vnfInstanceId; - relatedInstanceListElement2.relatedInstance.modelInfo = new SOModelInfo(); - relatedInstanceListElement2.relatedInstance.modelInfo.modelType = "vnf"; - relatedInstanceListElement2.relatedInstance.modelInfo.modelInvariantId = "09fd971e-db5f-475d-997c-cf6704b6b8fe"; - relatedInstanceListElement2.relatedInstance.modelInfo.modelNameVersionId = "152ed917-6dcc-46ee-bf8a-a775c5aa5a74"; - relatedInstanceListElement2.relatedInstance.modelInfo.modelName = "9e4c31d2-4b25-4d9e-9fb4"; - relatedInstanceListElement2.relatedInstance.modelInfo.modelVersion = "2.0"; - relatedInstanceListElement2.relatedInstance.modelInfo.modelCustomizationName = "0d9e0d9d-3527-49f4-b3cb 2"; - - request.requestDetails.relatedInstanceList.add(relatedInstanceListElement1); - request.requestDetails.relatedInstanceList.add(relatedInstanceListElement2); - - logger.debug(Serialization.gsonPretty.toJson(request)); - } - -} diff --git a/controlloop/common/model-impl/pom.xml b/controlloop/common/model-impl/pom.xml index e96befbf7..3f0c004e6 100644 --- a/controlloop/common/model-impl/pom.xml +++ b/controlloop/common/model-impl/pom.xml @@ -37,7 +37,7 @@ appc appclcm events - mso + so rest sdc trafficgenerator diff --git a/controlloop/common/model-impl/so/pom.xml b/controlloop/common/model-impl/so/pom.xml new file mode 100644 index 000000000..faeb12130 --- /dev/null +++ b/controlloop/common/model-impl/so/pom.xml @@ -0,0 +1,57 @@ + + + + 4.0.0 + + so + + + org.onap.policy.drools-applications + model-impl + 1.1.0-SNAPSHOT + + + + + junit + junit + 4.12 + provided + + + com.google.code.gson + gson + 2.5 + provided + + + org.drools + drools-core + 6.5.0.Final + provided + + + org.onap.policy.drools-applications + rest + ${project.version} + + + diff --git a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOAsyncRequestStatus.java b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOAsyncRequestStatus.java new file mode 100644 index 000000000..97978c73f --- /dev/null +++ b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOAsyncRequestStatus.java @@ -0,0 +1,63 @@ +/*- + * ============LICENSE_START======================================================= + * mso + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= + */ + +package org.onap.policy.so; + +import java.io.Serializable; +import java.time.LocalDateTime; + +import com.google.gson.annotations.SerializedName; + +public class SOAsyncRequestStatus implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -3283942659786236032L; + + @SerializedName("correlator") + public String correlator; + + @SerializedName("requestId") + public String requestId; + + @SerializedName("instanceReferences") + public SOInstanceReferences instanceReferences; + + @SerializedName("startTime") + public LocalDateTime startTime; + + @SerializedName("finishTime") + public LocalDateTime finishTime; + + @SerializedName("requestScope") + public String requestScope; + + @SerializedName("requestType") + public String requestType; + + @SerializedName("requestStatus") + public SORequestStatus requestStatus; + + + public SOAsyncRequestStatus() { + } + +} diff --git a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOCloudConfiguration.java b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOCloudConfiguration.java new file mode 100644 index 000000000..6b817075f --- /dev/null +++ b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOCloudConfiguration.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * mso + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= + */ + +package org.onap.policy.so; + +import java.io.Serializable; + + +import com.google.gson.annotations.SerializedName; + +public class SOCloudConfiguration implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -3283942659786236032L; + + @SerializedName("lcpCloudRegionId") + public String lcpCloudRegionId; + + @SerializedName("tenantId") + public String tenantId; + + public SOCloudConfiguration() { + } + +} diff --git a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOInstanceReferences.java b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOInstanceReferences.java new file mode 100644 index 000000000..97abd3950 --- /dev/null +++ b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOInstanceReferences.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * mso + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= + */ + +package org.onap.policy.so; + +import java.io.Serializable; + + +import com.google.gson.annotations.SerializedName; + +public class SOInstanceReferences implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -3283942659786236032L; + + @SerializedName("requestId") + public String requestId; + + @SerializedName("instanceId") + public String instanceId; + + public SOInstanceReferences() { + } + +} diff --git a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOManager.java b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOManager.java new file mode 100644 index 000000000..86ade6db7 --- /dev/null +++ b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOManager.java @@ -0,0 +1,168 @@ +/*- + * ============LICENSE_START======================================================= + * mso + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= + */ + +package org.onap.policy.so; + +import java.util.Base64; +import java.util.HashMap; +import java.util.Map; + +import org.onap.policy.so.util.Serialization; +import org.onap.policy.rest.RESTManager; +import org.onap.policy.rest.RESTManager.Pair; +import org.drools.core.WorkingMemory; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonSyntaxException; + +public final class SOManager { + + private static final Logger logger = LoggerFactory.getLogger(SOManager.class); + private static ExecutorService executors = Executors.newCachedThreadPool(); + + public static SOResponse createModuleInstance(String url, String urlBase, String username, String password, SORequest request) { + + // + // Call REST + // + Map headers = new HashMap(); + //headers.put("X-FromAppId", "POLICY"); + //headers.put("X-TransactionId", requestID.toString()); + headers.put("Accept", "application/json"); + + // + // 201 - CREATED - you are done just return + // + + Pair httpDetails = RESTManager.post(url, username, password, headers, "application/json", Serialization.gsonPretty.toJson(request)); + + if (httpDetails == null) { + return null; + } + + if (httpDetails.a == 202) { + try { + SOResponse response = Serialization.gsonPretty.fromJson(httpDetails.b, SOResponse.class); + + String body = Serialization.gsonPretty.toJson(response); + logger.debug("***** Response to post:"); + logger.debug(body); + + String requestId = response.requestReferences.requestId; + int attemptsLeft = 20; + + //String getUrl = "/orchestrationRequests/v2/"+requestId; + String urlGet = urlBase + "/orchestrationRequests/v2/"+requestId; + SOResponse responseGet = null; + + while(attemptsLeft-- > 0){ + + Pair httpDetailsGet = RESTManager.get(urlGet, username, password, headers); + responseGet = Serialization.gsonPretty.fromJson(httpDetailsGet.b, SOResponse.class); + body = Serialization.gsonPretty.toJson(responseGet); + logger.debug("***** Response to get:"); + logger.debug(body); + + if(httpDetailsGet.a == 200){ + if(responseGet.request.requestStatus.requestState.equalsIgnoreCase("COMPLETE") || + responseGet.request.requestStatus.requestState.equalsIgnoreCase("FAILED")){ + logger.debug("***** ######## VF Module Creation "+responseGet.request.requestStatus.requestState); + return responseGet; + } + } + Thread.sleep(20000); + } + + if (responseGet != null + && responseGet.request != null + && responseGet.request.requestStatus != null + && responseGet.request.requestStatus.requestState != null) { + logger.warn("***** ######## VF Module Creation timeout. Status: ( {})", responseGet.request.requestStatus.requestState); + } + + return responseGet; + } catch (JsonSyntaxException e) { + logger.error("Failed to deserialize into SOResponse: ", e); + } catch (InterruptedException e) { + logger.error("Interrupted exception: ", e); + } + } + + + + + return null; + } + + /** + * + * @param wm + * @param url + * @param urlBase + * @param username + * @param password + * @param request + * + * This method makes an asynchronous Rest call to MSO and inserts the response into the Drools working memory + */ + public void asyncSORestCall(WorkingMemory wm, String serviceInstanceId, String vnfInstanceId, SORequest request) { + executors.submit(new Runnable() + { + @Override + public void run() + { + String serverRoot = "http://localhost:6667"; // TODO + String username = "username"; // TODO + String password = "password"; // TODO + String url = serverRoot + "/serviceInstances/v2/" + serviceInstanceId + "/vnfs/" + vnfInstanceId + "/vfModulesHTTPS/1.1"; + + String auth = username + ":" + password; + + Map headers = new HashMap(); + byte[] encodedBytes = Base64.getEncoder().encode(auth.getBytes()); + headers.put("Accept", "application/json"); + headers.put("Authorization", "Basic " + new String(encodedBytes)); + + Gson gsonPretty = new GsonBuilder().disableHtmlEscaping() + .setPrettyPrinting() + .create(); + + String msoJson = gsonPretty.toJson(request); + + SOResponse mso = new SOResponse(); + Pair httpResponse = RESTManager.post(url, "policy", "policy", headers, "application/json", msoJson); + if (httpResponse != null) { + Gson gson = new Gson(); + mso = gson.fromJson(httpResponse.b, SOResponse.class); + mso.httpResponseCode = httpResponse.a; + } + + wm.insert(mso); + logger.info("SOResponse inserted " + gsonPretty.toJson(mso)); + } + }); + } + +} diff --git a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOModelInfo.java b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOModelInfo.java new file mode 100644 index 000000000..94070ba9a --- /dev/null +++ b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOModelInfo.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * mso + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= + */ + +package org.onap.policy.so; + +import java.io.Serializable; + + +import com.google.gson.annotations.SerializedName; + +public class SOModelInfo implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -3283942659786236032L; + + @SerializedName("modelType") + public String modelType; + + @SerializedName("modelInvariantId") + public String modelInvariantId; + + @SerializedName("modelNameVersionId") + public String modelNameVersionId; + + @SerializedName("modelName") + public String modelName; + + @SerializedName("modelVersion") + public String modelVersion; + + @SerializedName("modelCustomizationName") + public String modelCustomizationName; + + @SerializedName("modelCustomizationId") + public String modelCustomizationId; + + public SOModelInfo() { + } + +} diff --git a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOPolicyException.java b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOPolicyException.java new file mode 100644 index 000000000..150733963 --- /dev/null +++ b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOPolicyException.java @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * mso + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= + */ + +package org.onap.policy.so; + +import java.io.Serializable; + +import com.google.gson.annotations.SerializedName; + +public class SOPolicyException implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -3283942659786236032L; + + @SerializedName("messageId") + public String messageId; + + @SerializedName("text") + public String text; + + public SOPolicyException() { + } + +} diff --git a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORelatedInstance.java b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORelatedInstance.java new file mode 100644 index 000000000..ac737307c --- /dev/null +++ b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORelatedInstance.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * mso + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= + */ + +package org.onap.policy.so; + +import java.io.Serializable; + + + +import com.google.gson.annotations.SerializedName; + +public class SORelatedInstance implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -3283942659786236032L; + + @SerializedName("instanceId") + public String instanceId; + + @SerializedName("instanceName") + public String instanceName; + + @SerializedName("modelInfo") + public SOModelInfo modelInfo; + + + public SORelatedInstance() { + } + +} diff --git a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORelatedInstanceListElement.java b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORelatedInstanceListElement.java new file mode 100644 index 000000000..c4b85ab52 --- /dev/null +++ b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORelatedInstanceListElement.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * mso + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= + */ + +package org.onap.policy.so; + +import java.io.Serializable; + + +import com.google.gson.annotations.SerializedName; + +public class SORelatedInstanceListElement implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -3283942659786236032L; + + @SerializedName("relatedInstance") + public SORelatedInstance relatedInstance; + + + public SORelatedInstanceListElement() { + } + +} diff --git a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequest.java b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequest.java new file mode 100644 index 000000000..3e90ff345 --- /dev/null +++ b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequest.java @@ -0,0 +1,61 @@ +/*- + * ============LICENSE_START======================================================= + * mso + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= + */ + +package org.onap.policy.so; + +import java.io.Serializable; +import java.time.LocalDateTime; +import java.util.UUID; + +import com.google.gson.annotations.SerializedName; + +public class SORequest implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -3283942659786236032L; + + @SerializedName("requestId") + public UUID requestId; + + @SerializedName("startTime") + //public LocalDateTime startTime; + public String startTime; + + @SerializedName("finishTime") + public LocalDateTime finishTime; + + @SerializedName("requestScope") + public String requestScope; + + @SerializedName("requestType") + public String requestType; + + @SerializedName("requestDetails") + public SORequestDetails requestDetails; + + @SerializedName("requestStatus") + public SORequestStatus requestStatus; + + public SORequest() { + } + +} diff --git a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestDetails.java b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestDetails.java new file mode 100644 index 000000000..ab4afc16c --- /dev/null +++ b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestDetails.java @@ -0,0 +1,124 @@ +/*- + * ============LICENSE_START======================================================= + * mso + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= + */ + +package org.onap.policy.so; + +import java.io.Serializable; +import java.util.LinkedList; +import java.util.List; + +import com.google.gson.annotations.SerializedName; + +public class SORequestDetails implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -3283942659786236032L; + + @SerializedName("modelInfo") + public SOModelInfo modelInfo; + + @SerializedName("cloudConfiguration") + public SOCloudConfiguration cloudConfiguration; + + @SerializedName("requestInfo") + public SORequestInfo requestInfo; + + @SerializedName("subscriberInfo") + public SOSubscriberInfo subscriberInfo; + + @SerializedName("relatedInstanceList") + public List relatedInstanceList= new LinkedList(); + + @SerializedName("requestParameters") + public SORequestParameters requestParameters; + + public SORequestDetails() { + + } + + public SORequestDetails(SORequestDetails soRequestDetails) { + this.modelInfo = soRequestDetails.modelInfo; + this.cloudConfiguration = soRequestDetails.cloudConfiguration; + this.requestInfo = soRequestDetails.requestInfo; + this.relatedInstanceList = soRequestDetails.relatedInstanceList; + this.requestParameters = soRequestDetails.requestParameters; + } + + @Override + public String toString() { + return "SORequestDetails [modelInfo=" + modelInfo + + ", cloudConfiguration=" + cloudConfiguration + + ", requestInfo=" + requestInfo + ", relatedInstanceList=" + + relatedInstanceList + ", requestParameters=" + + requestParameters + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((cloudConfiguration == null) ? 0 : cloudConfiguration.hashCode()); + result = prime * result + ((modelInfo == null) ? 0 : modelInfo.hashCode()); + result = prime * result + ((relatedInstanceList == null) ? 0 : relatedInstanceList.hashCode()); + result = prime * result + ((requestInfo == null) ? 0 : requestInfo.hashCode()); + result = prime * result + ((requestParameters == null) ? 0 : requestParameters.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + SORequestDetails other = (SORequestDetails) obj; + if (cloudConfiguration == null) { + if (other.cloudConfiguration != null) + return false; + } else if (!cloudConfiguration.equals(other.cloudConfiguration)) + return false; + if (modelInfo == null) { + if (other.modelInfo != null) + return false; + } else if (!modelInfo.equals(other.modelInfo)) + return false; + if (relatedInstanceList == null) { + if (other.relatedInstanceList != null) + return false; + } else if (!relatedInstanceList.equals(other.relatedInstanceList)) + return false; + if (requestInfo == null) { + if (other.requestInfo != null) + return false; + } else if (!requestInfo.equals(other.requestInfo)) + return false; + if (requestParameters == null) { + if (other.requestParameters != null) + return false; + } else if (!requestParameters.equals(other.requestParameters)) + return false; + return true; + } + +} diff --git a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestError.java b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestError.java new file mode 100644 index 000000000..d49897c72 --- /dev/null +++ b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestError.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * mso + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= + */ + +package org.onap.policy.so; + +import java.io.Serializable; + +import com.google.gson.annotations.SerializedName; + +public class SORequestError implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -3283942659786236032L; + + + @SerializedName("policyException") + public SOPolicyException policyException; + + + @SerializedName("serviceException") + public SOServiceException serviceException; + + /* + @SerializedName("messageId") + public String messageId; + + @SerializedName("text") + public String text; + + @SerializedName("url") + public String url; + + @SerializedName("variables") + public String variables; + */ + + public SORequestError() { + } + +} diff --git a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestInfo.java b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestInfo.java new file mode 100644 index 000000000..640649800 --- /dev/null +++ b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestInfo.java @@ -0,0 +1,66 @@ +/*- + * ============LICENSE_START======================================================= + * mso + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= + */ + +package org.onap.policy.so; + +import java.io.Serializable; + + +import com.google.gson.annotations.SerializedName; + +public class SORequestInfo implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -3283942659786236032L; + + @SerializedName("instanceName") + public String instanceName; + + @SerializedName("source") + public String source; + + @SerializedName("productFamilyId") + public String productFamilyId; + + @SerializedName("suppressRollback") + public boolean suppressRollback; + + @SerializedName("billingAccountNumber") + public String billingAccountNumber; + + @SerializedName("callbackUrl") + public String callbackUrl; + + @SerializedName("correlator") + public String correlator; + + @SerializedName("orderNumber") + public String orderNumber; + + @SerializedName("orderVersion") + public Integer orderVersion; + + + public SORequestInfo() { + } + +} diff --git a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestParameters.java b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestParameters.java new file mode 100644 index 000000000..c66f0979c --- /dev/null +++ b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestParameters.java @@ -0,0 +1,47 @@ +/*- + * ============LICENSE_START======================================================= + * mso + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= + */ + +package org.onap.policy.so; + +import java.io.Serializable; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + + +import com.google.gson.annotations.SerializedName; + +public class SORequestParameters implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -3283942659786236032L; + + @SerializedName("subscriptionServiceType") + public String subscriptionServiceType; + + @SerializedName("userParams") + public List> userParams = new LinkedList>(); + + public SORequestParameters() { + } + +} diff --git a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestReferences.java b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestReferences.java new file mode 100644 index 000000000..f3e15e1d7 --- /dev/null +++ b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestReferences.java @@ -0,0 +1,38 @@ +/*- + * ============LICENSE_START======================================================= + * mso + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= + */ + +package org.onap.policy.so; + +import java.io.Serializable; + + +import com.google.gson.annotations.SerializedName; + +public class SORequestReferences implements Serializable { + + private static final long serialVersionUID = -3283942659786236032L; + + @SerializedName("instanceId") + public String instanceId; + + @SerializedName("requestId") + public String requestId; + +} diff --git a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestStatus.java b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestStatus.java new file mode 100644 index 000000000..4b57fc7ba --- /dev/null +++ b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestStatus.java @@ -0,0 +1,51 @@ +/*- + * ============LICENSE_START======================================================= + * mso + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= + */ + +package org.onap.policy.so; + +import java.io.Serializable; + +import com.google.gson.annotations.SerializedName; + +public class SORequestStatus implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -3283942659786236032L; + + @SerializedName("percentProgress") + public int percentProgress; + + @SerializedName("requestState") + public String requestState; + + @SerializedName("timestamp") + //public LocalDateTime timestamp; + public String timestamp; + + @SerializedName("wasRolledBack") + public boolean wasRolledBack; + + + public SORequestStatus() { + } + +} diff --git a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOResponse.java b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOResponse.java new file mode 100644 index 000000000..c5c3737b2 --- /dev/null +++ b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOResponse.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * mso + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= + */ + +package org.onap.policy.so; + +import java.io.Serializable; + +import com.google.gson.annotations.SerializedName; + +public class SOResponse implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -3283942659786236032L; + + @SerializedName("requestReferences") + public SORequestReferences requestReferences; + + @SerializedName("requestError") + public SORequestError requestError; + + @SerializedName("request") + public SORequest request; + + public int httpResponseCode; + + + public SOResponse() { + } + +} diff --git a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOServiceException.java b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOServiceException.java new file mode 100644 index 000000000..58999fd30 --- /dev/null +++ b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOServiceException.java @@ -0,0 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * mso + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= + */ + +package org.onap.policy.so; + +import java.io.Serializable; +import java.util.LinkedList; +import java.util.List; + +import com.google.gson.annotations.SerializedName; + +public class SOServiceException implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -3283942659786236032L; + + @SerializedName("messageId") + public String messageId; + + @SerializedName("text") + public String text; + + @SerializedName("variables") + public List variables = new LinkedList(); + + public SOServiceException() { + } + +} diff --git a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOSubscriberInfo.java b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOSubscriberInfo.java new file mode 100644 index 000000000..745e237fe --- /dev/null +++ b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOSubscriberInfo.java @@ -0,0 +1,47 @@ +/*- + * ============LICENSE_START======================================================= + * mso + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= + */ + +package org.onap.policy.so; + +import java.io.Serializable; + + +import com.google.gson.annotations.SerializedName; + +public class SOSubscriberInfo implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -3283942659786236032L; + + @SerializedName("globalSubscriberId") + public String globalSubscriberId; + + @SerializedName("subscriberCommonSiteId") + public String subscriberCommonSiteId; + + @SerializedName("subscriberName") + public String subscriberName; + + public SOSubscriberInfo() { + } + +} diff --git a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/util/Serialization.java b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/util/Serialization.java new file mode 100644 index 000000000..c9d013ea6 --- /dev/null +++ b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/util/Serialization.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * mso + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= + */ + +package org.onap.policy.so.util; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +public final class Serialization { + + final static public Gson gsonPretty = new GsonBuilder().disableHtmlEscaping() + .setPrettyPrinting() + .create(); + +} diff --git a/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestDemo.java b/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestDemo.java new file mode 100644 index 000000000..af8f4be0e --- /dev/null +++ b/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestDemo.java @@ -0,0 +1,167 @@ +/*- + * ============LICENSE_START======================================================= + * mso + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= + */ + +package org.onap.policy.so; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; +import org.onap.policy.so.SOCloudConfiguration; +import org.onap.policy.so.SOModelInfo; +import org.onap.policy.so.SORelatedInstance; +import org.onap.policy.so.SORelatedInstanceListElement; +import org.onap.policy.so.SORequest; +import org.onap.policy.so.SORequestDetails; +import org.onap.policy.so.SORequestInfo; +import org.onap.policy.so.SORequestParameters; +import org.onap.policy.so.util.Serialization; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class TestDemo { + private static final Logger logger = LoggerFactory.getLogger(TestDemo.class); + @Test + public void test() { + + SORequest request = new SORequest(); + request.requestDetails = new SORequestDetails(); + request.requestDetails.modelInfo = new SOModelInfo(); + request.requestDetails.cloudConfiguration = new SOCloudConfiguration(); + request.requestDetails.requestInfo = new SORequestInfo(); + request.requestDetails.requestParameters = new SORequestParameters(); + + request.requestDetails.modelInfo.modelType = "vfModule"; + request.requestDetails.modelInfo.modelInvariantId = "ff5256d2-5a33-55df-13ab-12abad84e7ff"; + request.requestDetails.modelInfo.modelNameVersionId = "fe6478e5-ea33-3346-ac12-ab121484a3fe"; + request.requestDetails.modelInfo.modelName = "vSAMP12..base..module-0"; + request.requestDetails.modelInfo.modelVersion = "1"; + + request.requestDetails.cloudConfiguration.lcpCloudRegionId = "mdt1"; + request.requestDetails.cloudConfiguration.tenantId = "88a6ca3ee0394ade9403f075db23167e"; + + request.requestDetails.requestInfo.instanceName = "SOTEST103a-vSAMP12_base_module-0"; + request.requestDetails.requestInfo.source = "VID"; + request.requestDetails.requestInfo.suppressRollback = true; + + SORelatedInstanceListElement relatedInstanceListElement1 = new SORelatedInstanceListElement(); + SORelatedInstanceListElement relatedInstanceListElement2 = new SORelatedInstanceListElement(); + SORelatedInstanceListElement relatedInstanceListElement3 = new SORelatedInstanceListElement(); + relatedInstanceListElement1.relatedInstance = new SORelatedInstance(); + relatedInstanceListElement2.relatedInstance = new SORelatedInstance(); + relatedInstanceListElement3.relatedInstance = new SORelatedInstance(); + + relatedInstanceListElement1.relatedInstance.instanceId = "17ef4658-bd1f-4ef0-9ca0-ea76e2bf122c"; + relatedInstanceListElement1.relatedInstance.instanceName = "SOTESTVOL103a-vSAMP12_base_module-0_vol"; + relatedInstanceListElement1.relatedInstance.modelInfo = new SOModelInfo(); + relatedInstanceListElement1.relatedInstance.modelInfo.modelType = "volumeGroup"; + + relatedInstanceListElement2.relatedInstance.instanceId = "serviceInstanceId"; + relatedInstanceListElement2.relatedInstance.modelInfo = new SOModelInfo(); + relatedInstanceListElement2.relatedInstance.modelInfo.modelType = "service"; + relatedInstanceListElement2.relatedInstance.modelInfo.modelInvariantId = "ff3514e3-5a33-55df-13ab-12abad84e7ff"; + relatedInstanceListElement2.relatedInstance.modelInfo.modelNameVersionId = "fe6985cd-ea33-3346-ac12-ab121484a3fe"; + relatedInstanceListElement2.relatedInstance.modelInfo.modelName = "parent service model name"; + relatedInstanceListElement2.relatedInstance.modelInfo.modelVersion = "1.0"; + + relatedInstanceListElement3.relatedInstance.instanceId = "vnfInstanceId"; + relatedInstanceListElement3.relatedInstance.modelInfo = new SOModelInfo(); + relatedInstanceListElement3.relatedInstance.modelInfo.modelType = "vnf"; + relatedInstanceListElement3.relatedInstance.modelInfo.modelInvariantId = "ff5256d1-5a33-55df-13ab-12abad84e7ff"; + relatedInstanceListElement3.relatedInstance.modelInfo.modelNameVersionId = "fe6478e4-ea33-3346-ac12-ab121484a3fe"; + relatedInstanceListElement3.relatedInstance.modelInfo.modelName = "vSAMP12"; + relatedInstanceListElement3.relatedInstance.modelInfo.modelVersion = "1.0"; + relatedInstanceListElement3.relatedInstance.modelInfo.modelCustomizationName = "vSAMP12 1"; + + request.requestDetails.relatedInstanceList.add(relatedInstanceListElement1); + request.requestDetails.relatedInstanceList.add(relatedInstanceListElement2); + request.requestDetails.relatedInstanceList.add(relatedInstanceListElement3); + + Map userParam1 = new HashMap<>(); + userParam1.put("name1", "value1"); + + Map userParam2 = new HashMap<>(); + userParam2.put("name2", "value2"); + + request.requestDetails.requestParameters.userParams.add(userParam1); + request.requestDetails.requestParameters.userParams.add(userParam2); + + logger.debug(Serialization.gsonPretty.toJson(request)); + + } + + @Test + public void testHack() { + + logger.debug("** HACK **"); + + SORequest request = new SORequest(); + // + request.requestDetails = new SORequestDetails(); + request.requestDetails.modelInfo = new SOModelInfo(); + request.requestDetails.cloudConfiguration = new SOCloudConfiguration(); + request.requestDetails.requestInfo = new SORequestInfo(); + request.requestDetails.requestParameters = new SORequestParameters(); + request.requestDetails.requestParameters.userParams = null; + + request.requestDetails.modelInfo.modelType = "vfModule"; + request.requestDetails.modelInfo.modelInvariantId = "a9c4a35a-de48-451a-9e4e-343f2ac52928"; + request.requestDetails.modelInfo.modelNameVersionId = "e0d98ad1-238d-4555-b439-023d3f9079f6"; + request.requestDetails.modelInfo.modelName = "0d9e0d9d352749f4B3cb..dnsscaling..module-0"; + request.requestDetails.modelInfo.modelVersion = "2.0"; + + request.requestDetails.cloudConfiguration.lcpCloudRegionId = "DFW"; + request.requestDetails.cloudConfiguration.tenantId = "1015548"; + + request.requestDetails.requestInfo.instanceName = "Vfmodule_Ete_Name1eScaling63928f-ccdc-4b34-bdef-9bf64109026e"; + request.requestDetails.requestInfo.source = "POLICY"; + request.requestDetails.requestInfo.suppressRollback = false; + + SORelatedInstanceListElement relatedInstanceListElement1 = new SORelatedInstanceListElement(); + SORelatedInstanceListElement relatedInstanceListElement2 = new SORelatedInstanceListElement(); + relatedInstanceListElement1.relatedInstance = new SORelatedInstance(); + relatedInstanceListElement2.relatedInstance = new SORelatedInstance(); + + String serviceInstanceId = "98af39ce-6408-466b-921f-c2c7a8f59ed6"; + relatedInstanceListElement1.relatedInstance.instanceId = serviceInstanceId; + relatedInstanceListElement1.relatedInstance.modelInfo = new SOModelInfo(); + relatedInstanceListElement1.relatedInstance.modelInfo.modelType = "service"; + relatedInstanceListElement1.relatedInstance.modelInfo.modelInvariantId = "24329a0c-1d57-4210-b1af-a65df64e9d59"; + relatedInstanceListElement1.relatedInstance.modelInfo.modelNameVersionId = "ac642881-8e7e-4217-bd64-16ad41c42e30"; + relatedInstanceListElement1.relatedInstance.modelInfo.modelName = "5116d67e-0b4f-46bf-a46f"; + relatedInstanceListElement1.relatedInstance.modelInfo.modelVersion = "2.0"; + + String vnfInstanceId = "8eb411b8-a936-412f-b01f-9a9a435c0e93"; + relatedInstanceListElement2.relatedInstance.instanceId = vnfInstanceId; + relatedInstanceListElement2.relatedInstance.modelInfo = new SOModelInfo(); + relatedInstanceListElement2.relatedInstance.modelInfo.modelType = "vnf"; + relatedInstanceListElement2.relatedInstance.modelInfo.modelInvariantId = "09fd971e-db5f-475d-997c-cf6704b6b8fe"; + relatedInstanceListElement2.relatedInstance.modelInfo.modelNameVersionId = "152ed917-6dcc-46ee-bf8a-a775c5aa5a74"; + relatedInstanceListElement2.relatedInstance.modelInfo.modelName = "9e4c31d2-4b25-4d9e-9fb4"; + relatedInstanceListElement2.relatedInstance.modelInfo.modelVersion = "2.0"; + relatedInstanceListElement2.relatedInstance.modelInfo.modelCustomizationName = "0d9e0d9d-3527-49f4-b3cb 2"; + + request.requestDetails.relatedInstanceList.add(relatedInstanceListElement1); + request.requestDetails.relatedInstanceList.add(relatedInstanceListElement2); + + logger.debug(Serialization.gsonPretty.toJson(request)); + } + +} diff --git a/controlloop/common/simulators/pom.xml b/controlloop/common/simulators/pom.xml index 9d3b71c0d..26a81a8ff 100644 --- a/controlloop/common/simulators/pom.xml +++ b/controlloop/common/simulators/pom.xml @@ -47,10 +47,17 @@ org.onap.policy.drools-applications - mso + so ${project.version} test + + org.onap.policy.drools-applications + so + 1.1.0-SNAPSHOT + provided + + org.onap.policy.drools-applications vfc diff --git a/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/MsoSimulatorJaxRs.java b/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/MsoSimulatorJaxRs.java deleted file mode 100644 index 824c547ce..000000000 --- a/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/MsoSimulatorJaxRs.java +++ /dev/null @@ -1,37 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * simulators - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= - */ - -package org.onap.policy.simulators; - -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; - -@Path("/serviceInstances") -public class MsoSimulatorJaxRs { - - @POST - @Path("/v2/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModulesHTTPS/1.1") - public String msoPostQuery(@PathParam("serviceInstanceId") String serviceInstanceId, @PathParam("vnfInstanceId") String vnfInstanceId) - { - return "{\"requestReferences\": {\"instanceId\": \"ff305d54-75b4-ff1b-bdb2-eb6b9e5460ff\", \"requestId\": \"rq1234d1-5a33-ffdf-23ab-12abad84e331\"}}"; - } - -} diff --git a/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/SoSimulatorJaxRs.java b/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/SoSimulatorJaxRs.java new file mode 100644 index 000000000..1ebb281fd --- /dev/null +++ b/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/SoSimulatorJaxRs.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * simulators + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= + */ + +package org.onap.policy.simulators; + +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.MediaType; + +import org.onap.policy.so.SORequest; +import org.onap.policy.so.util.Serialization; + +@Path("/serviceInstances") +public class SoSimulatorJaxRs { + + @POST + @Path("/v2/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModulesHTTPS/1.1") + @Consumes(MediaType.APPLICATION_JSON) + public String SoPostQuery(@PathParam("serviceInstanceId") String serviceInstanceId, @PathParam("vnfInstanceId") String vnfInstanceId, String req) + { + SORequest request = Serialization.gsonPretty.fromJson(req, SORequest.class); + return "{\"requestReferences\": {\"instanceId\": \"ff305d54-75b4-ff1b-bdb2-eb6b9e5460ff\", \"requestId\": " + request.requestId + "}}"; + } + +} diff --git a/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/Util.java b/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/Util.java index 27cc6e0fa..e0eb1ff01 100644 --- a/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/Util.java +++ b/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/Util.java @@ -22,7 +22,7 @@ package org.onap.policy.simulators; import org.onap.policy.drools.http.server.HttpServletServer; import org.onap.policy.simulators.AaiSimulatorJaxRs; -import org.onap.policy.simulators.MsoSimulatorJaxRs; +import org.onap.policy.simulators.SoSimulatorJaxRs; import org.onap.policy.simulators.VfcSimulatorJaxRs; public class Util { @@ -33,9 +33,9 @@ public class Util { return testServer; } - public static HttpServletServer buildMsoSim() throws InterruptedException { + public static HttpServletServer buildSoSim() throws InterruptedException { HttpServletServer testServer = HttpServletServer.factory.build("testServer", "localhost", 6667, "/", false, true); - testServer.addServletClass("/*", MsoSimulatorJaxRs.class.getName()); + testServer.addServletClass("/*", SoSimulatorJaxRs.class.getName()); testServer.waitedStart(5000); return testServer; } diff --git a/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/MsoSimulatorTest.java b/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/MsoSimulatorTest.java deleted file mode 100644 index 917288ed5..000000000 --- a/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/MsoSimulatorTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * simulators - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= - */ - -package org.onap.policy.simulators; - -import static org.junit.Assert.*; - -import java.util.HashMap; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.onap.policy.drools.http.server.HttpServletServer; -import org.onap.policy.mso.SOResponse; -import org.onap.policy.mso.util.Serialization; -import org.onap.policy.rest.RESTManager; -import org.onap.policy.rest.RESTManager.Pair; - -public class MsoSimulatorTest { - - @BeforeClass - public static void setUpSimulator() { - try { - Util.buildMsoSim(); - } catch (InterruptedException e) { - fail(e.getMessage()); - } - } - - @AfterClass - public static void tearDownSimulator() { - HttpServletServer.factory.destroy(); - } - - @Test - public void testResponse(){ - Pair httpDetails = RESTManager.post("http://localhost:6667/serviceInstances/v2/12345/vnfs/12345/vfModulesHTTPS/1.1", "username", "password", new HashMap(), "application/json", "Some Request Here"); - assertNotNull(httpDetails); - SOResponse response = Serialization.gsonPretty.fromJson(httpDetails.b, SOResponse.class); - assertNotNull(response); - } -} diff --git a/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/SoSimulatorTest.java b/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/SoSimulatorTest.java new file mode 100644 index 000000000..0a7cd4168 --- /dev/null +++ b/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/SoSimulatorTest.java @@ -0,0 +1,133 @@ +/*- + * ============LICENSE_START======================================================= + * simulators + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= + */ + +package org.onap.policy.simulators; + +import static org.junit.Assert.*; + +import java.util.HashMap; +import java.util.UUID; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.policy.drools.http.server.HttpServletServer; +import org.onap.policy.so.SOCloudConfiguration; +import org.onap.policy.so.SOModelInfo; +import org.onap.policy.so.SORelatedInstance; +import org.onap.policy.so.SORelatedInstanceListElement; +import org.onap.policy.so.SORequest; +import org.onap.policy.so.SORequestDetails; +import org.onap.policy.so.SORequestInfo; +import org.onap.policy.so.SORequestParameters; +import org.onap.policy.so.SOResponse; +import org.onap.policy.so.util.Serialization; +import org.onap.policy.rest.RESTManager; +import org.onap.policy.rest.RESTManager.Pair; + +public class SoSimulatorTest { + + @BeforeClass + public static void setUpSimulator() { + try { + Util.buildSoSim(); + } catch (InterruptedException e) { + fail(e.getMessage()); + } + } + + @AfterClass + public static void tearDownSimulator() { + HttpServletServer.factory.destroy(); + } + + /** + * Create dummy SO request for TestResponse() junit + */ + private SORequest createTestRequest() { + + // Construct SO Request + SORequest request = new SORequest(); + request.requestId = UUID.randomUUID(); + request.requestDetails = new SORequestDetails(); + request.requestDetails.modelInfo = new SOModelInfo(); + request.requestDetails.cloudConfiguration = new SOCloudConfiguration(); + request.requestDetails.requestInfo = new SORequestInfo(); + request.requestDetails.requestParameters = new SORequestParameters(); + request.requestDetails.requestParameters.userParams = null; + // + // cloudConfiguration + // + request.requestDetails.cloudConfiguration.lcpCloudRegionId = "DFW"; + request.requestDetails.cloudConfiguration.tenantId = "1015548"; + // + // modelInfo + // + request.requestDetails.modelInfo.modelType = "vfModule"; + request.requestDetails.modelInfo.modelInvariantId = "f32568ec-2f1c-458a-864b-0593d53d141a"; + request.requestDetails.modelInfo.modelNameVersionId = "69615025-879d-4f0d-afe3-b7d1a7eeed1f"; + request.requestDetails.modelInfo.modelName = "C15ce9e1E9144c8fB8bb..dnsscaling..module-1"; + request.requestDetails.modelInfo.modelVersion = "1.0"; + // + // requestInfo + // + request.requestDetails.requestInfo.instanceName = "vDNS_Ete_Named90e1ab3-dcd5-4877-9edb-eadfc84e32c8"; + request.requestDetails.requestInfo.source = "POLICY"; + request.requestDetails.requestInfo.suppressRollback = false; + // + // relatedInstanceList + // + SORelatedInstanceListElement relatedInstanceListElement1 = new SORelatedInstanceListElement(); + SORelatedInstanceListElement relatedInstanceListElement2 = new SORelatedInstanceListElement(); + relatedInstanceListElement1.relatedInstance = new SORelatedInstance(); + relatedInstanceListElement2.relatedInstance = new SORelatedInstance(); + // + relatedInstanceListElement1.relatedInstance.instanceId = "cf8426a6-0b53-4e3d-bfa6-4b2f4d5913a5"; + relatedInstanceListElement1.relatedInstance.modelInfo = new SOModelInfo(); + relatedInstanceListElement1.relatedInstance.modelInfo.modelType = "service"; + relatedInstanceListElement1.relatedInstance.modelInfo.modelInvariantId = "4fcbc1c0-7793-46d8-8aa1-fa1c2ed9ec7b"; + relatedInstanceListElement1.relatedInstance.modelInfo.modelNameVersionId = "5c996219-b2e2-4c76-9b43-7e8672a33c1d"; + relatedInstanceListElement1.relatedInstance.modelInfo.modelName = "8330e932-2a23-4943-8606"; + relatedInstanceListElement1.relatedInstance.modelInfo.modelVersion = "1.0"; + // + relatedInstanceListElement2.relatedInstance.instanceId = "594e2fe0-48b8-41ff-82e2-3d4bab69b192"; + relatedInstanceListElement2.relatedInstance.modelInfo = new SOModelInfo(); + relatedInstanceListElement2.relatedInstance.modelInfo.modelType = "vnf"; + relatedInstanceListElement2.relatedInstance.modelInfo.modelInvariantId = "033a32ed-aa65-4764-a736-36f2942f1aa0"; + relatedInstanceListElement2.relatedInstance.modelInfo.modelNameVersionId = "d4d072dc-4e21-4a03-9524-628985819a8e"; + relatedInstanceListElement2.relatedInstance.modelInfo.modelName = "c15ce9e1-e914-4c8f-b8bb"; + relatedInstanceListElement2.relatedInstance.modelInfo.modelVersion = "1"; + relatedInstanceListElement2.relatedInstance.modelInfo.modelCustomizationName = "c15ce9e1-e914-4c8f-b8bb 1"; + // + request.requestDetails.relatedInstanceList.add(relatedInstanceListElement1); + request.requestDetails.relatedInstanceList.add(relatedInstanceListElement2); + + return request; + } + + @Test + public void testResponse(){ + String request = Serialization.gsonPretty.toJson(createTestRequest()); + Pair httpDetails = RESTManager.post("http://localhost:6667/serviceInstances/v2/12345/vnfs/12345/vfModulesHTTPS/1.1", "username", "password", new HashMap<>(), "application/json", request); + assertNotNull(httpDetails); + SOResponse response = Serialization.gsonPretty.fromJson(httpDetails.b, SOResponse.class); + assertNotNull(response); + } +} diff --git a/controlloop/templates/template.demo.v1.0.0/template.demo/src/test/java/org/onap/policy/template/demo/TestFirewallDemo.java b/controlloop/templates/template.demo.v1.0.0/template.demo/src/test/java/org/onap/policy/template/demo/TestFirewallDemo.java index 825c69b50..5675b6bdf 100644 --- a/controlloop/templates/template.demo.v1.0.0/template.demo/src/test/java/org/onap/policy/template/demo/TestFirewallDemo.java +++ b/controlloop/templates/template.demo.v1.0.0/template.demo/src/test/java/org/onap/policy/template/demo/TestFirewallDemo.java @@ -144,7 +144,7 @@ public class TestFirewallDemo { // So no need to test it again here // try { - Thread.sleep(3000); + Thread.sleep(10000); } catch (InterruptedException e) { } // diff --git a/controlloop/templates/template.demo/pom.xml b/controlloop/templates/template.demo/pom.xml index e08174004..d3d3ef0ab 100644 --- a/controlloop/templates/template.demo/pom.xml +++ b/controlloop/templates/template.demo/pom.xml @@ -73,7 +73,7 @@ org.onap.policy.drools-applications - mso + so ${project.version} provided @@ -175,7 +175,7 @@ org.onap.policy.drools-applications - actor.mso + actor.so ${project.version} provided diff --git a/controlloop/templates/template.demo/src/main/resources/ControlLoop_Template_xacml_guard.drl b/controlloop/templates/template.demo/src/main/resources/ControlLoop_Template_xacml_guard.drl index f832ea5e2..82899f08b 100644 --- a/controlloop/templates/template.demo/src/main/resources/ControlLoop_Template_xacml_guard.drl +++ b/controlloop/templates/template.demo/src/main/resources/ControlLoop_Template_xacml_guard.drl @@ -39,18 +39,18 @@ import org.onap.policy.appclcm.LCMResponse; import org.onap.policy.appclcm.LCMCommonHeader; import org.onap.policy.vfc.VFCRequest; import org.onap.policy.vfc.VFCManager; -import org.onap.policy.mso.SOManager; -import org.onap.policy.mso.SORequest; -import org.onap.policy.mso.SORequestStatus; -import org.onap.policy.mso.SORequestDetails; -import org.onap.policy.mso.SOModelInfo; -import org.onap.policy.mso.SOCloudConfiguration; -import org.onap.policy.mso.SORequestInfo; -import org.onap.policy.mso.SORequestParameters; -import org.onap.policy.mso.SORelatedInstanceListElement; -import org.onap.policy.mso.SORelatedInstance; -import org.onap.policy.mso.SOResponse; -import org.onap.policy.controlloop.actor.mso.MSOActorServiceProvider; +import org.onap.policy.so.SOManager; +import org.onap.policy.so.SORequest; +import org.onap.policy.so.SORequestStatus; +import org.onap.policy.so.SORequestDetails; +import org.onap.policy.so.SOModelInfo; +import org.onap.policy.so.SOCloudConfiguration; +import org.onap.policy.so.SORequestInfo; +import org.onap.policy.so.SORequestParameters; +import org.onap.policy.so.SORelatedInstanceListElement; +import org.onap.policy.so.SORelatedInstance; +import org.onap.policy.so.SOResponse; +import org.onap.policy.controlloop.actor.so.SOActorServiceProvider; import org.onap.policy.guard.PolicyGuard; import org.onap.policy.guard.PolicyGuard.LockResult; import org.onap.policy.guard.TargetLock; @@ -517,7 +517,7 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED" if(request instanceof SORequest) { // Call SO. The response will be inserted into memory once it's received - MSOActorServiceProvider.sendRequest(drools.getWorkingMemory(), request); + SOActorServiceProvider.sendRequest(drools.getWorkingMemory(), request); } break; case "VFC": @@ -926,10 +926,8 @@ rule "${policyName}.SO.RESPONSE" $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.closedLoopControlName, onset.requestID == $event.requestID ) $opTimer : OperationTimer( closedLoopControlName == $event.closedLoopControlName, requestID == $event.requestID.toString() ) $lock : TargetLock (requestID == $event.requestID) - $request : SORequest( requestId == $event.requestID.toString() ) - $response : SOResponse( request.requestId == $event.requestID.toString() ) - then - + $response : SOResponse( requestReferences.requestId.toString() == $event.requestID.toString() ) + then // // Logging Logger.info("------------------------------------------------------------------------------------------------"); @@ -941,7 +939,6 @@ rule "${policyName}.SO.RESPONSE" Logger.metrics($opTimer); Logger.metrics($lock); Logger.metrics($response); - // Get the result of the operation // PolicyResult policyResult = $operation.onResponse($response); diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/TestSO.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/TestSO.java index b277b669e..16ad7a8b0 100644 --- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/TestSO.java +++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/TestSO.java @@ -38,7 +38,6 @@ import java.util.regex.Pattern; import org.junit.AfterClass; import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Test; import org.kie.api.KieServices; import org.kie.api.builder.KieBuilder; @@ -58,7 +57,7 @@ import org.onap.policy.controlloop.impl.ControlLoopLoggerStdOutImpl; import org.onap.policy.controlloop.policy.ControlLoopPolicy; import org.onap.policy.drools.http.server.HttpServletServer; import org.onap.policy.drools.impl.PolicyEngineJUnitImpl; -import org.onap.policy.mso.util.Serialization; +import org.onap.policy.so.util.Serialization; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -71,6 +70,7 @@ public class TestSO { public static void setUpSimulator() { try { Util.buildAaiSim(); + Util.buildSoSim(); } catch (InterruptedException e) { fail(e.getMessage()); } @@ -81,7 +81,6 @@ public class TestSO { HttpServletServer.factory.destroy(); } - @Ignore @Test public void testvDNS() throws IOException { @@ -192,7 +191,7 @@ public class TestSO { // So no need to test it again here // try { - Thread.sleep(3000); + Thread.sleep(10000); } catch (InterruptedException e) { } // diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/Util.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/Util.java index fb9f88f16..5a96e1667 100644 --- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/Util.java +++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/Util.java @@ -35,8 +35,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.commons.io.IOUtils; -import org.yaml.snakeyaml.Yaml; -import org.yaml.snakeyaml.constructor.Constructor; import org.kie.api.KieServices; import org.kie.api.builder.KieBuilder; import org.kie.api.builder.KieFileSystem; @@ -53,18 +51,16 @@ import org.onap.policy.controlloop.policy.guard.ControlLoopGuard; import org.onap.policy.drools.http.server.HttpServletServer; import org.onap.policy.drools.impl.PolicyEngineJUnitImpl; import org.onap.policy.guard.PolicyGuardYamlToXacml; -import org.onap.policy.simulators.AaiSimulatorJaxRs; -import org.onap.policy.simulators.MsoSimulatorJaxRs; -import org.onap.policy.simulators.VfcSimulatorJaxRs; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.constructor.Constructor; import com.att.research.xacml.api.pdp.PDPEngine; import com.att.research.xacml.api.pdp.PDPEngineFactory; import com.att.research.xacml.util.FactoryException; import com.att.research.xacml.util.XACMLProperties; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - public final class Util { private static final Logger logger = LoggerFactory.getLogger(Util.class); @@ -121,8 +117,8 @@ public final class Util { return org.onap.policy.simulators.Util.buildAaiSim(); } - public static HttpServletServer buildMsoSim() throws InterruptedException { - return org.onap.policy.simulators.Util.buildMsoSim(); + public static HttpServletServer buildSoSim() throws InterruptedException { + return org.onap.policy.simulators.Util.buildSoSim(); } public static HttpServletServer buildVfcSim() throws InterruptedException { diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VDNSControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VDNSControlLoopTest.java new file mode 100644 index 000000000..e107e2e7c --- /dev/null +++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VDNSControlLoopTest.java @@ -0,0 +1,304 @@ +/*- + * ============LICENSE_START======================================================= + * demo + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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========================================================= + */ + +package org.onap.policy.template.demo; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.IOException; +import java.net.URLEncoder; +import java.time.Instant; +import java.util.HashMap; +import java.util.UUID; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.kie.api.runtime.KieSession; +import org.kie.api.runtime.rule.FactHandle; +import org.onap.policy.controlloop.ControlLoopEventStatus; +import org.onap.policy.controlloop.ControlLoopNotificationType; +import org.onap.policy.controlloop.ControlLoopTargetType; +import org.onap.policy.controlloop.VirtualControlLoopEvent; +import org.onap.policy.controlloop.VirtualControlLoopNotification; +import org.onap.policy.controlloop.policy.ControlLoopPolicy; +import org.onap.policy.controlloop.policy.TargetType; +import org.onap.policy.drools.http.server.HttpServletServer; +import org.onap.policy.drools.impl.PolicyEngineJUnitImpl; +import org.onap.policy.guard.PolicyGuard; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class VDNSControlLoopTest { + + private static final Logger logger = LoggerFactory.getLogger(VDNSControlLoopTest.class); + + private KieSession kieSession; + private Util.Pair pair; + private PolicyEngineJUnitImpl engine; + + @BeforeClass + public static void setUpSimulator() { + try { + Util.buildAaiSim(); + Util.buildSoSim(); + } catch (InterruptedException e) { + fail(e.getMessage()); + } + } + + @AfterClass + public static void tearDownSimulator() { + HttpServletServer.factory.destroy(); + } + + @Test + public void successTest() { + + /* + * Start the kie session + */ + try { + kieSession = startSession("src/main/resources/ControlLoop_Template_xacml_guard.drl", + "src/test/resources/yaml/policy_ControlLoop_SO-test.yaml", + "type=operational", + "CL_vDNS", + "v2.0"); + } catch (IOException e) { + e.printStackTrace(); + logger.debug("Could not create kieSession"); + fail("Could not create kieSession"); + } + + /* + * Create a thread to continuously fire rules + * until main thread calls halt + */ + new Thread( new Runnable() { + @Override + public void run() { + kieSession.fireUntilHalt(); + } + } ).start(); + + /* + * Create a unique requestId and a unique trigger source + */ + UUID requestID = UUID.randomUUID(); + String triggerSourceName = "foobartriggersource36"; + + /* + * This will be the object returned from the PolicyEngine + */ + Object obj = null; + + /* + * Simulate an onset event the policy engine will + * receive from DCAE to kick off processing through + * the rules + */ + try { + sendOnset(pair.a, requestID, triggerSourceName); + } catch (InterruptedException e) { + e.printStackTrace(); + logger.debug("Unable to send onset event"); + fail("Unable to send onset event"); + } + + /* + * Pull the object that was sent out and make + * sure it is a ControlLoopNoticiation of type active + */ + obj = engine.subscribe("UEB", "POLICY-CL-MGT"); + assertNotNull(obj); + assertTrue(obj instanceof VirtualControlLoopNotification); + assertTrue(((VirtualControlLoopNotification)obj).notification.equals(ControlLoopNotificationType.ACTIVE)); + + + /* + * Give the control loop time to acquire a lock + */ + try { + Thread.sleep(4000); + } catch (InterruptedException e) { + e.printStackTrace(); + logger.debug("An interrupt Exception was thrown"); + fail("An interrupt Exception was thrown"); + } + + /* + * Give time to finish processing + */ + try { + Thread.sleep(10000); + } catch (InterruptedException e) { + e.printStackTrace(); + logger.debug("An interrupt Exception was thrown"); + fail("An interrupt Exception was thrown"); + } + + /* + * One final check to make sure the lock is released + */ + assertFalse(PolicyGuard.isLocked(TargetType.VNF, triggerSourceName, requestID)); + + /* + * This will stop the thread that is firing the rules + */ + kieSession.halt(); + + /* + * The only fact in memory should be Params + */ + assertEquals(1, kieSession.getFactCount()); + + /* + * Print what's left in memory + */ + dumpFacts(kieSession); + + /* + * Gracefully shut down the kie session + */ + kieSession.dispose(); + } + + /** + * This method will start a kie session and instantiate + * the Policy Engine. + * + * @param droolsTemplate + * the DRL rules file + * @param yamlFile + * the yaml file containing the policies + * @param policyScope + * scope for policy + * @param policyName + * name of the policy + * @param policyVersion + * version of the policy + * @return the kieSession to be used to insert facts + * @throws IOException + */ + private KieSession startSession(String droolsTemplate, + String yamlFile, + String policyScope, + String policyName, + String policyVersion) throws IOException { + + /* + * Load policies from yaml + */ + pair = Util.loadYaml(yamlFile); + assertNotNull(pair); + assertNotNull(pair.a); + assertNotNull(pair.a.getControlLoop()); + assertNotNull(pair.a.getControlLoop().getControlLoopName()); + assertTrue(pair.a.getControlLoop().getControlLoopName().length() > 0); + + /* + * Construct a kie session + */ + final KieSession kieSession = Util.buildContainer(droolsTemplate, + pair.a.getControlLoop().getControlLoopName(), + policyScope, + policyName, + policyVersion, + URLEncoder.encode(pair.b, "UTF-8")); + + /* + * Retrieve the Policy Engine + */ + engine = (PolicyEngineJUnitImpl) kieSession.getGlobal("Engine"); + + logger.debug("============"); + logger.debug(URLEncoder.encode(pair.b, "UTF-8")); + logger.debug("============"); + + return kieSession; + } + + /** + * This method is used to simulate event messages from DCAE + * that start the control loop (onset message). + * + * @param policy the controlLoopName comes from the policy + * @param requestID the requestId for this event + * @param triggerSourceName + * @throws InterruptedException + */ + protected void sendOnset(ControlLoopPolicy policy, UUID requestID, String triggerSourceName) throws InterruptedException { + VirtualControlLoopEvent event = new VirtualControlLoopEvent(); + event.closedLoopControlName = policy.getControlLoop().getControlLoopName(); + event.requestID = requestID; + event.target = "VNF_NAME"; + event.target_type = ControlLoopTargetType.VNF; + event.closedLoopAlarmStart = Instant.now(); + event.AAI = new HashMap<>(); + event.AAI.put("cloud-region.identity-url", "foo"); + event.AAI.put("vserver.selflink", "bar"); + event.AAI.put("vserver.is-closed-loop-disabled", "false"); + event.AAI.put("vserver.vserver-name", "vserver-name-16102016-aai3255-data-11-1"); + event.closedLoopEventStatus = ControlLoopEventStatus.ONSET; + kieSession.insert(event); + Thread.sleep(2000); + } + + /** + * This method is used to simulate event messages from DCAE + * that end the control loop (abatement message). + * + * @param policy the controlLoopName comes from the policy + * @param requestID the requestId for this event + * @param triggerSourceName + * @throws InterruptedException + */ + protected void sendAbatement(ControlLoopPolicy policy, UUID requestID, String triggerSourceName) throws InterruptedException { + VirtualControlLoopEvent event = new VirtualControlLoopEvent(); + event.closedLoopControlName = policy.getControlLoop().getControlLoopName(); + event.requestID = requestID; + event.target = "generic-vnf.vnf-id"; + event.closedLoopAlarmStart = Instant.now().minusSeconds(5); + event.closedLoopAlarmEnd = Instant.now(); + event.AAI = new HashMap<>(); + event.AAI.put("cloud-region.identity-url", "foo"); + event.AAI.put("vserver.selflink", "bar"); + event.AAI.put("vserver.is-closed-loop-disabled", "false"); + event.AAI.put("generic-vnf.vnf-id", "testGenericVnfID"); + event.closedLoopEventStatus = ControlLoopEventStatus.ABATED; + kieSession.insert(event); + } + + /** + * This method will dump all the facts in the working memory. + * + * @param kieSession the session containing the facts + */ + public void dumpFacts(KieSession kieSession) { + logger.debug("Fact Count: {}", kieSession.getFactCount()); + for (FactHandle handle : kieSession.getFactHandles()) { + logger.debug("FACT: {}", handle); + } + } +} -- cgit 1.2.3-korg