diff options
author | daniel <dc443y@att.com> | 2017-08-11 11:36:09 -0500 |
---|---|---|
committer | daniel <dc443y@att.com> | 2017-09-06 17:14:59 -0500 |
commit | 7576237fd14304e987eb3c907d481f503dab8232 (patch) | |
tree | ddc75f000cb86e3a426cf34d6031efbc14c8735e /controlloop/common/actors/actor.appc | |
parent | b2bdc20c1ce3a390dd7928144c2ccb17a98b1363 (diff) |
Add APPC LCM Interface
The LCM model code and service provider code is implemented.
This model code is now used for the vCPE use case scenario.
The vFW use case is still using the legacy APPC API as
request by APPC for Policy to use in R1. The APPC
service provider now generates a demo legacy APPC
request with pg-streams.
An A&AI named query is implemented for the vFW use case.
The code for obtaining the generic-vnf.vnf-id is not
in use until we set up the A&AI simulator to work
without having cyclical depenncies inside the POMs.
JUnits for the vFW and vCPE use cases are now supported.
These JUnits test the complete flow of each scenario.
A&AI testing is not supported in the JUnit test yet.
These JUnits use a target type of VM as VNF is not
supported yet. This will be changed when the Target
Lock supports VNF.
Amended to fix Sonar blockers.
Issue-ID: POLICY-104
Change-Id: I46869c5fd5094919da55ad563d608fe6d4b6fea7
Signed-off-by: Daniel Cruz <dc443y@att.com>
Diffstat (limited to 'controlloop/common/actors/actor.appc')
3 files changed, 205 insertions, 30 deletions
diff --git a/controlloop/common/actors/actor.appc/pom.xml b/controlloop/common/actors/actor.appc/pom.xml index 5f6519a47..2d39ca849 100644 --- a/controlloop/common/actors/actor.appc/pom.xml +++ b/controlloop/common/actors/actor.appc/pom.xml @@ -18,15 +18,45 @@ </dependency> <dependency> <groupId>org.onap.policy.drools-applications</groupId> + <artifactId>actor.appclcm</artifactId> + <version>1.1.0-SNAPSHOT</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.onap.policy.drools-applications</groupId> + <artifactId>aai</artifactId> + <version>1.1.0-SNAPSHOT</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.onap.policy.drools-applications</groupId> <artifactId>appc</artifactId> <version>1.1.0-SNAPSHOT</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.onap.policy.drools-applications</groupId> + <artifactId>trafficgenerator</artifactId> + <version>1.1.0-SNAPSHOT</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.onap.policy.drools-applications</groupId> <artifactId>events</artifactId> <version>1.1.0-SNAPSHOT</version> <scope>provided</scope> </dependency> + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + <version>2.5</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.12</version> + <scope>test</scope> + </dependency> </dependencies> </project> 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 index 7cdf99625..e7b7d2371 100644 --- 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 @@ -21,16 +21,17 @@ package org.onap.policy.controlloop.actor.appc; import java.util.Collections; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.onap.policy.controlloop.VirtualControlLoopEvent; +import org.onap.policy.controlloop.actor.appclcm.AppcLcmActorServiceProvider; import org.onap.policy.appc.CommonHeader; import org.onap.policy.appc.Request; import org.onap.policy.controlloop.ControlLoopOperation; 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; import org.onap.policy.controlloop.actorServiceProvider.spi.Actor; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -43,7 +44,7 @@ public class APPCActorServiceProvider implements Actor { .put("Restart", ImmutableList.of("VM")) .put("Rebuild", ImmutableList.of("VM")) .put("Migrate", ImmutableList.of("VM")) - .put("ModifyConfig", ImmutableList.of("VFC")) + .put("ModifyConfig", ImmutableList.of("VNF")) .build(); private static final ImmutableMap<String, List<String>> payloads = new ImmutableMap.Builder<String, List<String>>() .put("ModifyConfig", ImmutableList.of("generic-vnf.vnf-id")) @@ -69,43 +70,63 @@ public class APPCActorServiceProvider implements Actor { 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) { - // - // Construct an APPC request - // + /* + * Construct an APPC request + */ Request request = new Request(); request.CommonHeader = new CommonHeader(); request.CommonHeader.RequestID = onset.requestID; request.CommonHeader.SubRequestID = operation.subRequestId; request.Action = policy.getRecipe(); - // - // TODO: do we need to take care of the target - // + /* + * The target vnf-id may not be the same as the source vnf-id + * specified in the yaml, the target vnf-id is retrieved by + * a named query to A&AI. + */ + String resourceId = policy.getTarget().getResourceID(); + String sourceVnfId = onset.AAI.get("generic-vnf.vnf-id"); + String vnfId = "test"; //AppcLcmActorServiceProvider.vnfNamedQuery(resourceId, sourceVnfId); + + /* + * For now Policy generates the PG Streams as a demo, in the + * future the payload can be provided by CLAMP + */ + request.Payload.put("generic-vnf.vnf-id", vnfId); + + PGRequest pgRequest = new PGRequest(); + pgRequest.pgStreams = new PGStreams(); - // - // Handle the payload - // - if (policy.getPayload() != null && !policy.getPayload().isEmpty()) { - request.Payload = new HashMap<String, Object>(); - // - // Add each payload entry - // - for (Map.Entry<String, String> entry : policy.getPayload().entrySet()) { - // - // TODO: entry key has ref$, value has {xxxx} - // - request.Payload.put(entry.getKey(), entry.getValue()); - } + 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.Payload.put("pg-streams", pgRequest.pgStreams); + /* + * Return the request + */ - request.Payload.put("AICVServerSelfLink", onset.AAI.get("vserver.selflink"));//.AICVServerSelfLink); - request.Payload.put("AICIdentity", onset.AAI.get("cloud-region.identity-url"));//AICIdentity); - // - // Return the request - // return request; } 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 new file mode 100644 index 000000000..c8179992c --- /dev/null +++ b/controlloop/common/actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java @@ -0,0 +1,124 @@ +/*- + * ============LICENSE_START======================================================= + * AppcServiceProviderTest + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.controlloop.actor.appc; + +import static org.junit.Assert.*; + +import java.time.Instant; +import java.util.HashMap; +import java.util.UUID; + +import org.junit.Test; +import org.onap.policy.appc.Request; +import org.onap.policy.appc.util.Serialization; +import org.onap.policy.controlloop.ControlLoopEventStatus; +import org.onap.policy.controlloop.ControlLoopOperation; +import org.onap.policy.controlloop.ControlLoopTargetType; +import org.onap.policy.controlloop.VirtualControlLoopEvent; +import org.onap.policy.controlloop.policy.Policy; +import org.onap.policy.controlloop.policy.Target; +import org.onap.policy.controlloop.policy.TargetType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AppcServiceProviderTest { + + private static final Logger logger = LoggerFactory.getLogger(AppcServiceProviderTest.class); + + private static VirtualControlLoopEvent onsetEvent; + private static ControlLoopOperation operation; + private static Policy policy; + + static { + /* + * Construct an onset with an AAI subtag containing + * generic-vnf.vnf-id and a target type of VM. + */ + onsetEvent = new VirtualControlLoopEvent(); + onsetEvent.closedLoopControlName = "closedLoopControlName-Test"; + onsetEvent.requestID = UUID.randomUUID(); + onsetEvent.closedLoopEventClient = "tca.instance00001"; + onsetEvent.target_type = ControlLoopTargetType.VF; + onsetEvent.target = "generic-vnf.vnf-id"; + onsetEvent.from = "DCAE"; + onsetEvent.closedLoopAlarmStart = Instant.now(); + onsetEvent.AAI = new HashMap<>(); + onsetEvent.AAI.put("generic-vnf.vnf-id", "fw0001vm001fw001"); + onsetEvent.closedLoopEventStatus = ControlLoopEventStatus.ONSET; + + /* Construct an operation with an APPC actor and ModifyConfig operation. */ + operation = new ControlLoopOperation(); + operation.actor = "APPC"; + operation.operation = "ModifyConfig"; + operation.target = "VM"; + operation.end = Instant.now(); + operation.subRequestId = "1"; + + /* Construct a policy specifying to modify configuration. */ + policy = new Policy(); + policy.setName("Modify Packet Generation Config"); + policy.setDescription("Upon getting the trigger event, modify packet gen config"); + policy.setActor("APPC"); + policy.setTarget(new Target(TargetType.VM)); + policy.setRecipe("ModifyConfig"); + policy.setPayload(null); + policy.setRetry(2); + policy.setTimeout(300); + + } + + @Test + public void constructModifyConfigRequestTest() { + + Request appcRequest = APPCActorServiceProvider.constructRequest(onsetEvent, operation, policy); + + /* The service provider must return a non null APPC request */ + assertNotNull(appcRequest); + + /* A common header is required and cannot be null */ + assertNotNull(appcRequest.getCommonHeader()); + assertEquals(appcRequest.getCommonHeader().RequestID, onsetEvent.requestID); + + /* An action is required and cannot be null */ + assertNotNull(appcRequest.Action); + assertEquals(appcRequest.Action, "ModifyConfig"); + + /* A payload is required and cannot be null */ + assertNotNull(appcRequest.getPayload()); + assertTrue(appcRequest.getPayload().containsKey("generic-vnf.vnf-id")); + assertTrue(appcRequest.getPayload().containsKey("pg-streams")); + + logger.debug("APPC Request: \n" + appcRequest.toString()); + + /* Print out request as json to make sure serialization works */ + String jsonRequest = Serialization.gsonPretty.toJson(appcRequest); + logger.debug("JSON Output: \n" + jsonRequest); + + /* The JSON string must contain the following fields */ + assertTrue(jsonRequest.contains("CommonHeader")); + assertTrue(jsonRequest.contains("Action")); + assertTrue(jsonRequest.contains("ModifyConfig")); + assertTrue(jsonRequest.contains("Payload")); + assertTrue(jsonRequest.contains("generic-vnf.vnf-id")); + assertTrue(jsonRequest.contains("pg-streams")); + } + +} |