From a24a985d328b97f50a41d3448d235866af625ca9 Mon Sep 17 00:00:00 2001 From: Pamela Dragosh Date: Fri, 21 Sep 2018 20:08:11 -0400 Subject: Fix checkstyle declarations I fixed what I thought would be tolerable for this release. Same issue as policy/common I had to defined the checkstyle in each repo where the suppressions were needed. Issue-ID: POLICY-1135 Change-Id: I8f30bee7e9cddc692ddad3cf88acedb2e6b4781b Signed-off-by: Pamela Dragosh --- .../actor/appc/APPCActorServiceProvider.java | 126 ------ .../actor/appc/AppcActorServiceProvider.java | 126 ++++++ ...licy.controlloop.actorServiceProvider.spi.Actor | 2 +- .../actor/appc/AppcServiceProviderTest.java | 4 +- .../actor/appclcm/AppcLcmRecipeFormatter.java | 4 +- .../actor/so/SOActorServiceProvider.java | 457 --------------------- .../actor/so/SoActorServiceProvider.java | 457 +++++++++++++++++++++ ...licy.controlloop.actorServiceProvider.spi.Actor | 2 +- .../actor/so/SoActorServiceProviderTest.java | 38 +- .../actor/vfc/VFCActorServiceProvider.java | 150 ------- .../actor/vfc/VfcActorServiceProvider.java | 151 +++++++ ...licy.controlloop.actorServiceProvider.spi.Actor | 2 +- .../actor/vfc/VfcActorServiceProviderTest.java | 22 +- .../eventmanager/checkstyle-suppressions.xml | 33 ++ controlloop/common/eventmanager/pom.xml | 40 ++ .../eventmanager/ControlLoopEventManager.java | 17 +- .../eventmanager/ControlLoopOperationManager.java | 14 +- .../checkstyle-suppressions.xml | 30 ++ .../common/feature-controlloop-trans/pom.xml | 37 +- .../feature/trans/ControlLoopMetricsFeature.java | 2 +- .../common/guard/checkstyle-suppressions.xml | 30 ++ controlloop/common/guard/pom.xml | 40 ++ .../java/org/onap/policy/guard/CallGuardTask.java | 11 +- .../org/onap/policy/guard/PipEngineGetStatus.java | 34 +- .../java/org/onap/policy/guard/PolicyGuard.java | 32 +- .../org/onap/policy/guard/PolicyGuardRequest.java | 12 +- .../org/onap/policy/guard/PolicyGuardResponse.java | 6 +- .../onap/policy/guard/PolicyGuardXacmlHelper.java | 6 +- .../org/onap/policy/guard/impl/VMTargetLock.java | 6 +- .../org/onap/policy/guard/impl/VNFTargetLock.java | 6 +- .../onap/policy/guard/PipEngineGetStatusTest.java | 160 -------- .../onap/policy/controlloop/ControlLoopEvent.java | 3 +- .../model-impl/rest/checkstyle-suppressions.xml | 30 ++ controlloop/common/model-impl/rest/pom.xml | 42 ++ .../org/onap/policy/rest/HttpDeleteWithBody.java | 5 +- .../model-impl/sdc/checkstyle-suppressions.xml | 30 ++ controlloop/common/model-impl/sdc/pom.xml | 42 ++ .../model-impl/so/checkstyle-suppressions.xml | 30 ++ controlloop/common/model-impl/so/pom.xml | 41 ++ .../main/java/org/onap/policy/so/SOManager.java | 65 +-- .../java/org/onap/policy/so/SoOperationType.java | 3 +- .../trafficgenerator/checkstyle-suppressions.xml | 30 ++ .../common/model-impl/trafficgenerator/pom.xml | 42 ++ .../model-impl/vfc/checkstyle-suppressions.xml | 30 ++ controlloop/common/model-impl/vfc/pom.xml | 41 ++ controlloop/common/policy-yaml/pom.xml | 49 +++ .../onap/policy/simulators/AaiSimulatorJaxRs.java | 27 +- .../onap/policy/simulators/SoSimulatorJaxRs.java | 2 +- 48 files changed, 1509 insertions(+), 1060 deletions(-) delete mode 100644 controlloop/common/actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/APPCActorServiceProvider.java create mode 100644 controlloop/common/actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/AppcActorServiceProvider.java delete 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/java/org/onap/policy/controlloop/actor/so/SoActorServiceProvider.java delete mode 100644 controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java create mode 100644 controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcActorServiceProvider.java create mode 100644 controlloop/common/eventmanager/checkstyle-suppressions.xml create mode 100644 controlloop/common/feature-controlloop-trans/checkstyle-suppressions.xml create mode 100644 controlloop/common/guard/checkstyle-suppressions.xml create mode 100644 controlloop/common/model-impl/rest/checkstyle-suppressions.xml create mode 100644 controlloop/common/model-impl/sdc/checkstyle-suppressions.xml create mode 100644 controlloop/common/model-impl/so/checkstyle-suppressions.xml create mode 100644 controlloop/common/model-impl/trafficgenerator/checkstyle-suppressions.xml create mode 100644 controlloop/common/model-impl/vfc/checkstyle-suppressions.xml (limited to 'controlloop/common') diff --git a/controlloop/common/actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/APPCActorServiceProvider.java b/controlloop/common/actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/APPCActorServiceProvider.java deleted file mode 100644 index 8960ee022..000000000 --- a/controlloop/common/actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/APPCActorServiceProvider.java +++ /dev/null @@ -1,126 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * APPCActorServiceProvider - * ================================================================================ - * Copyright (C) 2017-2018 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.appc; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - -import java.util.Collections; -import java.util.List; - -import org.onap.policy.appc.CommonHeader; -import org.onap.policy.appc.Request; -import org.onap.policy.controlloop.ControlLoopOperation; -import org.onap.policy.controlloop.VirtualControlLoopEvent; -import org.onap.policy.controlloop.actorserviceprovider.spi.Actor; -import org.onap.policy.controlloop.policy.Policy; -import org.onap.policy.vnf.trafficgenerator.PGRequest; -import org.onap.policy.vnf.trafficgenerator.PGStream; -import org.onap.policy.vnf.trafficgenerator.PGStreams; - - -public class APPCActorServiceProvider implements Actor { - // Strings for targets - private static final String TARGET_VM = "VM"; - private static final String TARGET_VNF = "VNF"; - - // Strings for recipes - private static final String RECIPE_RESTART = "Restart"; - private static final String RECIPE_REBUILD = "Rebuild"; - private static final String RECIPE_MIGRATE = "Migrate"; - private static final String RECIPE_MODIFY = "ModifyConfig"; - - private static final ImmutableList recipes = - ImmutableList.of(RECIPE_RESTART, RECIPE_REBUILD, RECIPE_MIGRATE, RECIPE_MODIFY); - private static final ImmutableMap> targets = new ImmutableMap.Builder>() - .put(RECIPE_RESTART, ImmutableList.of(TARGET_VM)).put(RECIPE_REBUILD, ImmutableList.of(TARGET_VM)) - .put(RECIPE_MIGRATE, ImmutableList.of(TARGET_VM)).put(RECIPE_MODIFY, ImmutableList.of(TARGET_VNF)).build(); - private static final ImmutableMap> payloads = new ImmutableMap.Builder>() - .put(RECIPE_MODIFY, ImmutableList.of("generic-vnf.vnf-id")).build(); - - @Override - public String actor() { - return "APPC"; - } - - @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 ImmutableList.copyOf(payloads.getOrDefault(recipe, Collections.emptyList())); - } - - /** - * Constructs an APPC request conforming to the legacy API. The legacy API will be deprecated in - * future releases as all legacy functionality is moved into the LCM API. - * - * @param onset the event that is reporting the alert for policy to perform an action - * @param operation the control loop operation specifying the actor, operation, target, etc. - * @param policy the policy the was specified from the yaml generated by CLAMP or through the - * Policy GUI/API - * @return an APPC request conforming to the legacy API - */ - public static Request constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation, Policy policy, - String targetVnf) { - /* - * Construct an APPC request - */ - Request request = new Request(); - request.setCommonHeader(new CommonHeader()); - request.getCommonHeader().setRequestId(onset.getRequestId()); - request.getCommonHeader().setSubRequestId(operation.getSubRequestId()); - request.setAction(policy.getRecipe().substring(0, 1).toUpperCase() + policy.getRecipe().substring(1)); - - /* - * For now Policy generates the PG Streams as a demo, in the future the payload can be - * provided by CLAMP - */ - request.getPayload().put("generic-vnf.vnf-id", targetVnf); - - PGRequest pgRequest = new PGRequest(); - pgRequest.pgStreams = new PGStreams(); - - PGStream pgStream; - for (int i = 0; i < 5; i++) { - pgStream = new PGStream(); - pgStream.streamId = "fw_udp" + (i + 1); - pgStream.isEnabled = "true"; - pgRequest.pgStreams.pgStream.add(pgStream); - } - request.getPayload().put("pg-streams", pgRequest.pgStreams); - - /* - * Return the request - */ - - return request; - } - - -} diff --git a/controlloop/common/actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/AppcActorServiceProvider.java b/controlloop/common/actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/AppcActorServiceProvider.java new file mode 100644 index 000000000..865584972 --- /dev/null +++ b/controlloop/common/actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/AppcActorServiceProvider.java @@ -0,0 +1,126 @@ +/*- + * ============LICENSE_START======================================================= + * APPCActorServiceProvider + * ================================================================================ + * Copyright (C) 2017-2018 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.appc; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; + +import java.util.Collections; +import java.util.List; + +import org.onap.policy.appc.CommonHeader; +import org.onap.policy.appc.Request; +import org.onap.policy.controlloop.ControlLoopOperation; +import org.onap.policy.controlloop.VirtualControlLoopEvent; +import org.onap.policy.controlloop.actorserviceprovider.spi.Actor; +import org.onap.policy.controlloop.policy.Policy; +import org.onap.policy.vnf.trafficgenerator.PGRequest; +import org.onap.policy.vnf.trafficgenerator.PGStream; +import org.onap.policy.vnf.trafficgenerator.PGStreams; + + +public class AppcActorServiceProvider implements Actor { + // Strings for targets + private static final String TARGET_VM = "VM"; + private static final String TARGET_VNF = "VNF"; + + // Strings for recipes + private static final String RECIPE_RESTART = "Restart"; + private static final String RECIPE_REBUILD = "Rebuild"; + private static final String RECIPE_MIGRATE = "Migrate"; + private static final String RECIPE_MODIFY = "ModifyConfig"; + + private static final ImmutableList recipes = + ImmutableList.of(RECIPE_RESTART, RECIPE_REBUILD, RECIPE_MIGRATE, RECIPE_MODIFY); + private static final ImmutableMap> targets = new ImmutableMap.Builder>() + .put(RECIPE_RESTART, ImmutableList.of(TARGET_VM)).put(RECIPE_REBUILD, ImmutableList.of(TARGET_VM)) + .put(RECIPE_MIGRATE, ImmutableList.of(TARGET_VM)).put(RECIPE_MODIFY, ImmutableList.of(TARGET_VNF)).build(); + private static final ImmutableMap> payloads = new ImmutableMap.Builder>() + .put(RECIPE_MODIFY, ImmutableList.of("generic-vnf.vnf-id")).build(); + + @Override + public String actor() { + return "APPC"; + } + + @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 ImmutableList.copyOf(payloads.getOrDefault(recipe, Collections.emptyList())); + } + + /** + * Constructs an APPC request conforming to the legacy API. The legacy API will be deprecated in + * future releases as all legacy functionality is moved into the LCM API. + * + * @param onset the event that is reporting the alert for policy to perform an action + * @param operation the control loop operation specifying the actor, operation, target, etc. + * @param policy the policy the was specified from the yaml generated by CLAMP or through the + * Policy GUI/API + * @return an APPC request conforming to the legacy API + */ + public static Request constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation, Policy policy, + String targetVnf) { + /* + * Construct an APPC request + */ + Request request = new Request(); + request.setCommonHeader(new CommonHeader()); + request.getCommonHeader().setRequestId(onset.getRequestId()); + request.getCommonHeader().setSubRequestId(operation.getSubRequestId()); + request.setAction(policy.getRecipe().substring(0, 1).toUpperCase() + policy.getRecipe().substring(1)); + + /* + * For now Policy generates the PG Streams as a demo, in the future the payload can be + * provided by CLAMP + */ + request.getPayload().put("generic-vnf.vnf-id", targetVnf); + + PGRequest pgRequest = new PGRequest(); + pgRequest.pgStreams = new PGStreams(); + + PGStream pgStream; + for (int i = 0; i < 5; i++) { + pgStream = new PGStream(); + pgStream.streamId = "fw_udp" + (i + 1); + pgStream.isEnabled = "true"; + pgRequest.pgStreams.pgStream.add(pgStream); + } + request.getPayload().put("pg-streams", pgRequest.pgStreams); + + /* + * Return the request + */ + + return request; + } + + +} diff --git a/controlloop/common/actors/actor.appc/src/main/resources/META-INF/services/org.onap.policy.controlloop.actorServiceProvider.spi.Actor b/controlloop/common/actors/actor.appc/src/main/resources/META-INF/services/org.onap.policy.controlloop.actorServiceProvider.spi.Actor index 8181582b5..f1002a301 100644 --- a/controlloop/common/actors/actor.appc/src/main/resources/META-INF/services/org.onap.policy.controlloop.actorServiceProvider.spi.Actor +++ b/controlloop/common/actors/actor.appc/src/main/resources/META-INF/services/org.onap.policy.controlloop.actorServiceProvider.spi.Actor @@ -1 +1 @@ -org.onap.policy.controlloop.actor.appc.APPCActorServiceProvider \ No newline at end of file +org.onap.policy.controlloop.actor.appc.AppcActorServiceProvider \ No newline at end of file diff --git a/controlloop/common/actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java b/controlloop/common/actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java index 1fffe043c..9f8528fe0 100644 --- a/controlloop/common/actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java +++ b/controlloop/common/actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java @@ -125,7 +125,7 @@ public class AppcServiceProviderTest { public void constructModifyConfigRequestTest() { Request appcRequest; - appcRequest = APPCActorServiceProvider.constructRequest(onsetEvent, operation, policy, "vnf01"); + appcRequest = AppcActorServiceProvider.constructRequest(onsetEvent, operation, policy, "vnf01"); /* The service provider must return a non null APPC request */ assertNotNull(appcRequest); @@ -168,7 +168,7 @@ public class AppcServiceProviderTest { @Test public void testMethods() { - APPCActorServiceProvider sp = new APPCActorServiceProvider(); + AppcActorServiceProvider sp = new AppcActorServiceProvider(); assertEquals("APPC", sp.actor()); assertEquals(4, sp.recipes().size()); diff --git a/controlloop/common/actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmRecipeFormatter.java b/controlloop/common/actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmRecipeFormatter.java index c9feb0d2a..12fad9e84 100644 --- a/controlloop/common/actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmRecipeFormatter.java +++ b/controlloop/common/actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmRecipeFormatter.java @@ -3,6 +3,7 @@ * * ================================================================================ * Copyright (C) 2018 Nokia Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2018 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. @@ -21,9 +22,8 @@ package org.onap.policy.controlloop.actor.appclcm; import com.google.common.collect.Lists; -import org.apache.commons.lang.StringUtils; - import java.util.stream.Collectors; +import org.apache.commons.lang.StringUtils; class AppcLcmRecipeFormatter { 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 deleted file mode 100644 index 7c0214bfb..000000000 --- a/controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java +++ /dev/null @@ -1,457 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * SOActorServiceProvider - * ================================================================================ - * Copyright (C) 2017-2018 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 com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.gson.reflect.TypeToken; -import java.lang.reflect.Type; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import org.drools.core.WorkingMemory; -import org.onap.policy.aai.AaiNqExtraProperty; -import org.onap.policy.aai.AaiNqInventoryResponseItem; -import org.onap.policy.aai.AaiNqResponseWrapper; -import org.onap.policy.controlloop.ControlLoopOperation; -import org.onap.policy.controlloop.VirtualControlLoopEvent; -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.SoOperationType; -import org.onap.policy.so.util.Serialization; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SOActorServiceProvider implements Actor { - private static final Logger logger = LoggerFactory.getLogger(SOActorServiceProvider.class); - - // Strings for SO Actor - private static final String SO_ACTOR = "SO"; - - // Strings for targets - private static final String TARGET_VFC = "VFC"; - - // Strings for recipes - private static final String RECIPE_VF_MODULE_CREATE = "VF Module Create"; - private static final String RECIPE_VF_MODULE_DELETE = "VF Module Delete"; - - private static final ImmutableList recipes = ImmutableList.of(RECIPE_VF_MODULE_CREATE, - RECIPE_VF_MODULE_DELETE); - private static final ImmutableMap> targets = new ImmutableMap.Builder>() - .put(RECIPE_VF_MODULE_CREATE, ImmutableList.of(TARGET_VFC)) - .put(RECIPE_VF_MODULE_DELETE, ImmutableList.of(TARGET_VFC)).build(); - - // name of request parameters within policy payload - public static final String REQ_PARAM_NM = "requestParameters"; - - // name of configuration parameters within policy payload - public static final String CONFIG_PARAM_NM = "configurationParameters"; - - private static final String MODEL_NAME_PROPERTY_KEY = "model-ver.model-name"; - private static final String MODEL_VERSION_PROPERTY_KEY = "model-ver.model-version"; - private static final String MODEL_VERSION_ID_PROPERTY_KEY = "model-ver.model-version-id"; - - // used to decode configuration parameters via gson - private static final Type CONFIG_TYPE = new TypeToken>>() {}.getType(); - - // Static variables required to hold the IDs of the last service item, VNF item and VF Module. - // Note that in - // a multithreaded deployment this WILL break - private static String lastVNFItemVnfId; - private static String lastServiceItemServiceInstanceId; - private static String lastVfModuleItemVfModuleInstanceId; - - @Override - public String actor() { - return SO_ACTOR; - } - - @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(); - } - - /** - * Constructs a SO request conforming to the lcm API. The actual request is - * constructed and then placed in a wrapper object used to send through DMAAP. - * - * @param onset the event that is reporting the alert for policy to perform an action - * @param operation the control loop operation specifying the actor, operation, - * target, etc. - * @param policy the policy the was specified from the yaml generated by CLAMP or - * through the Policy GUI/API - * @param aaiResponseWrapper wrapper for AAI vserver named-query response - * @return a SO request conforming to the lcm API using the DMAAP wrapper - */ - public SORequest constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation, Policy policy, - AaiNqResponseWrapper aaiResponseWrapper) { - if (!SO_ACTOR.equals(policy.getActor()) || !recipes().contains(policy.getRecipe())) { - return null; - } - - // A&AI named query should have been performed by now. If not, return null - if (aaiResponseWrapper == null) { - return null; - } - - AaiNqInventoryResponseItem vnfItem; - AaiNqInventoryResponseItem vnfServiceItem; - AaiNqInventoryResponseItem tenantItem; - - // Extract the items we're interested in from the response - try { - vnfItem = aaiResponseWrapper.getAaiNqResponse().getInventoryResponseItems().get(0).getItems() - .getInventoryResponseItems().get(0); - } catch (Exception e) { - logger.error("VNF Item not found in AAI response {}", Serialization.gsonPretty.toJson(aaiResponseWrapper), - e); - return null; - } - - try { - vnfServiceItem = vnfItem.getItems().getInventoryResponseItems().get(0); - } catch (Exception e) { - logger.error("VNF Service Item not found in AAI response {}", - Serialization.gsonPretty.toJson(aaiResponseWrapper), e); - return null; - } - - try { - tenantItem = aaiResponseWrapper.getAaiNqResponse().getInventoryResponseItems().get(0).getItems() - .getInventoryResponseItems().get(1); - } catch (Exception e) { - logger.error("Tenant Item not found in AAI response {}", - Serialization.gsonPretty.toJson(aaiResponseWrapper), e); - return null; - } - - // Find the index for base vf module and non-base vf module - AaiNqInventoryResponseItem baseItem = findVfModule(aaiResponseWrapper, true); - AaiNqInventoryResponseItem vfModuleItem = findVfModule(aaiResponseWrapper, false); - - // Report the error if either base vf module or non-base vf module is not found - if (baseItem == null || vfModuleItem == null) { - logger.error("Either base or non-base vf module is not found from AAI response."); - return null; - } - - // Construct SO Request for a policy's recipe - if (RECIPE_VF_MODULE_CREATE.equals(policy.getRecipe())) { - return constructCreateRequest(aaiResponseWrapper, policy, tenantItem, vnfItem, vnfServiceItem, - vfModuleItem); - } else if (RECIPE_VF_MODULE_DELETE.equals(policy.getRecipe())) { - return constructDeleteRequest(tenantItem, vnfItem, vnfServiceItem, vfModuleItem); - } else { - return null; - } - } - - /** - * Construct SO request to create vf-module - * - * @param aaiResponseWrapper the AAI response containing the VF modules - * @param policy the policy - * @param tenantItem tenant item from A&AI named-query response - * @param vnfItem vnf item from A&AI named-query response - * @param vnfServiceItem vnf service item from A&AI named-query response - * @param vfModuleItem vf module item from A&AI named-query response - * @return SO create vf-module request - */ - private SORequest constructCreateRequest(AaiNqResponseWrapper aaiResponseWrapper, Policy policy, - AaiNqInventoryResponseItem tenantItem, AaiNqInventoryResponseItem vnfItem, - AaiNqInventoryResponseItem vnfServiceItem, - AaiNqInventoryResponseItem vfModuleItem) { - SORequest request = new SORequest(); - request.setOperationType(SoOperationType.SCALE_OUT); - // - // - // Do NOT send So the requestId, they do not support this field - // - request.setRequestDetails(new SORequestDetails()); - request.getRequestDetails().setRequestParameters(new SORequestParameters()); - request.getRequestDetails().getRequestParameters().setUserParams(null); - - // cloudConfiguration - request.getRequestDetails().setCloudConfiguration(constructCloudConfiguration(tenantItem)); - // modelInfo - request.getRequestDetails().setModelInfo(constructVfModuleModelInfo(vfModuleItem)); - request.getRequestDetails().getModelInfo().setModelVersionId(vfModuleItem.getVfModule().getModelVersionId()); - - // requestInfo - request.getRequestDetails().setRequestInfo(constructRequestInfo()); - String vfModuleName = aaiResponseWrapper.genVfModuleName(); - request.getRequestDetails().getRequestInfo().setInstanceName(vfModuleName); - - // relatedInstanceList - SORelatedInstanceListElement relatedInstanceListElement1 = new SORelatedInstanceListElement(); - SORelatedInstanceListElement relatedInstanceListElement2 = new SORelatedInstanceListElement(); - relatedInstanceListElement1.setRelatedInstance(new SORelatedInstance()); - relatedInstanceListElement2.setRelatedInstance(new SORelatedInstance()); - - // Service Item - relatedInstanceListElement1.getRelatedInstance() - .setInstanceId(vnfServiceItem.getServiceInstance().getServiceInstanceId()); - relatedInstanceListElement1.getRelatedInstance().setModelInfo(new SOModelInfo()); - relatedInstanceListElement1.getRelatedInstance().getModelInfo().setModelType("service"); - relatedInstanceListElement1.getRelatedInstance().getModelInfo() - .setModelInvariantId(vnfServiceItem.getServiceInstance().getModelInvariantId()); - for (AaiNqExtraProperty prop : vnfServiceItem.getExtraProperties().getExtraProperty()) { - if (prop.getPropertyName().equals(MODEL_NAME_PROPERTY_KEY)) { - relatedInstanceListElement1.getRelatedInstance().getModelInfo().setModelName(prop.getPropertyValue()); - } else if (prop.getPropertyName().equals(MODEL_VERSION_PROPERTY_KEY)) { - relatedInstanceListElement1.getRelatedInstance().getModelInfo() - .setModelVersion(prop.getPropertyValue()); - } else if (prop.getPropertyName().equals(MODEL_VERSION_ID_PROPERTY_KEY)) { - relatedInstanceListElement1.getRelatedInstance().getModelInfo() - .setModelVersionId(prop.getPropertyValue()); - } - } - - // VNF Item - relatedInstanceListElement2.getRelatedInstance().setInstanceId(vnfItem.getGenericVnf().getVnfId()); - relatedInstanceListElement2.getRelatedInstance().setModelInfo(new SOModelInfo()); - relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelType("vnf"); - relatedInstanceListElement2.getRelatedInstance().getModelInfo() - .setModelInvariantId(vnfItem.getGenericVnf().getModelInvariantId()); - for (AaiNqExtraProperty prop : vnfItem.getExtraProperties().getExtraProperty()) { - if (prop.getPropertyName().equals(MODEL_NAME_PROPERTY_KEY)) { - relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelName(prop.getPropertyValue()); - } else if (prop.getPropertyName().equals(MODEL_VERSION_PROPERTY_KEY)) { - relatedInstanceListElement2.getRelatedInstance().getModelInfo() - .setModelVersion(prop.getPropertyValue()); - } else if (prop.getPropertyName().equals(MODEL_VERSION_ID_PROPERTY_KEY)) { - relatedInstanceListElement2.getRelatedInstance().getModelInfo() - .setModelVersionId(prop.getPropertyValue()); - } - } - relatedInstanceListElement2.getRelatedInstance().getModelInfo() - .setModelCustomizationName(vnfItem.getGenericVnf().getVnfType() - .substring(vnfItem.getGenericVnf().getVnfType().lastIndexOf('/') + 1)); - relatedInstanceListElement2.getRelatedInstance().getModelInfo() - .setModelCustomizationId(vnfItem.getGenericVnf().getModelCustomizationId()); - - // Insert the Service Item and VNF Item - request.getRequestDetails().getRelatedInstanceList().add(relatedInstanceListElement1); - request.getRequestDetails().getRelatedInstanceList().add(relatedInstanceListElement2); - - // Request Parameters - buildRequestParameters(policy, request.getRequestDetails()); - - // Configuration Parameters - buildConfigurationParameters(policy, request.getRequestDetails()); - // Save the instance IDs for the VNF and service to static fields - // vfModuleId is not required for the create vf-module - preserveInstanceIds(vnfItem.getGenericVnf().getVnfId(), vnfServiceItem.getServiceInstance() - .getServiceInstanceId(), null); - if (logger.isDebugEnabled()) { - logger.debug("Constructed SO request: {}", Serialization.gsonPretty.toJson(request)); - } - return request; - } - - /** - * Construct SO request to delete vf-module - * - * @param tenantItem tenant item from A&AI named-query response - * @param vnfItem vnf item from A&AI named-query response - * @param vnfServiceItem vnf service item from A&AI named-query response - * @param vfModuleItem vf module item from A&AI named-query response - * @return SO delete vf-module request - */ - private SORequest constructDeleteRequest(AaiNqInventoryResponseItem tenantItem, AaiNqInventoryResponseItem - vnfItem, AaiNqInventoryResponseItem vnfServiceItem, AaiNqInventoryResponseItem vfModuleItem) { - SORequest request = new SORequest(); - request.setOperationType(SoOperationType.DELETE_VF_MODULE); - request.setRequestDetails(new SORequestDetails()); - request.getRequestDetails().setRelatedInstanceList(null); - request.getRequestDetails().setConfigurationParameters(null); - - // cloudConfiguration - request.getRequestDetails().setCloudConfiguration(constructCloudConfiguration(tenantItem)); - // modelInfo - request.getRequestDetails().setModelInfo(constructVfModuleModelInfo(vfModuleItem)); - // requestInfo - request.getRequestDetails().setRequestInfo(constructRequestInfo()); - // Save the instance IDs for the VNF, service and vfModule to static fields - preserveInstanceIds(vnfItem.getGenericVnf().getVnfId(), vnfServiceItem.getServiceInstance() - .getServiceInstanceId(), vfModuleItem.getVfModule().getVfModuleId()); - - if (logger.isDebugEnabled()) { - logger.debug("Constructed SO request: {}", Serialization.gsonPretty.toJson(request)); - } - return request; - } - - /** - * construct requestInfo for the SO requestDetails - * - * @return SO request information - */ - private SORequestInfo constructRequestInfo() { - SORequestInfo soRequestInfo = new SORequestInfo(); - soRequestInfo.setSource("POLICY"); - soRequestInfo.setSuppressRollback(false); - soRequestInfo.setRequestorId("policy"); - return soRequestInfo; - } - - /** - * construct modelInfo of the vfModule for the SO requestDetails - * - * @param vfModuleItem vf module item from A&AI named-query response - * @return SO Model info for the vfModule - */ - private SOModelInfo constructVfModuleModelInfo(AaiNqInventoryResponseItem vfModuleItem) { - SOModelInfo soModelInfo = new SOModelInfo(); - soModelInfo.setModelType("vfModule"); - soModelInfo.setModelInvariantId(vfModuleItem.getVfModule().getModelInvariantId()); - soModelInfo.setModelCustomizationId(vfModuleItem.getVfModule().getModelCustomizationId()); - - for (AaiNqExtraProperty prop : vfModuleItem.getExtraProperties().getExtraProperty()) { - if (prop.getPropertyName().equals(MODEL_NAME_PROPERTY_KEY)) { - soModelInfo.setModelName(prop.getPropertyValue()); - } else if (prop.getPropertyName().equals(MODEL_VERSION_PROPERTY_KEY)) { - soModelInfo.setModelVersion(prop.getPropertyValue()); - } - } - return soModelInfo; - } - - /** - * construct cloudConfiguration for the SO requestDetails - * - * @param tenantItem tenant item from A&AI named-query response - * @return SO cloud configuration - */ - private SOCloudConfiguration constructCloudConfiguration(AaiNqInventoryResponseItem tenantItem) { - SOCloudConfiguration cloudConfiguration = new SOCloudConfiguration(); - cloudConfiguration.setTenantId(tenantItem.getTenant().getTenantId()); - cloudConfiguration.setLcpCloudRegionId(tenantItem.getItems().getInventoryResponseItems().get(0) - .getCloudRegion().getCloudRegionId()); - return cloudConfiguration; - } - - /** - * This method is needed to get the serviceInstanceId and vnfInstanceId which is used - * in the asyncSORestCall. - * - * @param requestId the request Id - * @param wm the working memory - * @param request the request - */ - public static void sendRequest(String requestId, WorkingMemory wm, Object request) { - SOManager soManager = new SOManager(); - soManager.asyncSORestCall(requestId, wm, lastServiceItemServiceInstanceId, lastVNFItemVnfId, - lastVfModuleItemVfModuleInstanceId, (SORequest) request); - } - - /** - * Find the base or non base VF module item in an AAI response. - * If there is more than one item, then the last item is returned - * - * @param aaiResponseWrapper the AAI response containing the VF modules - * @param baseFlag true if we are searching for the base, false if we are searching - * for the non base - * @return the base or non base VF module item or null if the module was not found - */ - private AaiNqInventoryResponseItem findVfModule(AaiNqResponseWrapper aaiResponseWrapper, boolean baseFlag) { - List lst = aaiResponseWrapper.getVfModuleItems(baseFlag); - return (lst.isEmpty() ? null : lst.get(lst.size() - 1)); - } - - /** - * Builds the request parameters from the policy payload. - * - * @param policy the policy - * @param request request into which to stick the request parameters - */ - private void buildRequestParameters(Policy policy, SORequestDetails request) { - // assume null until proven otherwise - request.setRequestParameters(null); - - if (policy.getPayload() == null) { - return; - } - - String json = policy.getPayload().get(REQ_PARAM_NM); - if (json == null) { - return; - } - - request.setRequestParameters(Serialization.gsonPretty.fromJson(json, SORequestParameters.class)); - } - - /** - * Builds the configuration parameters from the policy payload. - * - * @param policy the policy - * @param request request into which to stick the configuration parameters - */ - private void buildConfigurationParameters(Policy policy, SORequestDetails request) { - // assume null until proven otherwise - request.setConfigurationParameters(null); - - if (policy.getPayload() == null) { - return; - } - - String json = policy.getPayload().get(CONFIG_PARAM_NM); - if (json == null) { - return; - } - - request.setConfigurationParameters(Serialization.gsonPretty.fromJson(json, CONFIG_TYPE)); - } - - /** - * This method is called to remember the last service instance ID, VNF Item VNF ID and vf module ID. - * Note these fields are static, beware for multithreaded deployments - * - * @param vnfInstanceId update the last VNF instance ID to this value - * @param serviceInstanceId update the last service instance ID to this value - * @param vfModuleId update the vfModule instance ID to this value - */ - private static void preserveInstanceIds(final String vnfInstanceId, final String serviceInstanceId, - final String vfModuleId) { - lastVNFItemVnfId = vnfInstanceId; - lastServiceItemServiceInstanceId = serviceInstanceId; - lastVfModuleItemVfModuleInstanceId = vfModuleId; - } -} 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..8edddbb40 --- /dev/null +++ b/controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActorServiceProvider.java @@ -0,0 +1,457 @@ +/* + * ============LICENSE_START======================================================= + * SOActorServiceProvider + * ================================================================================ + * Copyright (C) 2017-2018 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 com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.gson.reflect.TypeToken; +import java.lang.reflect.Type; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import org.drools.core.WorkingMemory; +import org.onap.policy.aai.AaiNqExtraProperty; +import org.onap.policy.aai.AaiNqInventoryResponseItem; +import org.onap.policy.aai.AaiNqResponseWrapper; +import org.onap.policy.controlloop.ControlLoopOperation; +import org.onap.policy.controlloop.VirtualControlLoopEvent; +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.SoOperationType; +import org.onap.policy.so.util.Serialization; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SoActorServiceProvider implements Actor { + private static final Logger logger = LoggerFactory.getLogger(SoActorServiceProvider.class); + + // Strings for SO Actor + private static final String SO_ACTOR = "SO"; + + // Strings for targets + private static final String TARGET_VFC = "VFC"; + + // Strings for recipes + private static final String RECIPE_VF_MODULE_CREATE = "VF Module Create"; + private static final String RECIPE_VF_MODULE_DELETE = "VF Module Delete"; + + private static final ImmutableList recipes = ImmutableList.of(RECIPE_VF_MODULE_CREATE, + RECIPE_VF_MODULE_DELETE); + private static final ImmutableMap> targets = new ImmutableMap.Builder>() + .put(RECIPE_VF_MODULE_CREATE, ImmutableList.of(TARGET_VFC)) + .put(RECIPE_VF_MODULE_DELETE, ImmutableList.of(TARGET_VFC)).build(); + + // name of request parameters within policy payload + public static final String REQ_PARAM_NM = "requestParameters"; + + // name of configuration parameters within policy payload + public static final String CONFIG_PARAM_NM = "configurationParameters"; + + private static final String MODEL_NAME_PROPERTY_KEY = "model-ver.model-name"; + private static final String MODEL_VERSION_PROPERTY_KEY = "model-ver.model-version"; + private static final String MODEL_VERSION_ID_PROPERTY_KEY = "model-ver.model-version-id"; + + // used to decode configuration parameters via gson + private static final Type CONFIG_TYPE = new TypeToken>>() {}.getType(); + + // Static variables required to hold the IDs of the last service item, VNF item and VF Module. + // Note that in + // a multithreaded deployment this WILL break + private static String lastVNFItemVnfId; + private static String lastServiceItemServiceInstanceId; + private static String lastVfModuleItemVfModuleInstanceId; + + @Override + public String actor() { + return SO_ACTOR; + } + + @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(); + } + + /** + * Constructs a SO request conforming to the lcm API. The actual request is + * constructed and then placed in a wrapper object used to send through DMAAP. + * + * @param onset the event that is reporting the alert for policy to perform an action + * @param operation the control loop operation specifying the actor, operation, + * target, etc. + * @param policy the policy the was specified from the yaml generated by CLAMP or + * through the Policy GUI/API + * @param aaiResponseWrapper wrapper for AAI vserver named-query response + * @return a SO request conforming to the lcm API using the DMAAP wrapper + */ + public SORequest constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation, Policy policy, + AaiNqResponseWrapper aaiResponseWrapper) { + if (!SO_ACTOR.equals(policy.getActor()) || !recipes().contains(policy.getRecipe())) { + return null; + } + + // A&AI named query should have been performed by now. If not, return null + if (aaiResponseWrapper == null) { + return null; + } + + AaiNqInventoryResponseItem vnfItem; + AaiNqInventoryResponseItem vnfServiceItem; + AaiNqInventoryResponseItem tenantItem; + + // Extract the items we're interested in from the response + try { + vnfItem = aaiResponseWrapper.getAaiNqResponse().getInventoryResponseItems().get(0).getItems() + .getInventoryResponseItems().get(0); + } catch (Exception e) { + logger.error("VNF Item not found in AAI response {}", Serialization.gsonPretty.toJson(aaiResponseWrapper), + e); + return null; + } + + try { + vnfServiceItem = vnfItem.getItems().getInventoryResponseItems().get(0); + } catch (Exception e) { + logger.error("VNF Service Item not found in AAI response {}", + Serialization.gsonPretty.toJson(aaiResponseWrapper), e); + return null; + } + + try { + tenantItem = aaiResponseWrapper.getAaiNqResponse().getInventoryResponseItems().get(0).getItems() + .getInventoryResponseItems().get(1); + } catch (Exception e) { + logger.error("Tenant Item not found in AAI response {}", + Serialization.gsonPretty.toJson(aaiResponseWrapper), e); + return null; + } + + // Find the index for base vf module and non-base vf module + AaiNqInventoryResponseItem baseItem = findVfModule(aaiResponseWrapper, true); + AaiNqInventoryResponseItem vfModuleItem = findVfModule(aaiResponseWrapper, false); + + // Report the error if either base vf module or non-base vf module is not found + if (baseItem == null || vfModuleItem == null) { + logger.error("Either base or non-base vf module is not found from AAI response."); + return null; + } + + // Construct SO Request for a policy's recipe + if (RECIPE_VF_MODULE_CREATE.equals(policy.getRecipe())) { + return constructCreateRequest(aaiResponseWrapper, policy, tenantItem, vnfItem, vnfServiceItem, + vfModuleItem); + } else if (RECIPE_VF_MODULE_DELETE.equals(policy.getRecipe())) { + return constructDeleteRequest(tenantItem, vnfItem, vnfServiceItem, vfModuleItem); + } else { + return null; + } + } + + /** + * Construct SO request to create vf-module. + * + * @param aaiResponseWrapper the AAI response containing the VF modules + * @param policy the policy + * @param tenantItem tenant item from A&AI named-query response + * @param vnfItem vnf item from A&AI named-query response + * @param vnfServiceItem vnf service item from A&AI named-query response + * @param vfModuleItem vf module item from A&AI named-query response + * @return SO create vf-module request + */ + private SORequest constructCreateRequest(AaiNqResponseWrapper aaiResponseWrapper, Policy policy, + AaiNqInventoryResponseItem tenantItem, AaiNqInventoryResponseItem vnfItem, + AaiNqInventoryResponseItem vnfServiceItem, + AaiNqInventoryResponseItem vfModuleItem) { + SORequest request = new SORequest(); + request.setOperationType(SoOperationType.SCALE_OUT); + // + // + // Do NOT send So the requestId, they do not support this field + // + request.setRequestDetails(new SORequestDetails()); + request.getRequestDetails().setRequestParameters(new SORequestParameters()); + request.getRequestDetails().getRequestParameters().setUserParams(null); + + // cloudConfiguration + request.getRequestDetails().setCloudConfiguration(constructCloudConfiguration(tenantItem)); + // modelInfo + request.getRequestDetails().setModelInfo(constructVfModuleModelInfo(vfModuleItem)); + request.getRequestDetails().getModelInfo().setModelVersionId(vfModuleItem.getVfModule().getModelVersionId()); + + // requestInfo + request.getRequestDetails().setRequestInfo(constructRequestInfo()); + String vfModuleName = aaiResponseWrapper.genVfModuleName(); + request.getRequestDetails().getRequestInfo().setInstanceName(vfModuleName); + + // relatedInstanceList + SORelatedInstanceListElement relatedInstanceListElement1 = new SORelatedInstanceListElement(); + SORelatedInstanceListElement relatedInstanceListElement2 = new SORelatedInstanceListElement(); + relatedInstanceListElement1.setRelatedInstance(new SORelatedInstance()); + relatedInstanceListElement2.setRelatedInstance(new SORelatedInstance()); + + // Service Item + relatedInstanceListElement1.getRelatedInstance() + .setInstanceId(vnfServiceItem.getServiceInstance().getServiceInstanceId()); + relatedInstanceListElement1.getRelatedInstance().setModelInfo(new SOModelInfo()); + relatedInstanceListElement1.getRelatedInstance().getModelInfo().setModelType("service"); + relatedInstanceListElement1.getRelatedInstance().getModelInfo() + .setModelInvariantId(vnfServiceItem.getServiceInstance().getModelInvariantId()); + for (AaiNqExtraProperty prop : vnfServiceItem.getExtraProperties().getExtraProperty()) { + if (prop.getPropertyName().equals(MODEL_NAME_PROPERTY_KEY)) { + relatedInstanceListElement1.getRelatedInstance().getModelInfo().setModelName(prop.getPropertyValue()); + } else if (prop.getPropertyName().equals(MODEL_VERSION_PROPERTY_KEY)) { + relatedInstanceListElement1.getRelatedInstance().getModelInfo() + .setModelVersion(prop.getPropertyValue()); + } else if (prop.getPropertyName().equals(MODEL_VERSION_ID_PROPERTY_KEY)) { + relatedInstanceListElement1.getRelatedInstance().getModelInfo() + .setModelVersionId(prop.getPropertyValue()); + } + } + + // VNF Item + relatedInstanceListElement2.getRelatedInstance().setInstanceId(vnfItem.getGenericVnf().getVnfId()); + relatedInstanceListElement2.getRelatedInstance().setModelInfo(new SOModelInfo()); + relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelType("vnf"); + relatedInstanceListElement2.getRelatedInstance().getModelInfo() + .setModelInvariantId(vnfItem.getGenericVnf().getModelInvariantId()); + for (AaiNqExtraProperty prop : vnfItem.getExtraProperties().getExtraProperty()) { + if (prop.getPropertyName().equals(MODEL_NAME_PROPERTY_KEY)) { + relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelName(prop.getPropertyValue()); + } else if (prop.getPropertyName().equals(MODEL_VERSION_PROPERTY_KEY)) { + relatedInstanceListElement2.getRelatedInstance().getModelInfo() + .setModelVersion(prop.getPropertyValue()); + } else if (prop.getPropertyName().equals(MODEL_VERSION_ID_PROPERTY_KEY)) { + relatedInstanceListElement2.getRelatedInstance().getModelInfo() + .setModelVersionId(prop.getPropertyValue()); + } + } + relatedInstanceListElement2.getRelatedInstance().getModelInfo() + .setModelCustomizationName(vnfItem.getGenericVnf().getVnfType() + .substring(vnfItem.getGenericVnf().getVnfType().lastIndexOf('/') + 1)); + relatedInstanceListElement2.getRelatedInstance().getModelInfo() + .setModelCustomizationId(vnfItem.getGenericVnf().getModelCustomizationId()); + + // Insert the Service Item and VNF Item + request.getRequestDetails().getRelatedInstanceList().add(relatedInstanceListElement1); + request.getRequestDetails().getRelatedInstanceList().add(relatedInstanceListElement2); + + // Request Parameters + buildRequestParameters(policy, request.getRequestDetails()); + + // Configuration Parameters + buildConfigurationParameters(policy, request.getRequestDetails()); + // Save the instance IDs for the VNF and service to static fields + // vfModuleId is not required for the create vf-module + preserveInstanceIds(vnfItem.getGenericVnf().getVnfId(), vnfServiceItem.getServiceInstance() + .getServiceInstanceId(), null); + if (logger.isDebugEnabled()) { + logger.debug("Constructed SO request: {}", Serialization.gsonPretty.toJson(request)); + } + return request; + } + + /** + * Construct SO request to delete vf-module. + * + * @param tenantItem tenant item from A&AI named-query response + * @param vnfItem vnf item from A&AI named-query response + * @param vnfServiceItem vnf service item from A&AI named-query response + * @param vfModuleItem vf module item from A&AI named-query response + * @return SO delete vf-module request + */ + private SORequest constructDeleteRequest(AaiNqInventoryResponseItem tenantItem, AaiNqInventoryResponseItem + vnfItem, AaiNqInventoryResponseItem vnfServiceItem, AaiNqInventoryResponseItem vfModuleItem) { + SORequest request = new SORequest(); + request.setOperationType(SoOperationType.DELETE_VF_MODULE); + request.setRequestDetails(new SORequestDetails()); + request.getRequestDetails().setRelatedInstanceList(null); + request.getRequestDetails().setConfigurationParameters(null); + + // cloudConfiguration + request.getRequestDetails().setCloudConfiguration(constructCloudConfiguration(tenantItem)); + // modelInfo + request.getRequestDetails().setModelInfo(constructVfModuleModelInfo(vfModuleItem)); + // requestInfo + request.getRequestDetails().setRequestInfo(constructRequestInfo()); + // Save the instance IDs for the VNF, service and vfModule to static fields + preserveInstanceIds(vnfItem.getGenericVnf().getVnfId(), vnfServiceItem.getServiceInstance() + .getServiceInstanceId(), vfModuleItem.getVfModule().getVfModuleId()); + + if (logger.isDebugEnabled()) { + logger.debug("Constructed SO request: {}", Serialization.gsonPretty.toJson(request)); + } + return request; + } + + /** + * Construct requestInfo for the SO requestDetails. + * + * @return SO request information + */ + private SORequestInfo constructRequestInfo() { + SORequestInfo soRequestInfo = new SORequestInfo(); + soRequestInfo.setSource("POLICY"); + soRequestInfo.setSuppressRollback(false); + soRequestInfo.setRequestorId("policy"); + return soRequestInfo; + } + + /** + * Construct modelInfo of the vfModule for the SO requestDetails. + * + * @param vfModuleItem vf module item from A&AI named-query response + * @return SO Model info for the vfModule + */ + private SOModelInfo constructVfModuleModelInfo(AaiNqInventoryResponseItem vfModuleItem) { + SOModelInfo soModelInfo = new SOModelInfo(); + soModelInfo.setModelType("vfModule"); + soModelInfo.setModelInvariantId(vfModuleItem.getVfModule().getModelInvariantId()); + soModelInfo.setModelCustomizationId(vfModuleItem.getVfModule().getModelCustomizationId()); + + for (AaiNqExtraProperty prop : vfModuleItem.getExtraProperties().getExtraProperty()) { + if (prop.getPropertyName().equals(MODEL_NAME_PROPERTY_KEY)) { + soModelInfo.setModelName(prop.getPropertyValue()); + } else if (prop.getPropertyName().equals(MODEL_VERSION_PROPERTY_KEY)) { + soModelInfo.setModelVersion(prop.getPropertyValue()); + } + } + return soModelInfo; + } + + /** + * Construct cloudConfiguration for the SO requestDetails. + * + * @param tenantItem tenant item from A&AI named-query response + * @return SO cloud configuration + */ + private SOCloudConfiguration constructCloudConfiguration(AaiNqInventoryResponseItem tenantItem) { + SOCloudConfiguration cloudConfiguration = new SOCloudConfiguration(); + cloudConfiguration.setTenantId(tenantItem.getTenant().getTenantId()); + cloudConfiguration.setLcpCloudRegionId(tenantItem.getItems().getInventoryResponseItems().get(0) + .getCloudRegion().getCloudRegionId()); + return cloudConfiguration; + } + + /** + * This method is needed to get the serviceInstanceId and vnfInstanceId which is used + * in the asyncSORestCall. + * + * @param requestId the request Id + * @param wm the working memory + * @param request the request + */ + public static void sendRequest(String requestId, WorkingMemory wm, Object request) { + SOManager soManager = new SOManager(); + soManager.asyncSORestCall(requestId, wm, lastServiceItemServiceInstanceId, lastVNFItemVnfId, + lastVfModuleItemVfModuleInstanceId, (SORequest) request); + } + + /** + * Find the base or non base VF module item in an AAI response. + * If there is more than one item, then the last item is returned + * + * @param aaiResponseWrapper the AAI response containing the VF modules + * @param baseFlag true if we are searching for the base, false if we are searching + * for the non base + * @return the base or non base VF module item or null if the module was not found + */ + private AaiNqInventoryResponseItem findVfModule(AaiNqResponseWrapper aaiResponseWrapper, boolean baseFlag) { + List lst = aaiResponseWrapper.getVfModuleItems(baseFlag); + return (lst.isEmpty() ? null : lst.get(lst.size() - 1)); + } + + /** + * Builds the request parameters from the policy payload. + * + * @param policy the policy + * @param request request into which to stick the request parameters + */ + private void buildRequestParameters(Policy policy, SORequestDetails request) { + // assume null until proven otherwise + request.setRequestParameters(null); + + if (policy.getPayload() == null) { + return; + } + + String json = policy.getPayload().get(REQ_PARAM_NM); + if (json == null) { + return; + } + + request.setRequestParameters(Serialization.gsonPretty.fromJson(json, SORequestParameters.class)); + } + + /** + * Builds the configuration parameters from the policy payload. + * + * @param policy the policy + * @param request request into which to stick the configuration parameters + */ + private void buildConfigurationParameters(Policy policy, SORequestDetails request) { + // assume null until proven otherwise + request.setConfigurationParameters(null); + + if (policy.getPayload() == null) { + return; + } + + String json = policy.getPayload().get(CONFIG_PARAM_NM); + if (json == null) { + return; + } + + request.setConfigurationParameters(Serialization.gsonPretty.fromJson(json, CONFIG_TYPE)); + } + + /** + * This method is called to remember the last service instance ID, VNF Item VNF ID and vf module ID. + * Note these fields are static, beware for multithreaded deployments + * + * @param vnfInstanceId update the last VNF instance ID to this value + * @param serviceInstanceId update the last service instance ID to this value + * @param vfModuleId update the vfModule instance ID to this value + */ + private static void preserveInstanceIds(final String vnfInstanceId, final String serviceInstanceId, + final String vfModuleId) { + lastVNFItemVnfId = vnfInstanceId; + lastServiceItemServiceInstanceId = serviceInstanceId; + lastVfModuleItemVfModuleInstanceId = vfModuleId; + } +} 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 index ad136e98f..a955eb71c 100644 --- 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 @@ -1 +1 @@ -org.onap.policy.controlloop.actor.so.SOActorServiceProvider \ No newline at end of file +org.onap.policy.controlloop.actor.so.SoActorServiceProvider \ No newline at end of file diff --git a/controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java b/controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java index 9c1d87888..90a4c2868 100644 --- a/controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java +++ b/controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java @@ -63,15 +63,15 @@ public class SoActorServiceProviderTest { policy.setActor("Dorothy"); policy.setRecipe("GoToOz"); - assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp)); + assertNull(new SoActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp)); policy.setActor("SO"); - assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp)); + assertNull(new SoActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp)); policy.setRecipe(VF_MODULE_CREATE); // empty policy payload - SORequest request = new SOActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp); + SORequest request = new SoActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp); assertNotNull(request); assertEquals("my_module_3", request.getRequestDetails().getRequestInfo().getInstanceName()); @@ -80,7 +80,7 @@ public class SoActorServiceProviderTest { // non-empty policy payload policy.setPayload(makePayload()); - request = new SOActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp); + request = new SoActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp); assertNotNull(request); assertEquals(true, request.getRequestDetails().getRequestParameters().isUsePreload()); assertEquals("avalue", request.getRequestDetails().getRequestParameters().getUserParams().get(0).get("akey")); @@ -89,33 +89,33 @@ public class SoActorServiceProviderTest { // payload with config, but no request params policy.setPayload(makePayload()); - policy.getPayload().remove(SOActorServiceProvider.REQ_PARAM_NM); - request = new SOActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp); + policy.getPayload().remove(SoActorServiceProvider.REQ_PARAM_NM); + request = new SoActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp); assertNotNull(request); assertNull(request.getRequestDetails().getRequestParameters()); assertNotNull(request.getRequestDetails().getConfigurationParameters()); // payload with request, but no config params policy.setPayload(makePayload()); - policy.getPayload().remove(SOActorServiceProvider.CONFIG_PARAM_NM); - request = new SOActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp); + policy.getPayload().remove(SoActorServiceProvider.CONFIG_PARAM_NM); + request = new SoActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp); assertNotNull(request); assertNotNull(request.getRequestDetails().getRequestParameters()); assertNull(request.getRequestDetails().getConfigurationParameters()); // null response - assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy, null)); + assertNull(new SoActorServiceProvider().constructRequest(onset, operation, policy, null)); // response has no base VF module - assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy, + assertNull(new SoActorServiceProvider().constructRequest(onset, operation, policy, loadAaiResponse(onset, "aai/AaiNqResponse-NoBase.json"))); // response has no non-base VF modules (other than the "dummy") - assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy, + assertNull(new SoActorServiceProvider().constructRequest(onset, operation, policy, loadAaiResponse(onset, "aai/AaiNqResponse-NoNonBase.json"))); policy.setRecipe(VF_MODULE_DELETE); - SORequest deleteRequest = new SOActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp); + SORequest deleteRequest = new SoActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp); assertNotNull(deleteRequest); assertEquals(SoOperationType.DELETE_VF_MODULE, deleteRequest.getOperationType()); @@ -128,22 +128,22 @@ public class SoActorServiceProviderTest { // null tenant aaiNqResp.getAaiNqResponse().getInventoryResponseItems().get(0).getItems().getInventoryResponseItems() .remove(1); - assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp)); + assertNull(new SoActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp)); // null service item aaiNqResp.getAaiNqResponse().getInventoryResponseItems().get(0).getItems().getInventoryResponseItems().get(0) .setItems(null); - assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp)); + assertNull(new SoActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp)); // null response aaiNqResp.setAaiNqResponse(null); - assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp)); + assertNull(new SoActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp)); } @Test public void testSendRequest() { try { - SOActorServiceProvider.sendRequest(UUID.randomUUID().toString(), null, null); + SoActorServiceProvider.sendRequest(UUID.randomUUID().toString(), null, null); } catch (Exception e) { fail("Test should not throw an exception"); } @@ -151,7 +151,7 @@ public class SoActorServiceProviderTest { @Test public void testMethods() { - SOActorServiceProvider sp = new SOActorServiceProvider(); + SoActorServiceProvider sp = new SoActorServiceProvider(); assertEquals("SO", sp.actor()); assertEquals(2, sp.recipes().size()); @@ -170,8 +170,8 @@ public class SoActorServiceProviderTest { private Map makePayload() { Map payload = new TreeMap<>(); - payload.put(SOActorServiceProvider.REQ_PARAM_NM, makeReqParams()); - payload.put(SOActorServiceProvider.CONFIG_PARAM_NM, makeConfigParams()); + payload.put(SoActorServiceProvider.REQ_PARAM_NM, makeReqParams()); + payload.put(SoActorServiceProvider.CONFIG_PARAM_NM, makeConfigParams()); return payload; } diff --git a/controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java b/controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java deleted file mode 100644 index b8aaf854a..000000000 --- a/controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java +++ /dev/null @@ -1,150 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2017-2018 Intel Corp. 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.vfc; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - -import java.util.Collections; -import java.util.List; -import java.util.UUID; - -import org.onap.policy.aai.AaiGetVnfResponse; -import org.onap.policy.aai.AaiManager; -import org.onap.policy.controlloop.ControlLoopOperation; -import org.onap.policy.controlloop.VirtualControlLoopEvent; -import org.onap.policy.controlloop.actorserviceprovider.spi.Actor; -import org.onap.policy.controlloop.policy.Policy; -import org.onap.policy.drools.system.PolicyEngine; -import org.onap.policy.rest.RESTManager; -import org.onap.policy.vfc.VFCHealActionVmInfo; -import org.onap.policy.vfc.VFCHealAdditionalParams; -import org.onap.policy.vfc.VFCHealRequest; -import org.onap.policy.vfc.VFCRequest; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class VFCActorServiceProvider implements Actor { - private static final Logger logger = LoggerFactory.getLogger(VFCActorServiceProvider.class); - - // Strings for VFC Actor - private static final String VFC_ACTOR = "VFC"; - - // Strings for targets - private static final String TARGET_VM = "VM"; - - // Strings for recipes - private static final String RECIPE_RESTART = "Restart"; - - private static final ImmutableList recipes = ImmutableList.of(RECIPE_RESTART); - private static final ImmutableMap> targets = - new ImmutableMap.Builder>().put(RECIPE_RESTART, ImmutableList.of(TARGET_VM)).build(); - - @Override - public String actor() { - return VFC_ACTOR; - } - - @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(); - } - - /** - * Construct a request. - * - * @param onset the onset event - * @param operation the control loop operation - * @param policy the policy - * @param vnfResponse the VNF response - * @return the constructed request - */ - public static VFCRequest constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation, - Policy policy, AaiGetVnfResponse vnfResponse) { - - // Construct an VFC request - VFCRequest request = new VFCRequest(); - String serviceInstance = onset.getAai().get("service-instance.service-instance-id"); - if (serviceInstance == null || "".equals(serviceInstance)) { - AaiGetVnfResponse tempVnfResp = vnfResponse; - if (tempVnfResp == null) { // if the response is null, we haven't queried - // This does the AAI query since we haven't already - tempVnfResp = getAaiServiceInstance(onset); - if (tempVnfResp == null) { - return null; - } - } - serviceInstance = tempVnfResp.getServiceId(); - } - request.setNSInstanceId(serviceInstance); - request.setRequestId(onset.getRequestId()); - request.setHealRequest(new VFCHealRequest()); - request.getHealRequest().setVnfInstanceId(onset.getAai().get("generic-vnf.vnf-id")); - request.getHealRequest().setCause(operation.getMessage()); - request.getHealRequest().setAdditionalParams(new VFCHealAdditionalParams()); - - if (policy.getRecipe().toLowerCase().equalsIgnoreCase(RECIPE_RESTART)) { - request.getHealRequest().getAdditionalParams().setAction("restartvm"); - request.getHealRequest().getAdditionalParams().setActionInfo(new VFCHealActionVmInfo()); - request.getHealRequest().getAdditionalParams().getActionInfo() - .setVmid(onset.getAai().get("vserver.vserver-id")); - request.getHealRequest().getAdditionalParams().getActionInfo() - .setVmname(onset.getAai().get("vserver.vserver-name")); - } else { - return null; - } - return request; - } - - private static AaiGetVnfResponse getAaiServiceInstance(VirtualControlLoopEvent event) { - AaiGetVnfResponse response = null; - UUID requestId = event.getRequestId(); - String vnfName = event.getAai().get("generic-vnf.vnf-name"); - String vnfId = event.getAai().get("generic-vnf.vnf-id"); - String aaiUrl = PolicyEngine.manager.getEnvironmentProperty("aai.url"); - String aaiUsername = PolicyEngine.manager.getEnvironmentProperty("aai.username"); - String aaiPassword = PolicyEngine.manager.getEnvironmentProperty("aai.password"); - try { - if (vnfName != null) { - String url = aaiUrl + "/aai/v11/network/generic-vnfs/generic-vnf?vnf-name="; - response = new AaiManager(new RESTManager()).getQueryByVnfName(url, aaiUsername, aaiPassword, requestId, - vnfName); - } else if (vnfId != null) { - String url = aaiUrl + "/aai/v11/network/generic-vnfs/generic-vnf/"; - response = new AaiManager(new RESTManager()).getQueryByVnfId(url, aaiUsername, aaiPassword, requestId, - vnfId); - } else { - logger.error("getAAIServiceInstance failed"); - } - } catch (Exception e) { - logger.error("getAAIServiceInstance exception: ", e); - } - return response; - } -} diff --git a/controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcActorServiceProvider.java b/controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcActorServiceProvider.java new file mode 100644 index 000000000..8660aa3e2 --- /dev/null +++ b/controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VfcActorServiceProvider.java @@ -0,0 +1,151 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2017-2018 Intel Corp. All rights reserved. + * Modifications Copyright (C) 2018 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.vfc; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; + +import java.util.Collections; +import java.util.List; +import java.util.UUID; + +import org.onap.policy.aai.AaiGetVnfResponse; +import org.onap.policy.aai.AaiManager; +import org.onap.policy.controlloop.ControlLoopOperation; +import org.onap.policy.controlloop.VirtualControlLoopEvent; +import org.onap.policy.controlloop.actorserviceprovider.spi.Actor; +import org.onap.policy.controlloop.policy.Policy; +import org.onap.policy.drools.system.PolicyEngine; +import org.onap.policy.rest.RESTManager; +import org.onap.policy.vfc.VFCHealActionVmInfo; +import org.onap.policy.vfc.VFCHealAdditionalParams; +import org.onap.policy.vfc.VFCHealRequest; +import org.onap.policy.vfc.VFCRequest; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class VfcActorServiceProvider implements Actor { + private static final Logger logger = LoggerFactory.getLogger(VfcActorServiceProvider.class); + + // Strings for VFC Actor + private static final String VFC_ACTOR = "VFC"; + + // Strings for targets + private static final String TARGET_VM = "VM"; + + // Strings for recipes + private static final String RECIPE_RESTART = "Restart"; + + private static final ImmutableList recipes = ImmutableList.of(RECIPE_RESTART); + private static final ImmutableMap> targets = + new ImmutableMap.Builder>().put(RECIPE_RESTART, ImmutableList.of(TARGET_VM)).build(); + + @Override + public String actor() { + return VFC_ACTOR; + } + + @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(); + } + + /** + * Construct a request. + * + * @param onset the onset event + * @param operation the control loop operation + * @param policy the policy + * @param vnfResponse the VNF response + * @return the constructed request + */ + public static VFCRequest constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation, + Policy policy, AaiGetVnfResponse vnfResponse) { + + // Construct an VFC request + VFCRequest request = new VFCRequest(); + String serviceInstance = onset.getAai().get("service-instance.service-instance-id"); + if (serviceInstance == null || "".equals(serviceInstance)) { + AaiGetVnfResponse tempVnfResp = vnfResponse; + if (tempVnfResp == null) { // if the response is null, we haven't queried + // This does the AAI query since we haven't already + tempVnfResp = getAaiServiceInstance(onset); + if (tempVnfResp == null) { + return null; + } + } + serviceInstance = tempVnfResp.getServiceId(); + } + request.setNSInstanceId(serviceInstance); + request.setRequestId(onset.getRequestId()); + request.setHealRequest(new VFCHealRequest()); + request.getHealRequest().setVnfInstanceId(onset.getAai().get("generic-vnf.vnf-id")); + request.getHealRequest().setCause(operation.getMessage()); + request.getHealRequest().setAdditionalParams(new VFCHealAdditionalParams()); + + if (policy.getRecipe().toLowerCase().equalsIgnoreCase(RECIPE_RESTART)) { + request.getHealRequest().getAdditionalParams().setAction("restartvm"); + request.getHealRequest().getAdditionalParams().setActionInfo(new VFCHealActionVmInfo()); + request.getHealRequest().getAdditionalParams().getActionInfo() + .setVmid(onset.getAai().get("vserver.vserver-id")); + request.getHealRequest().getAdditionalParams().getActionInfo() + .setVmname(onset.getAai().get("vserver.vserver-name")); + } else { + return null; + } + return request; + } + + private static AaiGetVnfResponse getAaiServiceInstance(VirtualControlLoopEvent event) { + AaiGetVnfResponse response = null; + UUID requestId = event.getRequestId(); + String vnfName = event.getAai().get("generic-vnf.vnf-name"); + String vnfId = event.getAai().get("generic-vnf.vnf-id"); + String aaiUrl = PolicyEngine.manager.getEnvironmentProperty("aai.url"); + String aaiUsername = PolicyEngine.manager.getEnvironmentProperty("aai.username"); + String aaiPassword = PolicyEngine.manager.getEnvironmentProperty("aai.password"); + try { + if (vnfName != null) { + String url = aaiUrl + "/aai/v11/network/generic-vnfs/generic-vnf?vnf-name="; + response = new AaiManager(new RESTManager()).getQueryByVnfName(url, aaiUsername, aaiPassword, requestId, + vnfName); + } else if (vnfId != null) { + String url = aaiUrl + "/aai/v11/network/generic-vnfs/generic-vnf/"; + response = new AaiManager(new RESTManager()).getQueryByVnfId(url, aaiUsername, aaiPassword, requestId, + vnfId); + } else { + logger.error("getAAIServiceInstance failed"); + } + } catch (Exception e) { + logger.error("getAAIServiceInstance exception: ", e); + } + return response; + } +} diff --git a/controlloop/common/actors/actor.vfc/src/main/resources/META-INF/services/org.onap.policy.controlloop.actorServiceProvider.spi.Actor b/controlloop/common/actors/actor.vfc/src/main/resources/META-INF/services/org.onap.policy.controlloop.actorServiceProvider.spi.Actor index 1476eac1d..e43c726cf 100644 --- a/controlloop/common/actors/actor.vfc/src/main/resources/META-INF/services/org.onap.policy.controlloop.actorServiceProvider.spi.Actor +++ b/controlloop/common/actors/actor.vfc/src/main/resources/META-INF/services/org.onap.policy.controlloop.actorServiceProvider.spi.Actor @@ -1 +1 @@ -org.onap.policy.controlloop.actor.vfc.VFCActorServiceProvider +org.onap.policy.controlloop.actor.vfc.VfcActorServiceProvider diff --git a/controlloop/common/actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/VfcActorServiceProviderTest.java b/controlloop/common/actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/VfcActorServiceProviderTest.java index 934ea134c..02387b641 100644 --- a/controlloop/common/actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/VfcActorServiceProviderTest.java +++ b/controlloop/common/actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/VfcActorServiceProviderTest.java @@ -68,37 +68,37 @@ public class VfcActorServiceProviderTest { Policy policy = new Policy(); policy.setRecipe("GoToOz"); - assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, null)); + assertNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, null)); onset.getAai().put("generic-vnf.vnf-id", "dorothy.gale.1939"); - assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, null)); + assertNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, null)); PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666"); PolicyEngine.manager.setEnvironmentProperty("aai.username", "AAI"); PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI"); - assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, null)); + assertNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, null)); UUID requestId = UUID.randomUUID(); onset.setRequestId(requestId); - assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, null)); + assertNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, null)); onset.getAai().put("generic-vnf.vnf-name", "Dorothy"); PolicyEngine.manager.getEnvironment().remove("aai.password"); - assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, null)); + assertNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, null)); PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI"); - assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, null)); + assertNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, null)); onset.getAai().put("service-instance.service-instance-id", ""); - assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, null)); + assertNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, null)); - assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, new AaiGetVnfResponse())); + assertNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, new AaiGetVnfResponse())); policy.setRecipe("Restart"); - assertNotNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, new AaiGetVnfResponse())); + assertNotNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, new AaiGetVnfResponse())); VFCRequest request = - VFCActorServiceProvider.constructRequest(onset, operation, policy, new AaiGetVnfResponse()); + VfcActorServiceProvider.constructRequest(onset, operation, policy, new AaiGetVnfResponse()); assertEquals(requestId, Objects.requireNonNull(request).getRequestId()); assertEquals("dorothy.gale.1939", request.getHealRequest().getVnfInstanceId()); @@ -107,7 +107,7 @@ public class VfcActorServiceProviderTest { @Test public void testMethods() { - VFCActorServiceProvider sp = new VFCActorServiceProvider(); + VfcActorServiceProvider sp = new VfcActorServiceProvider(); assertEquals("VFC", sp.actor()); assertEquals(1, sp.recipes().size()); diff --git a/controlloop/common/eventmanager/checkstyle-suppressions.xml b/controlloop/common/eventmanager/checkstyle-suppressions.xml new file mode 100644 index 000000000..1bb593962 --- /dev/null +++ b/controlloop/common/eventmanager/checkstyle-suppressions.xml @@ -0,0 +1,33 @@ + + + + + + + + + diff --git a/controlloop/common/eventmanager/pom.xml b/controlloop/common/eventmanager/pom.xml index 6897317d5..e14d62ffc 100644 --- a/controlloop/common/eventmanager/pom.xml +++ b/controlloop/common/eventmanager/pom.xml @@ -205,4 +205,44 @@ test + + + + maven-checkstyle-plugin + + + onap-java-style + + check + + process-sources + + + onap-checkstyle/onap-java-style.xml + + ${project.build.sourceDirectory}/src/main/java + true + true + true + + + true + true + warning + + + + + + org.onap.oparent + checkstyle + ${oparent.version} + compile + + + + + diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java index 93535efc1..5241bd2fc 100644 --- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java +++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java @@ -29,8 +29,8 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.UUID; import java.util.NoSuchElementException; +import java.util.UUID; import org.onap.policy.aai.AaiGetVnfResponse; import org.onap.policy.aai.AaiGetVserverResponse; @@ -91,7 +91,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable { private static final long serialVersionUID = -1216568161322872641L; public final String closedLoopControlName; - public final UUID requestID; + private final UUID requestId; private String controlLoopResult; private ControlLoopProcessor processor = null; @@ -125,9 +125,9 @@ public class ControlLoopEventManager implements LockCallback, Serializable { requiredAAIKeys.add(VM_NAME); } - public ControlLoopEventManager(String closedLoopControlName, UUID requestID) { + public ControlLoopEventManager(String closedLoopControlName, UUID requestId) { this.closedLoopControlName = closedLoopControlName; - this.requestID = requestID; + this.requestId = requestId; } public String getClosedLoopControlName() { @@ -187,7 +187,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable { } public UUID getRequestID() { - return requestID; + return requestId; } /** @@ -499,7 +499,8 @@ public class ControlLoopEventManager implements LockCallback, Serializable { this.currentOperation.getTargetEntity(), this.onset.getRequestId(), this); this.targetLock = lock; - LockResult lockResult = LockResult.createLockResult(GuardResult.LOCK_ACQUIRED, lock); + LockResult lockResult = + LockResult.createLockResult(GuardResult.LOCK_ACQUIRED, lock); return lockResult; } // @@ -637,7 +638,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable { logger.error("{}: commitAbatement: no operation manager", this); return; } - try{ + try { this.lastOperationManager.commitAbatement(message,outcome); } catch (NoSuchElementException e) { logger.error("{}: commitAbatement threw an exception ", this, e); @@ -1027,7 +1028,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable { @Override public String toString() { - return "ControlLoopEventManager [closedLoopControlName=" + closedLoopControlName + ", requestID=" + requestID + return "ControlLoopEventManager [closedLoopControlName=" + closedLoopControlName + ", requestId=" + requestId + ", processor=" + processor + ", onset=" + (onset != null ? onset.getRequestId() : "null") + ", numOnsets=" + numOnsets + ", numAbatements=" + numAbatements + ", isActivated=" + isActivated + ", currentOperation=" + currentOperation + ", targetLock=" + targetLock + "]"; 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 466c826b1..c5344e38b 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 @@ -41,11 +41,11 @@ import org.onap.policy.controlloop.ControlLoopEvent; import org.onap.policy.controlloop.ControlLoopException; import org.onap.policy.controlloop.ControlLoopOperation; import org.onap.policy.controlloop.VirtualControlLoopEvent; -import org.onap.policy.controlloop.actor.appc.APPCActorServiceProvider; +import org.onap.policy.controlloop.actor.appc.AppcActorServiceProvider; import org.onap.policy.controlloop.actor.appclcm.AppcLcmActorServiceProvider; import org.onap.policy.controlloop.actor.sdnr.SdnrActorServiceProvider; -import org.onap.policy.controlloop.actor.so.SOActorServiceProvider; -import org.onap.policy.controlloop.actor.vfc.VFCActorServiceProvider; +import org.onap.policy.controlloop.actor.so.SoActorServiceProvider; +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.drools.system.PolicyEngine; @@ -258,7 +258,7 @@ public class ControlLoopOperationManager implements Serializable { */ this.currentOperation = operation; if ("ModifyConfig".equalsIgnoreCase(policy.getRecipe())) { - this.operationRequest = APPCActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset, + this.operationRequest = AppcActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset, operation.clOperation, this.policy, this.targetEntity); } else { this.operationRequest = AppcLcmActorServiceProvider.constructRequest( @@ -270,7 +270,7 @@ public class ControlLoopOperationManager implements Serializable { return operationRequest; case "SO": - SOActorServiceProvider soActorSp = new SOActorServiceProvider(); + SoActorServiceProvider soActorSp = new SoActorServiceProvider(); this.operationRequest = soActorSp.constructRequest((VirtualControlLoopEvent) onset, operation.clOperation, this.policy, eventManager.getNqVserverFromAai()); @@ -283,7 +283,7 @@ public class ControlLoopOperationManager implements Serializable { return operationRequest; case "VFC": - this.operationRequest = VFCActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset, + this.operationRequest = VfcActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset, operation.clOperation, this.policy, this.eventManager.getVnfResponse()); this.currentOperation = operation; if (this.operationRequest == null) { @@ -935,5 +935,5 @@ public class ControlLoopOperationManager implements Serializable { // Clear the current operation field // this.currentOperation = null; - } + } } diff --git a/controlloop/common/feature-controlloop-trans/checkstyle-suppressions.xml b/controlloop/common/feature-controlloop-trans/checkstyle-suppressions.xml new file mode 100644 index 000000000..f4ceebd66 --- /dev/null +++ b/controlloop/common/feature-controlloop-trans/checkstyle-suppressions.xml @@ -0,0 +1,30 @@ + + + + + + + + diff --git a/controlloop/common/feature-controlloop-trans/pom.xml b/controlloop/common/feature-controlloop-trans/pom.xml index 05bc4f8e7..2e609d0ed 100644 --- a/controlloop/common/feature-controlloop-trans/pom.xml +++ b/controlloop/common/feature-controlloop-trans/pom.xml @@ -61,7 +61,6 @@ - org.apache.maven.plugins maven-dependency-plugin @@ -85,6 +84,42 @@ + + maven-checkstyle-plugin + + + onap-java-style + + check + + process-sources + + + onap-checkstyle/onap-java-style.xml + + ${project.build.sourceDirectory}/src/main/java + true + true + true + + + true + true + warning + + + + + + org.onap.oparent + checkstyle + ${oparent.version} + compile + + + diff --git a/controlloop/common/feature-controlloop-trans/src/main/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetricsFeature.java b/controlloop/common/feature-controlloop-trans/src/main/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetricsFeature.java index f1d577d43..259925324 100644 --- a/controlloop/common/feature-controlloop-trans/src/main/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetricsFeature.java +++ b/controlloop/common/feature-controlloop-trans/src/main/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetricsFeature.java @@ -65,7 +65,7 @@ public class ControlLoopMetricsFeature implements PolicyControllerFeatureAPI { * @param protocol - protocol * @param topic - topic * @param event - event object - * @return + * @return false do not take ownership else true */ @Override public boolean beforeDeliver(PolicyController controller, CommInfrastructure protocol, String topic, Object event) { diff --git a/controlloop/common/guard/checkstyle-suppressions.xml b/controlloop/common/guard/checkstyle-suppressions.xml new file mode 100644 index 000000000..9b071df87 --- /dev/null +++ b/controlloop/common/guard/checkstyle-suppressions.xml @@ -0,0 +1,30 @@ + + + + + + + + diff --git a/controlloop/common/guard/pom.xml b/controlloop/common/guard/pom.xml index a3ecf961f..08e403e41 100644 --- a/controlloop/common/guard/pom.xml +++ b/controlloop/common/guard/pom.xml @@ -107,4 +107,44 @@ test + + + + maven-checkstyle-plugin + + + onap-java-style + + check + + process-sources + + + onap-checkstyle/onap-java-style.xml + + ${project.build.sourceDirectory}/src/main/java + true + true + true + + + true + true + warning + + + + + + org.onap.oparent + checkstyle + ${oparent.version} + compile + + + + + diff --git a/controlloop/common/guard/src/main/java/org/onap/policy/guard/CallGuardTask.java b/controlloop/common/guard/src/main/java/org/onap/policy/guard/CallGuardTask.java index 146f42170..59a1816b7 100644 --- a/controlloop/common/guard/src/main/java/org/onap/policy/guard/CallGuardTask.java +++ b/controlloop/common/guard/src/main/java/org/onap/policy/guard/CallGuardTask.java @@ -20,6 +20,8 @@ package org.onap.policy.guard; +import com.att.research.xacml.api.DataTypeException; +import com.att.research.xacml.std.annotations.RequestParser; import java.util.HashSet; import java.util.Set; import java.util.UUID; @@ -27,8 +29,6 @@ import java.util.function.Supplier; import org.drools.core.WorkingMemory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.att.research.xacml.api.DataTypeException; -import com.att.research.xacml.std.annotations.RequestParser; public class CallGuardTask implements Runnable { @@ -36,14 +36,14 @@ public class CallGuardTask implements Runnable { /** * Actor/recipe pairs whose guard requests need a VF Module count. Each element is of - * the form ":". + * the form "<actor>:<recipe>". */ private static final Set NEEDS_VF_COUNT = new HashSet<>(); /** * Actor/recipe pairs whose guard requests need the VF Module count to be incremented * (i.e., because a module is being added). Each element is of the form - * ":". + * "<actor>:<recipe>". */ private static final Set INCR_VF_COUNT = new HashSet<>(); @@ -69,7 +69,8 @@ public class CallGuardTask implements Runnable { /** * Guard url is grabbed from PolicyEngine.manager properties */ - public CallGuardTask(WorkingMemory wm, String cl, String act, String rec, String tar, String reqId, Supplier vfcnt) { + public CallGuardTask(WorkingMemory wm, String cl, String act, + String rec, String tar, String reqId, Supplier vfcnt) { workingMemory = wm; clname = cl; actor = act; diff --git a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PipEngineGetStatus.java b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PipEngineGetStatus.java index 40b26c847..36bb36f5c 100644 --- a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PipEngineGetStatus.java +++ b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PipEngineGetStatus.java @@ -39,14 +39,12 @@ import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; -import java.util.List; import java.util.Properties; import java.util.Set; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.NoResultException; -import javax.persistence.NonUniqueResultException; import javax.persistence.Persistence; import javax.persistence.Query; @@ -66,26 +64,12 @@ public class PipEngineGetStatus extends StdConfigurableEngine { private static final String XML_SCHEMA_STRING = "http://www.w3.org/2001/XMLSchema#string"; - private static final String XACML_SUBJECT_CATEGORY_ACCESS_SUBJECT = - "urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"; - private static final String XACML_ACTOR_ACTOR_ID = "urn:oasis:names:tc:xacml:1.0:actor:actor-id"; - private static final String XACML_ATTRIBUTE_CATEGORY_ACTION = - "urn:oasis:names:tc:xacml:3.0:attribute-category:action"; - private static final String XACML_OPERATION_OPERATION_ID = "urn:oasis:names:tc:xacml:1.0:operation:operation-id"; private static final String XACML_ATTRIBUTE_CATEGORY_RESOURCE = "urn:oasis:names:tc:xacml:3.0:attribute-category:resource"; private static final String XACML_TARGET_TARGET_ID = "urn:oasis:names:tc:xacml:1.0:target:target-id"; private static final String XACML_TEST_SQL_RESOURCE_OPERATIONS_STATUS = "com:att:research:xacml:test:sql:resource:operations:status"; - private static final PIPRequest PIP_REQUEST_ACTOR = - new StdPIPRequest(new IdentifierImpl(XACML_SUBJECT_CATEGORY_ACCESS_SUBJECT), - new IdentifierImpl(XACML_ACTOR_ACTOR_ID), new IdentifierImpl(XML_SCHEMA_STRING)); - - private static final PIPRequest PIP_REQUEST_RECIPE = - new StdPIPRequest(new IdentifierImpl(XACML_ATTRIBUTE_CATEGORY_ACTION), - new IdentifierImpl(XACML_OPERATION_OPERATION_ID), new IdentifierImpl(XML_SCHEMA_STRING)); - private static final PIPRequest PIP_REQUEST_TARGET = new StdPIPRequest(new IdentifierImpl(XACML_ATTRIBUTE_CATEGORY_RESOURCE), new IdentifierImpl(XACML_TARGET_TARGET_ID), new IdentifierImpl(XML_SCHEMA_STRING)); @@ -121,7 +105,7 @@ public class PipEngineGetStatus extends StdConfigurableEngine { } else if (!issuer.contains(this.getIssuer())) { // Notice, we are checking here for the base issuer prefix. logger.debug("Requested issuer '{}' does not match {}", issuer, getIssuer()); - logger.debug("Status PIP - Issuer {} does not match with: ", issuer, this.getIssuer()); + logger.debug("Status PIP - Issuer {} does not match with: {}", issuer, this.getIssuer()); return StdPIPResponse.PIP_RESPONSE_EMPTY; } @@ -282,13 +266,13 @@ public class PipEngineGetStatus extends StdConfigurableEngine { // Run the query // String ret = null; - try{ + try { ret = ((String)nq.getSingleResult()); - } catch(NoResultException ex) { + } catch (NoResultException ex) { logger.debug("NoResultException for getSingleResult()"); ret = "NO_MATCHING_ENTRY"; - } catch(Exception ex){ - logger.error("getStatusFromDB threw: ", ex); + } catch (Exception ex) { + logger.error("getStatusFromDB threw an exception", ex); } if (ret != null) { logger.debug("SQL query result: {}", ret); @@ -298,13 +282,13 @@ public class PipEngineGetStatus extends StdConfigurableEngine { // try { em.close(); - } catch(Exception ex){ - logger.error("getStatusFromDB threw: ", ex); + } catch (Exception ex) { + logger.error("getStatusFromDB threw an exception ", ex); } try { emf.close(); - } catch(Exception ex){ - logger.error("getStatusFromDB threw: ", ex); + } catch (Exception ex) { + logger.error("getStatusFromDB threw an exception ", ex); } return ret; } diff --git a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuard.java b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuard.java index a7b4f73f2..865a442b9 100644 --- a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuard.java +++ b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuard.java @@ -85,28 +85,28 @@ public class PolicyGuard { * * @param targetType the target type * @param targetInstance the target instance - * @param requestID the request Id + * @param requestId the request Id * @return the TargetLock * @throws IllegalArgumentException if an argument is null */ public static TargetLock createTargetLock(TargetType targetType, String targetInstance, - UUID requestID, LockCallback callback) { + UUID requestId, LockCallback callback) { switch (targetType) { case PNF: // // Create the Lock object // - return new PNFTargetLock(targetType, targetInstance, requestID, callback); + return new PNFTargetLock(targetType, targetInstance, requestId, callback); case VM: // // Create the Lock object // - return new VMTargetLock(targetType, targetInstance, requestID, callback); + return new VMTargetLock(targetType, targetInstance, requestId, callback); case VNF: // // Create the Lock object // - return new VNFTargetLock(targetType, targetInstance, requestID, callback); + return new VNFTargetLock(targetType, targetInstance, requestId, callback); default: logger.error("invalid target type {} for lock on {}", targetType, targetInstance); return null; @@ -118,21 +118,21 @@ public class PolicyGuard { * * @param targetType the target type * @param targetInstance the target instance - * @param requestID the request Id + * @param requestId the request Id * @param callback the LockCallback * @param holdSec maximum number of seconds to hold the lock * @return the LockResult * @throws IllegalArgumentException if an argument is null */ public static LockResult lockTarget(TargetType targetType, String targetInstance, - UUID requestID, LockCallback callback, int holdSec) { - String owner = makeOwner(targetType, requestID); + UUID requestId, LockCallback callback, int holdSec) { + String owner = makeOwner(targetType, requestId); boolean result = factory.getManager().lock(targetInstance, owner, holdSec); if (!result) { return LockResult.createLockResult(GuardResult.LOCK_DENIED, null); } - TargetLock lock = createTargetLock(targetType, targetInstance, requestID, callback); + TargetLock lock = createTargetLock(targetType, targetInstance, requestId, callback); if (lock == null) { // // Bad lock type: unlock and return exception result @@ -188,12 +188,12 @@ public class PolicyGuard { * * @param targetType the target type * @param targetInstance the target instance - * @param requestID the request Id + * @param requestId the request Id * @return true if the target is locked, false otherwise * @throws IllegalArgumentException if an argument is null */ - public static boolean isLocked(TargetType targetType, String targetInstance, UUID requestID) { - String owner = makeOwner(targetType, requestID); + public static boolean isLocked(TargetType targetType, String targetInstance, UUID requestId) { + String owner = makeOwner(targetType, requestId); return factory.getManager().isLockedBy(targetInstance, owner); } @@ -204,16 +204,16 @@ public class PolicyGuard { * @return the "owner" of a resource * @throws IllegalArgumentException if either argument is null */ - private static String makeOwner(TargetType targetType, UUID requestID) { + private static String makeOwner(TargetType targetType, UUID requestId) { if (targetType == null) { - throw new IllegalArgumentException("null targetType for lock request id " + requestID); + throw new IllegalArgumentException("null targetType for lock request id " + requestId); } - if (requestID == null) { + if (requestId == null) { throw new IllegalArgumentException("null requestID for lock type " + targetType); } - return targetType + ":" + requestID; + return targetType + ":" + requestId; } /** diff --git a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardRequest.java b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardRequest.java index bca31d904..5cb080fa5 100644 --- a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardRequest.java +++ b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardRequest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * guard * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -33,14 +33,14 @@ public class PolicyGuardRequest { * * @param actor the actor * @param target the target - * @param requestID the request Id + * @param requestId the request Id * @param operation the operation */ - public PolicyGuardRequest(String actor, String target, UUID requestID, String operation) { + public PolicyGuardRequest(String actor, String target, UUID requestId, String operation) { super(); this.actor = actor; this.target = target; - this.requestId = requestID; + this.requestId = requestId; this.operation = operation; } @@ -70,8 +70,8 @@ public class PolicyGuardRequest { return requestId; } - public void setRequestID(UUID requestID) { - this.requestId = requestID; + public void setRequestID(UUID requestId) { + this.requestId = requestId; } public String getOperation() { diff --git a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardResponse.java b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardResponse.java index e9ff435f8..d7ece3081 100644 --- a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardResponse.java +++ b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardResponse.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * guard * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -49,8 +49,8 @@ public class PolicyGuardResponse { return requestId; } - public void setRequestID(UUID requestID) { - this.requestId = requestID; + public void setRequestID(UUID requestId) { + this.requestId = requestId; } public String getResult() { diff --git a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardXacmlHelper.java b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardXacmlHelper.java index 53ba6075e..ec4ebf9cd 100644 --- a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardXacmlHelper.java +++ b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardXacmlHelper.java @@ -115,7 +115,7 @@ public class PolicyGuardXacmlHelper { UrlEntry urlEntry = restUrls[restUrlIndex]; String jsonRequestString = jsonReq.toString(); netLogger.info("[OUT|{}|{}|]{}{}", "GUARD", urlEntry.restUrl, SYSTEM_LS, jsonRequestString); - response = callRESTfulPDP(new ByteArrayInputStream(jsonReq.toString().getBytes()), urlEntry.restUrl, + response = callRestfulPdp(new ByteArrayInputStream(jsonReq.toString().getBytes()), urlEntry.restUrl, urlEntry.authorization, urlEntry.clientAuth, urlEntry.environment); netLogger.info("[IN|{}|{}|]{}{}", "GUARD", urlEntry.restUrl, SYSTEM_LS, response); } catch (Exception e) { @@ -134,7 +134,7 @@ public class PolicyGuardXacmlHelper { * @param environment the Environment * @return response from guard which contains "Permit" or "Deny" */ - private String callRESTfulPDP(InputStream is, URL restURL, String authorization, String clientauth, + private String callRestfulPdp(InputStream is, URL restUrl, String authorization, String clientauth, String environment) { HttpURLConnection connection = null; @@ -142,7 +142,7 @@ public class PolicyGuardXacmlHelper { // // Open up the connection // - connection = (HttpURLConnection) restURL.openConnection(); + connection = (HttpURLConnection) restUrl.openConnection(); connection.setRequestProperty("Content-Type", "application/json"); // // Setup our method and headers diff --git a/controlloop/common/guard/src/main/java/org/onap/policy/guard/impl/VMTargetLock.java b/controlloop/common/guard/src/main/java/org/onap/policy/guard/impl/VMTargetLock.java index dc81712cd..6046e3a32 100644 --- a/controlloop/common/guard/src/main/java/org/onap/policy/guard/impl/VMTargetLock.java +++ b/controlloop/common/guard/src/main/java/org/onap/policy/guard/impl/VMTargetLock.java @@ -41,14 +41,14 @@ public class VMTargetLock implements TargetLock, Serializable { * * @param targetType the target type * @param target the target - * @param requestID the request Id + * @param requestId the request Id * @param callback the callback */ - public VMTargetLock(TargetType targetType, String target, UUID requestID, LockCallback callback) { + public VMTargetLock(TargetType targetType, String target, UUID requestId, LockCallback callback) { this.lockId = UUID.randomUUID(); this.targetType = targetType; this.target = target; - this.requestId = requestID; + this.requestId = requestId; this.callback = callback; } diff --git a/controlloop/common/guard/src/main/java/org/onap/policy/guard/impl/VNFTargetLock.java b/controlloop/common/guard/src/main/java/org/onap/policy/guard/impl/VNFTargetLock.java index 307c11acf..418a3ed78 100644 --- a/controlloop/common/guard/src/main/java/org/onap/policy/guard/impl/VNFTargetLock.java +++ b/controlloop/common/guard/src/main/java/org/onap/policy/guard/impl/VNFTargetLock.java @@ -42,14 +42,14 @@ public class VNFTargetLock implements TargetLock, Serializable { * * @param type the type * @param target the target - * @param requestID the request Id + * @param requestId the request Id * @param callback the callback */ - public VNFTargetLock(TargetType type, String target, UUID requestID, LockCallback callback) { + public VNFTargetLock(TargetType type, String target, UUID requestId, LockCallback callback) { this.lockId = UUID.randomUUID(); this.targetType = type; this.target = target; - this.requestId = requestID; + this.requestId = requestId; this.callback = callback; } diff --git a/controlloop/common/guard/src/test/java/org/onap/policy/guard/PipEngineGetStatusTest.java b/controlloop/common/guard/src/test/java/org/onap/policy/guard/PipEngineGetStatusTest.java index cf83c883c..5e99b0605 100644 --- a/controlloop/common/guard/src/test/java/org/onap/policy/guard/PipEngineGetStatusTest.java +++ b/controlloop/common/guard/src/test/java/org/onap/policy/guard/PipEngineGetStatusTest.java @@ -27,34 +27,14 @@ import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import com.att.research.xacml.api.Attribute; -import com.att.research.xacml.api.AttributeValue; -import com.att.research.xacml.api.Identifier; -import com.att.research.xacml.api.Status; -import com.att.research.xacml.api.pip.PIPEngine; import com.att.research.xacml.api.pip.PIPException; -import com.att.research.xacml.api.pip.PIPFinder; -import com.att.research.xacml.api.pip.PIPRequest; -import com.att.research.xacml.api.pip.PIPResponse; -import com.att.research.xacml.std.IdentifierImpl; -import com.att.research.xacml.std.StdAttribute; -import com.att.research.xacml.std.StdAttributeValue; -import com.att.research.xacml.std.StdStatus; -import com.att.research.xacml.std.StdStatusCode; import com.att.research.xacml.std.pip.StdPIPRequest; import com.att.research.xacml.std.pip.StdPIPResponse; import com.att.research.xacml.std.pip.finders.EngineFinder; -import com.att.research.xacml.util.FactoryException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; import java.util.Properties; -import java.util.UUID; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; @@ -268,144 +248,4 @@ public class PipEngineGetStatusTest { pegs.configure("Dorothy", new Properties()); } - private class DummyPipFinder implements PIPFinder { - @Override - public PIPResponse getAttributes(PIPRequest pipRequest, PIPEngine exclude) throws PIPException { - return null; - } - - @Override - public PIPResponse getAttributes(PIPRequest pipRequest, PIPEngine exclude, PIPFinder pipFinderParent) - throws PIPException { - return null; - } - - @Override - public PIPResponse getMatchingAttributes(PIPRequest pipRequest, PIPEngine exclude) throws PIPException { - try { - List attributeList = new ArrayList<>(); - Identifier categoryIdIn = new IdentifierImpl(new URI("http://somewhere.over.the.rainbow/category")); - Identifier dataTypeIdIn = new IdentifierImpl(new URI("http://www.w3.org/2001/XMLSchema#string")); - - Identifier attributeIdIn0 = new IdentifierImpl(new URI(UUID.randomUUID().toString())); - AttributeValue valueIn0 = new StdAttributeValue(dataTypeIdIn, "ActorDorothy"); - Attribute attribute0 = new StdAttribute(categoryIdIn, attributeIdIn0, valueIn0); - attributeList.add(attribute0); - - Identifier attributeIdIn1 = new IdentifierImpl(new URI(UUID.randomUUID().toString())); - AttributeValue valueIn1 = new StdAttributeValue(dataTypeIdIn, "OperationHomeFromOZ"); - Attribute attribute1 = new StdAttribute(categoryIdIn, attributeIdIn1, valueIn1); - attributeList.add(attribute1); - - Identifier attributeIdIn2 = new IdentifierImpl(new URI(UUID.randomUUID().toString())); - AttributeValue valueIn2 = new StdAttributeValue(dataTypeIdIn, "TargetWickedWitch"); - Attribute attribute2 = new StdAttribute(categoryIdIn, attributeIdIn2, valueIn2); - attributeList.add(attribute2); - - return new StdPIPResponse(attributeList); - } catch (Exception e) { - return null; - } - } - - @Override - public PIPResponse getMatchingAttributes(PIPRequest pipRequest, PIPEngine exclude, PIPFinder pipFinderParent) - throws PIPException { - return null; - } - - @Override - public Collection getPIPEngines() { - return null; - } - } - - private class DummyPipFinderPipException implements PIPFinder { - @Override - public PIPResponse getAttributes(PIPRequest pipRequest, PIPEngine exclude) throws PIPException { - return null; - } - - @Override - public PIPResponse getAttributes(PIPRequest pipRequest, PIPEngine exclude, PIPFinder pipFinderParent) - throws PIPException { - return null; - } - - @Override - public PIPResponse getMatchingAttributes(PIPRequest pipRequest, PIPEngine exclude) throws PIPException { - throw new PIPException(); - } - - @Override - public PIPResponse getMatchingAttributes(PIPRequest pipRequest, PIPEngine exclude, PIPFinder pipFinderParent) - throws PIPException { - return null; - } - - @Override - public Collection getPIPEngines() { - return null; - } - } - - private class DummyPipFinderResponseStatusNok implements PIPFinder { - @Override - public PIPResponse getAttributes(PIPRequest pipRequest, PIPEngine exclude) throws PIPException { - return null; - } - - @Override - public PIPResponse getAttributes(PIPRequest pipRequest, PIPEngine exclude, PIPFinder pipFinderParent) - throws PIPException { - return null; - } - - @Override - public PIPResponse getMatchingAttributes(PIPRequest pipRequest, PIPEngine exclude) throws PIPException { - Status status = new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, "Processing Error"); - return new StdPIPResponse(status); - } - - @Override - public PIPResponse getMatchingAttributes(PIPRequest pipRequest, PIPEngine exclude, PIPFinder pipFinderParent) - throws PIPException { - return null; - } - - @Override - public Collection getPIPEngines() { - return null; - } - } - - private class DummyPipFinderResponseEmptyAttrs implements PIPFinder { - @Override - public PIPResponse getAttributes(PIPRequest pipRequest, PIPEngine exclude) throws PIPException { - return null; - } - - @Override - public PIPResponse getAttributes(PIPRequest pipRequest, PIPEngine exclude, PIPFinder pipFinderParent) - throws PIPException { - return null; - } - - @Override - public PIPResponse getMatchingAttributes(PIPRequest pipRequest, PIPEngine exclude) throws PIPException { - List attributeList = new ArrayList<>(); - return new StdPIPResponse(attributeList); - } - - @Override - public PIPResponse getMatchingAttributes(PIPRequest pipRequest, PIPEngine exclude, PIPFinder pipFinderParent) - throws PIPException { - return null; - } - - @Override - public Collection getPIPEngines() { - return null; - } - } } diff --git a/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopEvent.java b/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopEvent.java index 2753ececc..944bef754 100644 --- a/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopEvent.java +++ b/controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopEvent.java @@ -20,11 +20,10 @@ package org.onap.policy.controlloop; +import com.google.gson.annotations.SerializedName; import java.io.Serializable; import java.util.UUID; -import com.google.gson.annotations.SerializedName; - public abstract class ControlLoopEvent implements Serializable { private static final long serialVersionUID = 2391252138583119195L; diff --git a/controlloop/common/model-impl/rest/checkstyle-suppressions.xml b/controlloop/common/model-impl/rest/checkstyle-suppressions.xml new file mode 100644 index 000000000..19202a9f0 --- /dev/null +++ b/controlloop/common/model-impl/rest/checkstyle-suppressions.xml @@ -0,0 +1,30 @@ + + + + + + + + diff --git a/controlloop/common/model-impl/rest/pom.xml b/controlloop/common/model-impl/rest/pom.xml index adaee84a4..2ca997b9c 100644 --- a/controlloop/common/model-impl/rest/pom.xml +++ b/controlloop/common/model-impl/rest/pom.xml @@ -46,4 +46,46 @@ provided + + + + + maven-checkstyle-plugin + + + onap-java-style + + check + + process-sources + + + onap-checkstyle/onap-java-style.xml + + ${project.build.sourceDirectory} + true + true + true + + + ${project.basedir}/checkstyle-suppressions.xml + true + true + warning + + + + + + org.onap.oparent + checkstyle + ${oparent.version} + compile + + + + + diff --git a/controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/HttpDeleteWithBody.java b/controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/HttpDeleteWithBody.java index 262872262..dc75334a2 100644 --- a/controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/HttpDeleteWithBody.java +++ b/controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/HttpDeleteWithBody.java @@ -3,6 +3,7 @@ * rest * ================================================================================ * Copyright (C) 2018 Amdocs. All rights reserved. + * Modifications Copyright (C) 2018 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. @@ -20,10 +21,8 @@ package org.onap.policy.rest; -import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; - import java.net.URI; - +import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; /** * Allows for HTTP DELETE requests to contain a body, which the HttpDelete diff --git a/controlloop/common/model-impl/sdc/checkstyle-suppressions.xml b/controlloop/common/model-impl/sdc/checkstyle-suppressions.xml new file mode 100644 index 000000000..fd73d24e3 --- /dev/null +++ b/controlloop/common/model-impl/sdc/checkstyle-suppressions.xml @@ -0,0 +1,30 @@ + + + + + + + + diff --git a/controlloop/common/model-impl/sdc/pom.xml b/controlloop/common/model-impl/sdc/pom.xml index 970e53083..77bca7d6c 100644 --- a/controlloop/common/model-impl/sdc/pom.xml +++ b/controlloop/common/model-impl/sdc/pom.xml @@ -38,4 +38,46 @@ test + + + + + maven-checkstyle-plugin + + + onap-java-style + + check + + process-sources + + + onap-checkstyle/onap-java-style.xml + + ${project.build.sourceDirectory} + true + true + true + + + ${project.basedir}/checkstyle-suppressions.xml + true + true + warning + + + + + + org.onap.oparent + checkstyle + ${oparent.version} + compile + + + + + diff --git a/controlloop/common/model-impl/so/checkstyle-suppressions.xml b/controlloop/common/model-impl/so/checkstyle-suppressions.xml new file mode 100644 index 000000000..01bb15f8a --- /dev/null +++ b/controlloop/common/model-impl/so/checkstyle-suppressions.xml @@ -0,0 +1,30 @@ + + + + + + + + diff --git a/controlloop/common/model-impl/so/pom.xml b/controlloop/common/model-impl/so/pom.xml index 549f3a40c..d09a2b2ec 100644 --- a/controlloop/common/model-impl/so/pom.xml +++ b/controlloop/common/model-impl/so/pom.xml @@ -70,4 +70,45 @@ test + + + + maven-checkstyle-plugin + + + onap-java-style + + check + + process-sources + + + onap-checkstyle/onap-java-style.xml + + ${project.build.sourceDirectory} + true + true + true + + + ${project.basedir}/checkstyle-suppressions.xml + true + true + warning + + + + + + org.onap.oparent + checkstyle + ${oparent.version} + compile + + + + + 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 index 5acd973ef..20b1ac57b 100644 --- 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 @@ -77,7 +77,7 @@ public final class SOManager { * @param username user name on SO * @param password password on SO * @param request the request to issue to SO - * @return + * @return the SO Response object */ public SOResponse createModuleInstance(final String url, final String urlBase, final String username, final String password, final SORequest request) { @@ -89,7 +89,7 @@ public final class SOManager { restManager.post(url, username, password, createSimpleHeaders(), MEDIA_TYPE, requestJson); // Process the response from SO - SOResponse response = waitForSOOperationCompletion(urlBase, username, password, url, httpResponse); + SOResponse response = waitForSoOperationCompletion(urlBase, username, password, url, httpResponse); if (SO_RESPONSE_ERROR != response.getHttpResponseCode()) { return response; } else { @@ -98,22 +98,21 @@ public final class SOManager { } /** - * Works just like {@link SOManager#asyncSORestCall(String, WorkingMemory, String, String, String, SORequest) - * except the vfModuleInstanceId is always null + * Works just like SOManager#asyncSORestCall(String, WorkingMemory, String, String, String, SORequest) + * except the vfModuleInstanceId is always null. * - * @see SOManager#asyncSORestCall(String, WorkingMemory, String, String, String, SORequest) */ - public Future asyncSORestCall(final String requestID, final WorkingMemory wm, + public Future asyncSORestCall(final String requestId, final WorkingMemory wm, final String serviceInstanceId, final String vnfInstanceId, final SORequest request) { - return asyncSORestCall(requestID, wm, serviceInstanceId, vnfInstanceId, null, request); + return asyncSORestCall(requestId, wm, serviceInstanceId, vnfInstanceId, null, request); } /** * This method makes an asynchronous Rest call to MSO and inserts the response into * Drools working memory. * - * @param requestID + * @param requestId the request id * @param wm the Drools working memory * @param serviceInstanceId service instance id to construct the request url * @param vnfInstanceId vnf instance id to construct the request url @@ -122,18 +121,20 @@ public final class SOManager { * @param request the SO request * @return a concurrent Future for the thread that handles the request */ - public Future asyncSORestCall(final String requestID, final WorkingMemory wm, - final String serviceInstanceId, final String vnfInstanceId, final String vfModuleInstanceId, final - SORequest request) { - return executors.submit(new AsyncSORestCallThread(requestID, wm, serviceInstanceId, vnfInstanceId, + public Future asyncSORestCall(final String requestId, + final WorkingMemory wm, + final String serviceInstanceId, + final String vnfInstanceId, + final String vfModuleInstanceId, final SORequest request) { + return executors.submit(new AsyncSoRestCallThread(requestId, wm, serviceInstanceId, vnfInstanceId, vfModuleInstanceId, request)); } /** * This class handles an asynchronous request to SO as a thread. */ - private class AsyncSORestCallThread implements Callable { - final String requestID; + private class AsyncSoRestCallThread implements Callable { + final String requestId; final WorkingMemory wm; final String serviceInstanceId; final String vnfInstanceId; @@ -150,9 +151,11 @@ public final class SOManager { * @param vfModuleInstanceId the vf module instance id (not null in case of delete vf module request) * @param request the request itself */ - private AsyncSORestCallThread(final String requestID, final WorkingMemory wm, final String serviceInstanceId, - final String vnfInstanceId, final String vfModuleInstanceId, final SORequest request) { - this.requestID = requestID; + private AsyncSoRestCallThread(final String requestId, + final WorkingMemory wm, final String serviceInstanceId, + final String vnfInstanceId, final String vfModuleInstanceId, + final SORequest request) { + this.requestId = requestId; this.wm = wm; this.serviceInstanceId = serviceInstanceId; this.vnfInstanceId = vnfInstanceId; @@ -191,10 +194,10 @@ public final class SOManager { } // Process the response from SO - SOResponse response = waitForSOOperationCompletion(urlBase, username, password, url, httpResponse); + SOResponse response = waitForSoOperationCompletion(urlBase, username, password, url, httpResponse); // Return the response to Drools in its working memory - SOResponseWrapper soWrapper = new SOResponseWrapper(response, requestID); + SOResponseWrapper soWrapper = new SOResponseWrapper(response, requestId); wm.insert(soWrapper); return response; @@ -211,11 +214,11 @@ public final class SOManager { * @param initialHTTPResponse The initial HTTP message returned from SO * @return The parsed final response of SO to the request */ - private SOResponse waitForSOOperationCompletion(final String urlBaseSO, final String username, + private SOResponse waitForSoOperationCompletion(final String urlBaseSO, final String username, final String password, final String initialRequestURL, final Pair initialHTTPResponse) { // Process the initial response from SO, the response to a post - SOResponse response = processSOResponse(initialRequestURL, initialHTTPResponse); + SOResponse response = processSoResponse(initialRequestURL, initialHTTPResponse); if (SO_RESPONSE_ERROR == response.getHttpResponseCode()) { return response; } @@ -224,7 +227,7 @@ public final class SOManager { String urlGet = urlBaseSO + "/orchestrationRequests/v5/" + response.getRequestReferences().getRequestId(); // The HTTP status code of the latest response - Pair latestHTTPResponse = initialHTTPResponse; + Pair latestHttpResponse = initialHTTPResponse; // Wait for the response from SO for (int attemptsLeft = GET_REQUESTS_BEFORE_TIMEOUT; attemptsLeft >= 0; attemptsLeft--) { @@ -232,7 +235,7 @@ public final class SOManager { // response // here before // issuing any other requests - if (isRequestStateFinished(latestHTTPResponse, response)) { + if (isRequestStateFinished(latestHttpResponse, response)) { return response; } @@ -252,13 +255,13 @@ public final class SOManager { Pair httpResponse = restManager.get(urlGet, username, password, createSimpleHeaders()); // Get our response - response = processSOResponse(urlGet, httpResponse); + response = processSoResponse(urlGet, httpResponse); if (SO_RESPONSE_ERROR == response.getHttpResponseCode()) { return response; } // Our latest HTTP response code - latestHTTPResponse = httpResponse; + latestHttpResponse = httpResponse; } // We have timed out on the SO request @@ -273,7 +276,7 @@ public final class SOManager { * @param httpResponse The HTTP message returned from SO * @return The parsed response */ - private SOResponse processSOResponse(final String requestURL, final Pair httpResponse) { + private SOResponse processSoResponse(final String requestUrl, final Pair httpResponse) { SOResponse response = new SOResponse(); // A null httpDetails indicates a HTTP problem, a valid response from SO must be @@ -299,10 +302,10 @@ public final class SOManager { response.setHttpResponseCode(httpResponse.first); } - netLogger.info("[IN|{}|{}|]{}{}", "SO", requestURL, LINE_SEPARATOR, httpResponse.second); + netLogger.info("[IN|{}|{}|]{}{}", "SO", requestUrl, LINE_SEPARATOR, httpResponse.second); if (logger.isDebugEnabled()) { - logger.debug("***** Response to SO Request to URL {}:", requestURL); + logger.debug("***** Response to SO Request to URL {}:", requestUrl); logger.debug(httpResponse.second); } @@ -332,12 +335,12 @@ public final class SOManager { /** * Check that the request state of a response is finished. * - * @param latestHTTPDetails the HTTP details of the response + * @param latestHttpDetails the HTTP details of the response * @param response The response to check * @return true if the request for the response is finished */ - private boolean isRequestStateFinished(final Pair latestHTTPDetails, final SOResponse response) { - if (latestHTTPDetails != null && 200 == latestHTTPDetails.first && isRequestStateDefined(response)) { + private boolean isRequestStateFinished(final Pair latestHttpDetails, final SOResponse response) { + if (latestHttpDetails != null && 200 == latestHttpDetails.first && isRequestStateDefined(response)) { String requestState = response.getRequest().getRequestStatus().getRequestState(); return "COMPLETE".equalsIgnoreCase(requestState) || "FAILED".equalsIgnoreCase(requestState); } else { diff --git a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SoOperationType.java b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SoOperationType.java index 7619e3a84..191ee05d2 100644 --- a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SoOperationType.java +++ b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SoOperationType.java @@ -3,6 +3,7 @@ * so * ================================================================================ * Copyright (C) 2018 Amdocs. All rights reserved. + * Modifications Copyright (C) 2018 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. @@ -21,7 +22,7 @@ package org.onap.policy.so; /** - * Enumeration of SO Operations type that can be performed by a policy + * Enumeration of SO Operations type that can be performed by a policy. */ public enum SoOperationType { SCALE_OUT("Create Vf Module"), diff --git a/controlloop/common/model-impl/trafficgenerator/checkstyle-suppressions.xml b/controlloop/common/model-impl/trafficgenerator/checkstyle-suppressions.xml new file mode 100644 index 000000000..57d62196f --- /dev/null +++ b/controlloop/common/model-impl/trafficgenerator/checkstyle-suppressions.xml @@ -0,0 +1,30 @@ + + + + + + + + diff --git a/controlloop/common/model-impl/trafficgenerator/pom.xml b/controlloop/common/model-impl/trafficgenerator/pom.xml index c1684e7c1..02fc90865 100644 --- a/controlloop/common/model-impl/trafficgenerator/pom.xml +++ b/controlloop/common/model-impl/trafficgenerator/pom.xml @@ -41,4 +41,46 @@ provided + + + + + maven-checkstyle-plugin + + + onap-java-style + + check + + process-sources + + + onap-checkstyle/onap-java-style.xml + + ${project.build.sourceDirectory} + true + true + true + + + ${project.basedir}/checkstyle-suppressions.xml + true + true + warning + + + + + + org.onap.oparent + checkstyle + ${oparent.version} + compile + + + + + diff --git a/controlloop/common/model-impl/vfc/checkstyle-suppressions.xml b/controlloop/common/model-impl/vfc/checkstyle-suppressions.xml new file mode 100644 index 000000000..ea04e03f1 --- /dev/null +++ b/controlloop/common/model-impl/vfc/checkstyle-suppressions.xml @@ -0,0 +1,30 @@ + + + + + + + + diff --git a/controlloop/common/model-impl/vfc/pom.xml b/controlloop/common/model-impl/vfc/pom.xml index 2992009c9..75f2ff244 100644 --- a/controlloop/common/model-impl/vfc/pom.xml +++ b/controlloop/common/model-impl/vfc/pom.xml @@ -69,4 +69,45 @@ provided + + + + maven-checkstyle-plugin + + + onap-java-style + + check + + process-sources + + + onap-checkstyle/onap-java-style.xml + + ${project.build.sourceDirectory} + true + true + true + + + ${project.basedir}/checkstyle-suppressions.xml + true + true + warning + + + + + + org.onap.oparent + checkstyle + ${oparent.version} + compile + + + + + diff --git a/controlloop/common/policy-yaml/pom.xml b/controlloop/common/policy-yaml/pom.xml index 633bd9c4f..b48e74d67 100644 --- a/controlloop/common/policy-yaml/pom.xml +++ b/controlloop/common/policy-yaml/pom.xml @@ -79,4 +79,53 @@ test + + + + + + maven-checkstyle-plugin + + + onap-java-style + + check + + process-sources + + + onap-checkstyle/onap-java-style.xml + + ${project.build.sourceDirectory}/src/main/java + true + true + true + + + true + true + warning + + + + + + org.onap.oparent + checkstyle + ${oparent.version} + compile + + + + + + diff --git a/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java b/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java index 3dd8347f2..3bacead01 100644 --- a/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java +++ b/controlloop/common/simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java @@ -96,12 +96,13 @@ public class AaiSimulatorJaxRs { } else { Map params = new TreeMap<>(); params.put("vnfId", "" + vnfId); - params.put("vnfName", getUUIDValue(vnfId, "ZRDM2MMEX39")); + params.put("vnfName", getUuidValue(vnfId, "ZRDM2MMEX39")); params.put("pnfVndName", "pnf-test-" + vnfId); - params.put("pnfVnfId", getUUIDValue(params.get("pnfVndName"), "jimmy-test")); + params.put("pnfVnfId", getUuidValue(params.get("pnfVndName"), "jimmy-test")); params.put("serviceInstanceVnfName", "service-instance-test-" + vnfId); - params.put("serviceInstanceVnfId", getUUIDValue(params.get("serviceInstanceVnfName"), "jimmy-test-vnf2")); + params.put("serviceInstanceVnfId", + getUuidValue(params.get("serviceInstanceVnfName"), "jimmy-test-vnf2")); return load("aai/AaiNqResponse-GenericVnf.json", params); } @@ -132,7 +133,8 @@ public class AaiSimulatorJaxRs { + "equipment-role\": \"UCPE\", \"orchestration-status\": \"created\", \"management-option\": \"" + "ATT\", \"ipv4-oam-address\": \"32.40.68.35\", \"ipv4-loopback0-address\": \"32.40.64.57\", \"" + "nm-lan-v6-address\": \"2001:1890:e00e:fffe::1345\", \"management-v6-address\": \"" - + "2001:1890:e00e:fffd::36\", \"in-maint\": false, \"prov-status\":\"ACTIVE\", \"is-closed-loop-disabled\": " + isDisabled + + "2001:1890:e00e:fffd::36\", \"in-maint\": false, \"prov-status\":\"ACTIVE\", " + + "\"is-closed-loop-disabled\": " + isDisabled + ", \"resource-version\": \"1493389458092\", \"relationship-list\": {\"relationship\":[{ \"" + "related-to\": \"service-instance\", \"related-link\": \"/aai/v11/business/customers/customer/" + "1610_Func_Global_20160817084727/service-subscriptions/service-subscription/uCPE-VMS/" @@ -154,13 +156,14 @@ public class AaiSimulatorJaxRs { + "USUCP0PCOIL0110UJZZ01-vsrx\" }]} ]}}"; } - final String vnfId = getUUIDValue(vnfName, "5e49ca06-2972-4532-9ed4-6d071588d792"); + final String vnfId = getUuidValue(vnfName, "5e49ca06-2972-4532-9ed4-6d071588d792"); return "{ \"vnf-id\": \"" + vnfId + "\", \"vnf-name\": \"" + vnfName + "\", \"vnf-type\": \"RT\", \"service-id\": \"d7bb0a21-66f2-4e6d-87d9-9ef3ced63ae4\", \"" + "equipment-role\": \"UCPE\", \"orchestration-status\": \"created\", \"management-option\": \"ATT" + "\", \"ipv4-oam-address\": \"32.40.68.35\", \"ipv4-loopback0-address\": \"32.40.64.57\", \"" + "nm-lan-v6-address\": \"2001:1890:e00e:fffe::1345\", \"management-v6-address\": \"" - + "2001:1890:e00e:fffd::36\", \"in-maint\": false, \"prov-status\":\"ACTIVE\", \"is-closed-loop-disabled\": " + isDisabled + + "2001:1890:e00e:fffd::36\", \"in-maint\": false, \"prov-status\":\"ACTIVE\", " + + "\"is-closed-loop-disabled\": " + isDisabled + ", \"resource-version\": \"1493389458092\", \"relationship-list\": {\"relationship\":[{ \"" + "related-to\": \"service-instance\", \"related-link\": \"/aai/v11/business/customers/customer" + "/1610_Func_Global_20160817084727/service-subscriptions/service-subscription/uCPE-VMS/" @@ -199,13 +202,14 @@ public class AaiSimulatorJaxRs { + "generic-vnfs/generic-vnf/getFail\",\"ERR.5.4.6114\"]}}}"; } final boolean isDisabled = "disableClosedLoop".equals(vnfId); - final String vnfName = getUUIDValue(vnfId, "USUCP0PCOIL0110UJRT01"); + final String vnfName = getUuidValue(vnfId, "USUCP0PCOIL0110UJRT01"); return "{ \"vnf-id\": \"" + vnfId + "\", \"vnf-name\": \"" + vnfName + "\", \"vnf-type\": \"RT\", \"service-id\": \"" + "d7bb0a21-66f2-4e6d-87d9-9ef3ced63ae4\", \"equipment-role\": \"UCPE\", \"orchestration-status" + "\": \"created\", \"management-option\": \"ATT\", \"ipv4-oam-address\": \"32.40.68.35\", \"" + "ipv4-loopback0-address\": \"32.40.64.57\", \"nm-lan-v6-address\": \"2001:1890:e00e:fffe::1345" - + "\", \"management-v6-address\": \"2001:1890:e00e:fffd::36\", \"in-maint\": false, \"prov-status\":\"ACTIVE\", \"" + "" + + "\", \"management-v6-address\": \"2001:1890:e00e:fffd::36\", \"in-maint\": false, " + + "\"prov-status\":\"ACTIVE\", \"" + "" + "is-closed-loop-disabled\": " + isDisabled + ", \"resource-version\": \"1493389458092\", \"" + "relationship-list\": {\"relationship\":[{ \"related-to\": \"service-instance\", \"related-link" + "\": \"/aai/v11/business/customers/customer/1610_Func_Global_20160817084727/service-subscriptions" @@ -243,11 +247,12 @@ public class AaiSimulatorJaxRs { + " Found:No Node of type generic-vnf found at nodes/vservers\",\"ERR.5.4.6114\"]}}}"; } final boolean isDisabled = "disableClosedLoop".equals(vserverName); - final String vserverId = getUUIDValue(vserverName, "d0668d4f-c25e-4a1b-87c4-83845c01efd8"); + final String vserverId = getUuidValue(vserverName, "d0668d4f-c25e-4a1b-87c4-83845c01efd8"); return "{\"vserver\": [{ \"vserver-id\": \"" + vserverId + "\", \"vserver-name\": \"" + vserverName + "\", \"vserver-name2\": \"vjunos0\", \"vserver-selflink\": \"https://aai-ext1.test.att.com:8443/aai/v7/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/tenants/tenant/USMSO1SX7NJ0103UJZZ01%3A%3AuCPE-VMS/vservers/vserver/d0668d4f-c25e-4a1b-87c4-83845c01efd8\", \"in-maint\": false, \"is-closed-loop-disabled\": " + isDisabled - + ", \"prov-status\":\"ACTIVE\", \"resource-version\": \"1494001931513\", \"relationship-list\": {\"relationship\":[{ \"related-to" + + ", \"prov-status\":\"ACTIVE\", \"resource-version\": \"1494001931513\", " + + "\"relationship-list\": {\"relationship\":[{ \"related-to" + "\": \"generic-vnf\", \"related-link\": \"/aai/v11/network/generic-vnfs/generic-vnf/" + "e1a41e99-4ede-409a-8f9d-b5e12984203a\", \"relationship-data\": [ {\"relationship-key\": \"" + "generic-vnf.vnf-id\",\"relationship-value\": \"e1a41e99-4ede-409a-8f9d-b5e12984203a\" }], \"" @@ -258,7 +263,7 @@ public class AaiSimulatorJaxRs { + "related-to-property\": [{\"property-key\": \"pserver.pserver-name2\"}]} ]}}]}"; } - private String getUUIDValue(final String value, final String defaultValue) { + private String getUuidValue(final String value, final String defaultValue) { return value != null ? UUID.nameUUIDFromBytes(value.getBytes()).toString() : defaultValue; } 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 index 35abf55b0..8bab8bba4 100644 --- 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 @@ -20,6 +20,7 @@ package org.onap.policy.simulators; +import com.att.aft.dme2.internal.gson.Gson; import java.util.UUID; import javax.ws.rs.Consumes; import javax.ws.rs.POST; @@ -31,7 +32,6 @@ import org.onap.policy.so.SORequest; import org.onap.policy.so.SORequestReferences; import org.onap.policy.so.SORequestStatus; import org.onap.policy.so.SOResponse; -import com.att.aft.dme2.internal.gson.Gson; @Path("/serviceInstantiation") public class SoSimulatorJaxRs { -- cgit 1.2.3-korg