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 org.onap.policy.so.util.Serialization;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.gson.reflect.TypeToken;
public class SOActorServiceProvider implements Actor {
private static final Logger logger = LoggerFactory.getLogger(SOActorServiceProvider.class);
* TestSOActorServiceProvider
* ================================================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * ================================================================================
* Modifications Copyright (C) 2018 AT&T. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
+
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.LinkedList;
import org.onap.policy.so.SORequestParameters;
import org.onap.policy.so.util.Serialization;
-public class TestSOActorServiceProvider {
+public class SoActorServiceProviderTest {
@Test
public void testConstructRequest() throws Exception {
* TestVFCActorServiceProvider
* ================================================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2018 AT&T 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.
import org.onap.policy.simulators.Util;
import org.onap.policy.vfc.VFCRequest;
-public class TestVFCActorServiceProvider {
+public class VfcActorServiceProviderTest {
/**
* Set up for test class.
}
/**
- * Does provisioning status, for an event, have a value other than ACTIVE?
+ * Does provisioning status, for an event, have a value other than ACTIVE.
*
* @param event the event
* @return {@code true} if the provisioning status is neither ACTIVE nor {@code null},
try {
if (vserverName != null) {
- String aaiHostURL = PolicyEngine.manager.getEnvironmentProperty("aai.url");
+ String aaiHostUrl = PolicyEngine.manager.getEnvironmentProperty("aai.url");
String aaiUser = PolicyEngine.manager.getEnvironmentProperty("aai.username");
String aaiPassword = PolicyEngine.manager.getEnvironmentProperty("aai.password");
String aaiGetQueryByVserver = "/aai/v11/nodes/vservers?vserver-name=";
- String url = aaiHostURL + aaiGetQueryByVserver;
+ String url = aaiHostUrl + aaiGetQueryByVserver;
logger.info("AAI Host URL by VServer: {}", url);
response = new AaiManager(new RESTManager()).getQueryByVserverName(url, aaiUser, aaiPassword, requestId,
vserverName);
String vnfName = event.getAai().get(GENERIC_VNF_VNF_NAME);
String vnfId = event.getAai().get(GENERIC_VNF_VNF_ID);
- String aaiHostURL = PolicyEngine.manager.getEnvironmentProperty("aai.url");
+ String aaiHostUrl = PolicyEngine.manager.getEnvironmentProperty("aai.url");
String aaiUser = PolicyEngine.manager.getEnvironmentProperty("aai.username");
String aaiPassword = PolicyEngine.manager.getEnvironmentProperty("aai.password");
try {
if (vnfName != null) {
String aaiGetQueryByVnfName = "/aai/v11/network/generic-vnfs/generic-vnf?vnf-name=";
- String url = aaiHostURL + aaiGetQueryByVnfName;
+ String url = aaiHostUrl + aaiGetQueryByVnfName;
logger.info("AAI Host URL by VNF name: {}", url);
response = new AaiManager(new RESTManager()).getQueryByVnfName(url, aaiUser, aaiPassword, requestId,
vnfName);
} else if (vnfId != null) {
String aaiGetQueryByVnfId = "/aai/v11/network/generic-vnfs/generic-vnf/";
- String url = aaiHostURL + aaiGetQueryByVnfId;
+ String url = aaiHostUrl + aaiGetQueryByVnfId;
logger.info("AAI Host URL by VNF ID: {}", url);
response =
new AaiManager(new RESTManager()).getQueryByVnfId(url, aaiUser, aaiPassword, requestId, vnfId);
* @return output from the AAI vserver named-query
*/
public AaiNqResponseWrapper getNqVserverFromAai() {
- if(nqVserverResponse != null) {
+ if (nqVserverResponse != null) {
// already queried
return nqVserverResponse;
}
String vserverName = onset.getAai().get(VSERVER_VSERVER_NAME);
- if(vserverName == null) {
+ if (vserverName == null) {
logger.warn("Missing vserver-name for AAI request {}", onset.getRequestId());
return null;
}
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import org.junit.rules.ExpectedException;
import org.onap.policy.aai.AaiGetVnfResponse;
import org.onap.policy.aai.AaiGetVserverResponse;
-import org.onap.policy.aai.AaiNqVServer;
import org.onap.policy.aai.AaiNqRequestError;
import org.onap.policy.aai.AaiNqResponseWrapper;
+import org.onap.policy.aai.AaiNqVServer;
import org.onap.policy.aai.RelatedToProperty;
import org.onap.policy.aai.Relationship;
import org.onap.policy.aai.RelationshipData;
HttpServletServer.factory.destroy();
}
+ /**
+ * Setup.
+ */
@Before
public void setUp() {
onset = new VirtualControlLoopEvent();
*/
public static AaiGetVserverResponse getQueryByVserverName2(String urlGet, String username, String password,
UUID requestId, String key) {
- AaiGetVserverResponse response = new AaiGetVserverResponse();
+ final AaiGetVserverResponse response = new AaiGetVserverResponse();
AaiNqVServer svr = new AaiNqVServer();
}
@Test
- public void testProcessVNFResponse_Success() throws Exception {
+ public void testProcessVnfResponse_Success() throws Exception {
AaiGetVnfResponse resp = new AaiGetVnfResponse();
resp.setIsClosedLoopDisabled(false);
resp.setProvStatus(ControlLoopEventManager.PROV_STATUS_ACTIVE);
}
@Test
- public void testProcessVNFResponse_NullResponse() throws Exception {
+ public void testProcessVnfResponse_NullResponse() throws Exception {
thrown.expect(AaiException.class);
thrown.expectMessage("AAI Response is null (query by vnf-id)");
}
@Test
- public void testProcessVNFResponse_Error() throws Exception {
+ public void testProcessVnfResponse_Error() throws Exception {
thrown.expect(AaiException.class);
thrown.expectMessage("AAI Responded with a request error (query by vnf-name)");
}
@Test
- public void testProcessVNFResponse_Disabled() throws Exception {
+ public void testProcessVnfResponse_Disabled() throws Exception {
thrown.expect(AaiException.class);
thrown.expectMessage("is-closed-loop-disabled is set to true (query by vnf-id)");
}
@Test
- public void testProcessVNFResponse_Inactive() throws Exception {
+ public void testProcessVnfResponse_Inactive() throws Exception {
thrown.expect(AaiException.class);
thrown.expectMessage("prov-status is not ACTIVE (query by vnf-name)");
clom.startOperation(onsetEvent);
- assertEquals("actor=SO,operation=Restart,target=Target [type=VFC, resourceID=null],subRequestId=1",
+ assertEquals("actor=SO,operation=Restart,target=Target [type=VFC, resourceId=null],subRequestId=1",
clom.getOperationMessage());
assertEquals(
- "actor=SO,operation=Restart,target=Target [type=VFC, resourceID=null],subRequestId=1, Guard result: "
+ "actor=SO,operation=Restart,target=Target [type=VFC, resourceId=null],subRequestId=1, Guard result: "
+ "The Wizard Escaped",
clom.getOperationMessage("The Wizard Escaped"));
import org.onap.policy.controlloop.VirtualControlLoopNotification;
import org.onap.policy.drools.features.PolicyControllerFeatureAPI;
import org.onap.policy.drools.system.PolicyController;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* Feature that tracks Transactions by observing Notification Patterns.
/**
* Feature Sequence Priority.
*/
- public final static int FEATURE_SEQUENCE_PRIORITY = 100000;
+ public static final int FEATURE_SEQUENCE_PRIORITY = 100000;
/**
* Properties Configuration Name.
return false;
}
- /**
- * Logger.
- */
- private static Logger logger = LoggerFactory.getLogger(ControlLoopMetricsFeature.class);
-
/**
* Intercept Control Loop Notifications.
*
* ============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.
/**
* Construct an instance.
*
- * @param clnameID the control loop Id
- * @param actorID the actor Id
- * @param operationID the operation Id
- * @param targetID the target Id
- * @param requestID the request Id
+ * @param clnameId the control loop Id
+ * @param actorId the actor Id
+ * @param operationId the operation Id
+ * @param targetId the target Id
+ * @param requestId the request Id
*/
- public PolicyGuardXacmlRequestAttributes(String clnameID, String actorID, String operationID, String targetID,
- String requestID) {
+ public PolicyGuardXacmlRequestAttributes(String clnameId, String actorId, String operationId, String targetId,
+ String requestId) {
super();
- this.clnameID = clnameID;
- this.actorID = actorID;
- this.operationID = operationID;
- this.targetID = targetID;
- this.requestID = requestID;
+ this.clnameID = clnameId;
+ this.actorID = actorId;
+ this.operationID = operationId;
+ this.targetID = targetId;
+ this.requestID = requestId;
}
@Override
*
* @param type the target type
* @param target the target
- * @param requestID the request Id
+ * @param requestId the request Id
* @param callback the callback
*/
- public PNFTargetLock(TargetType type, String target, UUID requestID, LockCallback callback) {
+ public PNFTargetLock(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;
}
import org.junit.Test;
import org.onap.policy.drools.system.PolicyEngine;
-public class PIPEngineGetHistoryTest {
+public class PipEngineGetHistoryTest {
static PIPEngineGetHistory pegh;
private static final String ISSUER = "issuerIntw:mid:end";
}
@Test
- public void testLockTargetTargetTypeStringUUIDLockCallbackInt() throws Exception {
+ public void testLockTargetTargetTypeStringUuidLockCallbackInt() throws Exception {
TargetType type = TargetType.VM;
LockResult<GuardResult, TargetLock> result;
============LICENSE_END=========================================================
-->
<persistence version="2.1"
- xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
+ xmlns="http://xmlns.jcp.org/xml/ns/persistence"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
- <!-- In-mem DB for junit -->
- <persistence-unit name="TestOperationsHistoryPU"
- transaction-type="RESOURCE_LOCAL">
- <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
- <properties>
- <property name="eclipselink.ddl-generation" value="create-or-extend-tables" />
- <property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
- <property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test" />
- <property name="javax.persistence.jdbc.user" value="sa" />
- <property name="javax.persistence.jdbc.password" value="" />
- <property name="eclipselink.logging.level" value="CONFIG" />
- </properties>
- </persistence-unit>
+ <!-- In-mem DB for junit -->
+ <persistence-unit name="TestOperationsHistoryPU"
+ transaction-type="RESOURCE_LOCAL">
+ <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
+ <properties>
+ <property name="eclipselink.ddl-generation"
+ value="create-or-extend-tables" />
+ <property name="javax.persistence.jdbc.driver"
+ value="org.h2.Driver" />
+ <property name="javax.persistence.jdbc.url"
+ value="jdbc:h2:mem:test" />
+ <property name="javax.persistence.jdbc.user"
+ value="sa" />
+ <property name="javax.persistence.jdbc.password"
+ value="" />
+ <property name="eclipselink.logging.level"
+ value="CONFIG" />
+ </properties>
+ </persistence-unit>
</persistence>
limitations under the License.
============LICENSE_END=========================================================
-->
-<Policy xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" PolicyId="urn:com:att:xacml:policy:id:25e12b06-11d5-4895-b2a2-6f6c594de069" Version="1" RuleCombiningAlgId="urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-unless-deny">
- <Description>Policy for frequency limiter.</Description>
- <Target>
- <AnyOf>
- <AllOf>
- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
+<Policy xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17"
+ PolicyId="urn:com:att:xacml:policy:id:25e12b06-11d5-4895-b2a2-6f6c594de069"
+ Version="1"
+ RuleCombiningAlgId="urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-unless-deny">
+ <Description>Policy for frequency limiter.</Description>
+ <Target>
+ <AnyOf>
+ <AllOf>
+ <Match
+ MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
<!-- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">.*</AttributeValue>-->
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">${clname}</AttributeValue>
- <AttributeDesignator Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" AttributeId="urn:oasis:names:tc:xacml:1.0:clname:clname-id" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false"/>
- </Match>
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#string">${clname}</AttributeValue>
+ <AttributeDesignator
+ Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
+ AttributeId="urn:oasis:names:tc:xacml:1.0:clname:clname-id"
+ DataType="http://www.w3.org/2001/XMLSchema#string"
+ MustBePresent="false" />
+ </Match>
- <!-- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">-->
- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">${actor}</AttributeValue>
- <AttributeDesignator Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" AttributeId="urn:oasis:names:tc:xacml:1.0:actor:actor-id" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false"/>
- </Match>
- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">${recipe}</AttributeValue>
- <AttributeDesignator Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action" AttributeId="urn:oasis:names:tc:xacml:1.0:operation:operation-id" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false"/>
- </Match>
- </AllOf>
- </AnyOf>
- </Target>
- <Rule RuleId="urn:com:att:xacml:rule:id:e1e8c5c0-e2ba-47d5-9289-6c015305ed21" Effect="Deny">
- <Description>DENY - only if target is in black list and guard is active.</Description>
- <Condition>
- <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:and">
- <VariableReference VariableId="isGuardActive"/>
- <VariableReference VariableId="isInBlackList"/>
- </Apply>
- </Condition>
- </Rule>
- <VariableDefinition VariableId="isInBlackList">
- <Apply FunctionId="urn:oasis:names:tc:xacml:3.0:function:any-of">
- <Function FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal"/>
- <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-one-and-only">
- <AttributeDesignator Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource" AttributeId="urn:oasis:names:tc:xacml:1.0:target:target-id" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false"/>
- </Apply>
- <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-bag">
- ${blackListElement}
- <!-- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">vserver.vserver-name</AttributeValue>-->
- </Apply>
- </Apply>
- </VariableDefinition>
- <VariableDefinition VariableId="isGuardActive">
- <Apply FunctionId="urn:oasis:names:tc:xacml:2.0:function:time-in-range">
- <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:time-one-and-only">
- <AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:environment:current-time" DataType="http://www.w3.org/2001/XMLSchema#time" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:environment" MustBePresent="false"/>
- </Apply>
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveStart}</AttributeValue>
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveEnd}</AttributeValue>
- </Apply>
- </VariableDefinition>
+ <!-- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">-->
+ <Match
+ MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#string">${actor}</AttributeValue>
+ <AttributeDesignator
+ Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
+ AttributeId="urn:oasis:names:tc:xacml:1.0:actor:actor-id"
+ DataType="http://www.w3.org/2001/XMLSchema#string"
+ MustBePresent="false" />
+ </Match>
+ <Match
+ MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#string">${recipe}</AttributeValue>
+ <AttributeDesignator
+ Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action"
+ AttributeId="urn:oasis:names:tc:xacml:1.0:operation:operation-id"
+ DataType="http://www.w3.org/2001/XMLSchema#string"
+ MustBePresent="false" />
+ </Match>
+ </AllOf>
+ </AnyOf>
+ </Target>
+ <Rule
+ RuleId="urn:com:att:xacml:rule:id:e1e8c5c0-e2ba-47d5-9289-6c015305ed21"
+ Effect="Deny">
+ <Description>DENY - only if target is in black list and guard is
+ active.</Description>
+ <Condition>
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:1.0:function:and">
+ <VariableReference
+ VariableId="isGuardActive" />
+ <VariableReference
+ VariableId="isInBlackList" />
+ </Apply>
+ </Condition>
+ </Rule>
+ <VariableDefinition VariableId="isInBlackList">
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:3.0:function:any-of">
+ <Function
+ FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal" />
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-one-and-only">
+ <AttributeDesignator
+ Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
+ AttributeId="urn:oasis:names:tc:xacml:1.0:target:target-id"
+ DataType="http://www.w3.org/2001/XMLSchema#string"
+ MustBePresent="false" />
+ </Apply>
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-bag">
+ ${blackListElement}
+ <!-- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">vserver.vserver-name</AttributeValue>-->
+ </Apply>
+ </Apply>
+ </VariableDefinition>
+ <VariableDefinition VariableId="isGuardActive">
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:2.0:function:time-in-range">
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:1.0:function:time-one-and-only">
+ <AttributeDesignator
+ AttributeId="urn:oasis:names:tc:xacml:1.0:environment:current-time"
+ DataType="http://www.w3.org/2001/XMLSchema#time"
+ Category="urn:oasis:names:tc:xacml:3.0:attribute-category:environment"
+ MustBePresent="false" />
+ </Apply>
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveStart}</AttributeValue>
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveEnd}</AttributeValue>
+ </Apply>
+ </VariableDefinition>
</Policy>
limitations under the License.
============LICENSE_END=========================================================
-->
-<Policy xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" PolicyId="urn:com:att:xacml:policy:id:25e12b06-11d5-4895-b2a2-6f6c594de069" Version="1" RuleCombiningAlgId="urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-unless-deny">
- <Description>Policy for frequency limiter.</Description>
- <Target>
- <AnyOf>
- <AllOf>
-
- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
+<Policy xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17"
+ PolicyId="urn:com:att:xacml:policy:id:25e12b06-11d5-4895-b2a2-6f6c594de069"
+ Version="1"
+ RuleCombiningAlgId="urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-unless-deny">
+ <Description>Policy for frequency limiter.</Description>
+ <Target>
+ <AnyOf>
+ <AllOf>
+
+ <Match
+ MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
<!-- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">.*</AttributeValue>-->
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">${clname}</AttributeValue>
- <AttributeDesignator Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" AttributeId="urn:oasis:names:tc:xacml:1.0:clname:clname-id" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false"/>
- </Match>
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#string">${clname}</AttributeValue>
+ <AttributeDesignator
+ Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
+ AttributeId="urn:oasis:names:tc:xacml:1.0:clname:clname-id"
+ DataType="http://www.w3.org/2001/XMLSchema#string"
+ MustBePresent="false" />
+ </Match>
- <!-- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">-->
- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">${actor}</AttributeValue>
- <AttributeDesignator Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" AttributeId="urn:oasis:names:tc:xacml:1.0:actor:actor-id" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false"/>
- </Match>
- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">${recipe}</AttributeValue>
- <AttributeDesignator Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action" AttributeId="urn:oasis:names:tc:xacml:1.0:operation:operation-id" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false"/>
- </Match>
-
- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">${targets}</AttributeValue>
- <AttributeDesignator Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource" AttributeId="urn:oasis:names:tc:xacml:1.0:target:target-id" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false"/>
- </Match>
-
- </AllOf>
- </AnyOf>
- </Target>
- <Rule RuleId="urn:com:att:xacml:rule:id:e1e8c5c0-e2ba-47d5-9289-6c015305ed21" Effect="Deny">
- <Description>DENY - only if number of operations performed in the past is larger than the limit and the Guard is active.</Description>
- <Condition>
- <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:and">
- <VariableReference VariableId="isGuardActive"/>
- <VariableReference VariableId="isHistoryGreaterThanLimit"/>
- </Apply>
- </Condition>
- </Rule>
- <VariableDefinition VariableId="isGuardActive">
- <Apply FunctionId="urn:oasis:names:tc:xacml:2.0:function:time-in-range">
- <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:time-one-and-only">
- <AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:environment:current-time" DataType="http://www.w3.org/2001/XMLSchema#time" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:environment" MustBePresent="false"/>
- </Apply>
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveStart}</AttributeValue>
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveEnd}</AttributeValue>
- </Apply>
- </VariableDefinition>
- <VariableDefinition VariableId="isHistoryGreaterThanLimit">
- <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:integer-greater-than-or-equal">
- <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:integer-one-and-only">
- <AttributeDesignator Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource" AttributeId="com:att:research:xacml:test:sql:resource:operations:count" DataType="http://www.w3.org/2001/XMLSchema#integer" Issuer="com:att:research:xacml:guard:historydb:tw:${twValue}:${twUnits}" MustBePresent="false"/>
- </Apply>
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#integer">${limit}</AttributeValue>
- </Apply>
- </VariableDefinition>
+ <!-- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">-->
+ <Match
+ MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#string">${actor}</AttributeValue>
+ <AttributeDesignator
+ Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
+ AttributeId="urn:oasis:names:tc:xacml:1.0:actor:actor-id"
+ DataType="http://www.w3.org/2001/XMLSchema#string"
+ MustBePresent="false" />
+ </Match>
+ <Match
+ MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#string">${recipe}</AttributeValue>
+ <AttributeDesignator
+ Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action"
+ AttributeId="urn:oasis:names:tc:xacml:1.0:operation:operation-id"
+ DataType="http://www.w3.org/2001/XMLSchema#string"
+ MustBePresent="false" />
+ </Match>
+
+ <Match
+ MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#string">${targets}</AttributeValue>
+ <AttributeDesignator
+ Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
+ AttributeId="urn:oasis:names:tc:xacml:1.0:target:target-id"
+ DataType="http://www.w3.org/2001/XMLSchema#string"
+ MustBePresent="false" />
+ </Match>
+
+ </AllOf>
+ </AnyOf>
+ </Target>
+ <Rule
+ RuleId="urn:com:att:xacml:rule:id:e1e8c5c0-e2ba-47d5-9289-6c015305ed21"
+ Effect="Deny">
+ <Description>DENY - only if number of operations performed in
+ the past is larger than the limit and the Guard is active.</Description>
+ <Condition>
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:1.0:function:and">
+ <VariableReference
+ VariableId="isGuardActive" />
+ <VariableReference
+ VariableId="isHistoryGreaterThanLimit" />
+ </Apply>
+ </Condition>
+ </Rule>
+ <VariableDefinition VariableId="isGuardActive">
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:2.0:function:time-in-range">
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:1.0:function:time-one-and-only">
+ <AttributeDesignator
+ AttributeId="urn:oasis:names:tc:xacml:1.0:environment:current-time"
+ DataType="http://www.w3.org/2001/XMLSchema#time"
+ Category="urn:oasis:names:tc:xacml:3.0:attribute-category:environment"
+ MustBePresent="false" />
+ </Apply>
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveStart}</AttributeValue>
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveEnd}</AttributeValue>
+ </Apply>
+ </VariableDefinition>
+ <VariableDefinition
+ VariableId="isHistoryGreaterThanLimit">
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:1.0:function:integer-greater-than-or-equal">
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:1.0:function:integer-one-and-only">
+ <AttributeDesignator
+ Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
+ AttributeId="com:att:research:xacml:test:sql:resource:operations:count"
+ DataType="http://www.w3.org/2001/XMLSchema#integer"
+ Issuer="com:att:research:xacml:guard:historydb:tw:${twValue}:${twUnits}"
+ MustBePresent="false" />
+ </Apply>
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#integer">${limit}</AttributeValue>
+ </Apply>
+ </VariableDefinition>
</Policy>
* ============LICENSE_START=======================================================
* aai
* ================================================================================
- * 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.
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
</dependency>
</dependencies>
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-checkstyle-plugin</artifactId>
- <executions>
- <execution>
- <id>onap-java-style</id>
- <goals>
- <goal>check</goal>
- </goals>
- <phase>process-sources</phase>
- <configuration>
- <!-- Use Google Java Style Guide:
- https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml
- with minor changes -->
- <configLocation>onap-checkstyle/onap-java-style.xml</configLocation>
- <!-- <sourceDirectory> is needed so that checkstyle ignores the generated sources directory -->
- <sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
- <includeResources>true</includeResources>
- <includeTestSourceDirectory>true</includeTestSourceDirectory>
- <includeTestResources>true</includeTestResources>
- <excludes>
- </excludes>
- <consoleOutput>true</consoleOutput>
- <failOnViolation>true</failOnViolation>
- <violationSeverity>warning</violationSeverity>
- </configuration>
- </execution>
- </executions>
- <dependencies>
- <dependency>
- <groupId>org.onap.oparent</groupId>
- <artifactId>checkstyle</artifactId>
- <version>0.1.1</version>
- <scope>compile</scope>
- </dependency>
- </dependencies>
- </plugin>
- </plugins>
- </build>
</project>
</dependency>
</dependencies>
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-checkstyle-plugin</artifactId>
- <executions>
- <execution>
- <id>onap-java-style</id>
- <goals>
- <goal>check</goal>
- </goals>
- <phase>process-sources</phase>
- <configuration>
- <!-- Use Google Java Style Guide:
- https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml
- with minor changes -->
- <configLocation>onap-checkstyle/onap-java-style.xml</configLocation>
- <!-- <sourceDirectory> is needed so that checkstyle ignores the generated sources directory -->
- <sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
- <includeResources>true</includeResources>
- <includeTestSourceDirectory>true</includeTestSourceDirectory>
- <includeTestResources>true</includeTestResources>
- <excludes>
- </excludes>
- <consoleOutput>true</consoleOutput>
- <failOnViolation>true</failOnViolation>
- <violationSeverity>warning</violationSeverity>
- </configuration>
- </execution>
- </executions>
- <dependencies>
- <dependency>
- <groupId>org.onap.oparent</groupId>
- <artifactId>checkstyle</artifactId>
- <version>0.1.1</version>
- <scope>compile</scope>
- </dependency>
- </dependencies>
- </plugin>
- </plugins>
- </build>
</project>
<scope>test</scope>
</dependency>
</dependencies>
-
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-checkstyle-plugin</artifactId>
- <executions>
- <execution>
- <id>onap-java-style</id>
- <goals>
- <goal>check</goal>
- </goals>
- <phase>process-sources</phase>
- <configuration>
- <!-- Use Google Java Style Guide:
- https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml
- with minor changes -->
- <configLocation>onap-checkstyle/onap-java-style.xml</configLocation>
- <!-- <sourceDirectory> is needed so that checkstyle ignores the generated sources directory -->
- <sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
- <includeResources>true</includeResources>
- <includeTestSourceDirectory>true</includeTestSourceDirectory>
- <includeTestResources>true</includeTestResources>
- <excludes>
- </excludes>
- <consoleOutput>true</consoleOutput>
- <failOnViolation>true</failOnViolation>
- <violationSeverity>warning</violationSeverity>
- </configuration>
- </execution>
- </executions>
- <dependencies>
- <dependency>
- <groupId>org.onap.oparent</groupId>
- <artifactId>checkstyle</artifactId>
- <version>0.1.1</version>
- <scope>compile</scope>
- </dependency>
- </dependencies>
- </plugin>
- </plugins>
- </build>
</project>
}
}
+ /**
+ * Perform REST Post.
+ *
+ * @param url the url
+ * @param username the user name
+ * @param password the password
+ * @param headers any headers
+ * @param contentType what the content type is
+ * @param body body to send
+ * @return the response status code and the body
+ */
public Pair<Integer, String> post(String url, String username, String password,
Map<String, String> headers, String contentType, String body) {
}
}
post.addHeader("Content-Type", contentType);
- if(authHeader != null) {
+ if (authHeader != null) {
post.setHeader(HttpHeaders.AUTHORIZATION, authHeader);
}
}
}
+ /**
+ * Do a REST get.
+ *
+ * @param url URL
+ * @param username user name
+ * @param password password
+ * @param headers any headers to add
+ * @return a Pair for the response status and the body
+ */
public Pair<Integer, String> get(String url, String username, String password,
Map<String, String> headers) {
get.addHeader(entry.getKey(), headers.get(entry.getKey()));
}
}
- if(authHeader != null) {
+ if (authHeader != null) {
get.setHeader(HttpHeaders.AUTHORIZATION, authHeader);
}
* ============LICENSE_START=======================================================
* sdc
* ================================================================================
- * 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.
private static final long serialVersionUID = -913729158733348027L;
- private UUID resourceUUID;
- private UUID resourceInvariantUUID;
+ private UUID resourceUuid;
+ private UUID resourceInvariantUuid;
private String resourceName;
private String resourceVersion;
private ResourceType resourceType;
//Empty Constructor
}
+ /**
+ * Constructor.
+ *
+ * @param resource copy object
+ */
public Resource(Resource resource) {
- this.resourceUUID = resource.resourceUUID;
- this.resourceInvariantUUID = resource.resourceInvariantUUID;
+ this.resourceUuid = resource.resourceUuid;
+ this.resourceInvariantUuid = resource.resourceInvariantUuid;
this.resourceName = resource.resourceName;
this.resourceVersion = resource.resourceVersion;
this.resourceType = resource.resourceType;
}
public Resource(UUID uuid) {
- this.resourceUUID = uuid;
+ this.resourceUuid = uuid;
}
public Resource(String name, ResourceType type) {
this.resourceType = type;
}
- public Resource(UUID uuid, UUID invariantUUID, String name, String version, ResourceType type) {
- this.resourceUUID = uuid;
- this.resourceInvariantUUID = invariantUUID;
+ /**
+ * Constructor.
+ *
+ * @param uuid uuid
+ * @param invariantUuid invariant uuid
+ * @param name name
+ * @param version version
+ * @param type type
+ */
+ public Resource(UUID uuid, UUID invariantUuid, String name, String version, ResourceType type) {
+ this.resourceUuid = uuid;
+ this.resourceInvariantUuid = invariantUuid;
this.resourceName = name;
this.resourceVersion = version;
this.resourceType = type;
}
- public UUID getResourceUUID() {
- return resourceUUID;
+ public UUID getResourceUuid() {
+ return resourceUuid;
}
- public void setResourceUUID(UUID resourceUUID) {
- this.resourceUUID = resourceUUID;
+ public void setResourceUuid(UUID resourceUuid) {
+ this.resourceUuid = resourceUuid;
}
- public UUID getResourceInvariantUUID() {
- return resourceInvariantUUID;
+ public UUID getResourceInvariantUuid() {
+ return resourceInvariantUuid;
}
- public void setResourceInvariantUUID(UUID resourceInvariantUUID) {
- this.resourceInvariantUUID = resourceInvariantUUID;
+ public void setResourceInvariantUuid(UUID resourceInvariantUuid) {
+ this.resourceInvariantUuid = resourceInvariantUuid;
}
public String getResourceName() {
@Override
public String toString() {
- return "Resource [resourceUUID=" + resourceUUID + ", resourceInvariantUUID=" + resourceInvariantUUID
+ return "Resource [resourceUUID=" + resourceUuid + ", resourceInvariantUUID=" + resourceInvariantUuid
+ ", resourceName=" + resourceName + ", resourceVersion=" + resourceVersion + ", resourceType="
+ resourceType + "]";
}
+
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + ((resourceInvariantUUID == null) ? 0 : resourceInvariantUUID.hashCode());
+ result = prime * result + ((resourceInvariantUuid == null) ? 0 : resourceInvariantUuid.hashCode());
result = prime * result + ((resourceName == null) ? 0 : resourceName.hashCode());
result = prime * result + ((resourceType == null) ? 0 : resourceType.hashCode());
- result = prime * result + ((resourceUUID == null) ? 0 : resourceUUID.hashCode());
+ result = prime * result + ((resourceUuid == null) ? 0 : resourceUuid.hashCode());
result = prime * result + ((resourceVersion == null) ? 0 : resourceVersion.hashCode());
return result;
}
+
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
Resource other = (Resource) obj;
- if (resourceInvariantUUID == null) {
- if (other.resourceInvariantUUID != null)
+ if (resourceInvariantUuid == null) {
+ if (other.resourceInvariantUuid != null) {
return false;
- } else if (!resourceInvariantUUID.equals(other.resourceInvariantUUID))
+ }
+ } else if (!resourceInvariantUuid.equals(other.resourceInvariantUuid)) {
return false;
+ }
if (resourceName == null) {
- if (other.resourceName != null)
+ if (other.resourceName != null) {
return false;
- } else if (!resourceName.equals(other.resourceName))
+ }
+ } else if (!resourceName.equals(other.resourceName)) {
return false;
+ }
if (resourceType == null) {
- if (other.resourceType != null)
+ if (other.resourceType != null) {
return false;
- } else if (!resourceType.equals(other.resourceType))
+ }
+ } else if (!resourceType.equals(other.resourceType)) {
return false;
- if (resourceUUID == null) {
- if (other.resourceUUID != null)
+ }
+ if (resourceUuid == null) {
+ if (other.resourceUuid != null) {
return false;
- } else if (!resourceUUID.equals(other.resourceUUID))
+ }
+ } else if (!resourceUuid.equals(other.resourceUuid)) {
return false;
+ }
if (resourceVersion == null) {
- if (other.resourceVersion != null)
+ if (other.resourceVersion != null) {
return false;
- } else if (!resourceVersion.equals(other.resourceVersion))
+ }
+ } else if (!resourceVersion.equals(other.resourceVersion)) {
return false;
+ }
return true;
}
* ============LICENSE_START=======================================================
* sdc
* ================================================================================
- * 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.
private String resourceInstanceName;
private String resourceName;
- private UUID resourceInvariantUUID;
+ private UUID resourceInvariantUuid;
private String resourceVersion;
private ResourceType resourceType;
- private UUID resourceUUID;
+ private UUID resourceUuid;
public ResourceInstance() {
//Empty Constructor
}
+ /**
+ * Constructor.
+ *
+ * @param instance copy object
+ */
public ResourceInstance(ResourceInstance instance) {
if (instance == null) {
return;
}
this.resourceInstanceName = instance.resourceInstanceName;
this.resourceName = instance.resourceName;
- this.resourceInvariantUUID = instance.resourceInvariantUUID;
+ this.resourceInvariantUuid = instance.resourceInvariantUuid;
this.resourceVersion = instance.resourceVersion;
this.resourceType = instance.resourceType;
- this.resourceUUID = instance.resourceUUID;
+ this.resourceUuid = instance.resourceUuid;
}
public String getResourceInstanceName() {
}
public UUID getResourceInvariantUUID() {
- return resourceInvariantUUID;
+ return resourceInvariantUuid;
}
- public void setResourceInvariantUUID(UUID resourceInvariantUUID) {
- this.resourceInvariantUUID = resourceInvariantUUID;
+ public void setResourceInvariantUUID(UUID resourceInvariantUuid) {
+ this.resourceInvariantUuid = resourceInvariantUuid;
}
public String getResourceVersion() {
this.resourceType = resourceType;
}
- public UUID getResourceUUID() {
- return resourceUUID;
+ public UUID getResourceUuid() {
+ return resourceUuid;
}
- public void setResourceUUID(UUID resourceUUID) {
- this.resourceUUID = resourceUUID;
+ public void setResourceUuid(UUID resourceUuid) {
+ this.resourceUuid = resourceUuid;
}
@Override
public String toString() {
return "ResourceInstance [resourceInstanceName=" + resourceInstanceName + ", resourceName=" + resourceName
- + ", resourceInvariantUUID=" + resourceInvariantUUID + ", resourceVersion=" + resourceVersion
- + ", resourceType=" + resourceType + ", resourceUUID=" + resourceUUID + "]";
+ + ", resourceInvariantUUID=" + resourceInvariantUuid + ", resourceVersion=" + resourceVersion
+ + ", resourceType=" + resourceType + ", resourceUUID=" + resourceUuid + "]";
}
+
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((resourceInstanceName == null) ? 0 : resourceInstanceName.hashCode());
- result = prime * result + ((resourceInvariantUUID == null) ? 0 : resourceInvariantUUID.hashCode());
+ result = prime * result + ((resourceInvariantUuid == null) ? 0 : resourceInvariantUuid.hashCode());
result = prime * result + ((resourceName == null) ? 0 : resourceName.hashCode());
result = prime * result + ((resourceType == null) ? 0 : resourceType.hashCode());
- result = prime * result + ((resourceUUID == null) ? 0 : resourceUUID.hashCode());
+ result = prime * result + ((resourceUuid == null) ? 0 : resourceUuid.hashCode());
result = prime * result + ((resourceVersion == null) ? 0 : resourceVersion.hashCode());
return result;
}
+
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
ResourceInstance other = (ResourceInstance) obj;
if (resourceInstanceName == null) {
- if (other.resourceInstanceName != null)
+ if (other.resourceInstanceName != null) {
return false;
- } else if (!resourceInstanceName.equals(other.resourceInstanceName))
+ }
+ } else if (!resourceInstanceName.equals(other.resourceInstanceName)) {
return false;
- if (resourceInvariantUUID == null) {
- if (other.resourceInvariantUUID != null)
+ }
+ if (resourceInvariantUuid == null) {
+ if (other.resourceInvariantUuid != null) {
return false;
- } else if (!resourceInvariantUUID.equals(other.resourceInvariantUUID))
+ }
+ } else if (!resourceInvariantUuid.equals(other.resourceInvariantUuid)) {
return false;
+ }
if (resourceName == null) {
- if (other.resourceName != null)
+ if (other.resourceName != null) {
return false;
- } else if (!resourceName.equals(other.resourceName))
+ }
+ } else if (!resourceName.equals(other.resourceName)) {
return false;
- if (resourceType != other.resourceType)
+ }
+ if (resourceType != other.resourceType) {
return false;
- if (resourceUUID == null) {
- if (other.resourceUUID != null)
+ }
+ if (resourceUuid == null) {
+ if (other.resourceUuid != null) {
return false;
- } else if (!resourceUUID.equals(other.resourceUUID))
+ }
+ } else if (!resourceUuid.equals(other.resourceUuid)) {
return false;
+ }
if (resourceVersion == null) {
- if (other.resourceVersion != null)
+ if (other.resourceVersion != null) {
return false;
- } else if (!resourceVersion.equals(other.resourceVersion))
+ }
+ } else if (!resourceVersion.equals(other.resourceVersion)) {
return false;
+ }
return true;
}
* ============LICENSE_START=======================================================
* sdc
* ================================================================================
- * 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.
package org.onap.policy.sdc;
public enum ResourceType {
- VF("VF"),
- VFC("VFC"),
- VL("VL"),
- CP("CP")
- ;
-
- private String type;
-
- private ResourceType(String type) {
- this.type = type;
- }
+ VF("VF"),
+ VFC("VFC"),
+ VL("VL"),
+ CP("CP")
+ ;
+
+ private String type;
+
+ private ResourceType(String type) {
+ this.type = type;
+ }
+
+ @Override
+ public String toString() {
+ return this.type;
+ }
- @Override
- public String toString() {
- return this.type;
- }
-
}
* ============LICENSE_START=======================================================
* sdc
* ================================================================================
- * 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.
this.serviceName = name;
}
+ /**
+ * Constructor.
+ *
+ * @param uuid service id
+ * @param invariantUUID service invariant id
+ * @param name name
+ * @param version version
+ */
public Service(UUID uuid, UUID invariantUUID, String name, String version) {
this.serviceUUID = uuid;
this.serviceInvariantUUID = invariantUUID;
this.serviceVersion = version;
}
+ /**
+ * Constructor.
+ *
+ * @param service copy object
+ */
public Service(Service service) {
this.serviceUUID = service.serviceUUID;
this.serviceInvariantUUID = service.serviceInvariantUUID;
return "Service [serviceUUID=" + serviceUUID + ", serviceInvariantUUID=" + serviceInvariantUUID
+ ", serviceName=" + serviceName + ", serviceVersion=" + serviceVersion + "]";
}
+
@Override
public int hashCode() {
final int prime = 31;
result = prime * result + ((serviceVersion == null) ? 0 : serviceVersion.hashCode());
return result;
}
+
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
Service other = (Service) obj;
if (serviceInvariantUUID == null) {
- if (other.serviceInvariantUUID != null)
+ if (other.serviceInvariantUUID != null) {
return false;
- } else if (!serviceInvariantUUID.equals(other.serviceInvariantUUID))
+ }
+ } else if (!serviceInvariantUUID.equals(other.serviceInvariantUUID)) {
return false;
+ }
if (serviceName == null) {
- if (other.serviceName != null)
+ if (other.serviceName != null) {
return false;
- } else if (!serviceName.equals(other.serviceName))
+ }
+ } else if (!serviceName.equals(other.serviceName)) {
return false;
+ }
if (serviceUUID == null) {
- if (other.serviceUUID != null)
+ if (other.serviceUUID != null) {
return false;
- } else if (!serviceUUID.equals(other.serviceUUID))
+ }
+ } else if (!serviceUUID.equals(other.serviceUUID)) {
return false;
+ }
if (serviceVersion == null) {
- if (other.serviceVersion != null)
+ if (other.serviceVersion != null) {
return false;
- } else if (!serviceVersion.equals(other.serviceVersion))
+ }
+ } else if (!serviceVersion.equals(other.serviceVersion)) {
return false;
+ }
return true;
}
* ============LICENSE_START=======================================================
* sdc
* ================================================================================
- * 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.
//Empty Constructor
}
+ /**
+ * Constructor.
+ *
+ * @param instance copy object
+ */
public ServiceInstance(ServiceInstance instance) {
if (instance == null) {
return;
+ ", widgetModelVersion=" + widgetModelVersion + ", serviceName=" + serviceName
+ ", serviceInstanceName=" + serviceInstanceName + "]";
}
+
@Override
public int hashCode() {
final int prime = 31;
result = prime * result + ((widgetModelVersion == null) ? 0 : widgetModelVersion.hashCode());
return result;
}
+
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
ServiceInstance other = (ServiceInstance) obj;
if (personaModelUUID == null) {
- if (other.personaModelUUID != null)
+ if (other.personaModelUUID != null) {
return false;
- } else if (!personaModelUUID.equals(other.personaModelUUID))
+ }
+ } else if (!personaModelUUID.equals(other.personaModelUUID)) {
return false;
+ }
if (serviceInstanceName == null) {
- if (other.serviceInstanceName != null)
+ if (other.serviceInstanceName != null) {
return false;
- } else if (!serviceInstanceName.equals(other.serviceInstanceName))
+ }
+ } else if (!serviceInstanceName.equals(other.serviceInstanceName)) {
return false;
+ }
if (serviceInstanceUUID == null) {
- if (other.serviceInstanceUUID != null)
+ if (other.serviceInstanceUUID != null) {
return false;
- } else if (!serviceInstanceUUID.equals(other.serviceInstanceUUID))
+ }
+ } else if (!serviceInstanceUUID.equals(other.serviceInstanceUUID)) {
return false;
+ }
if (serviceName == null) {
- if (other.serviceName != null)
+ if (other.serviceName != null) {
return false;
- } else if (!serviceName.equals(other.serviceName))
+ }
+ } else if (!serviceName.equals(other.serviceName)) {
return false;
+ }
if (serviceUUID == null) {
- if (other.serviceUUID != null)
+ if (other.serviceUUID != null) {
return false;
- } else if (!serviceUUID.equals(other.serviceUUID))
+ }
+ } else if (!serviceUUID.equals(other.serviceUUID)) {
return false;
+ }
if (widgetModelUUID == null) {
- if (other.widgetModelUUID != null)
+ if (other.widgetModelUUID != null) {
return false;
- } else if (!widgetModelUUID.equals(other.widgetModelUUID))
+ }
+ } else if (!widgetModelUUID.equals(other.widgetModelUUID)) {
return false;
+ }
if (widgetModelVersion == null) {
- if (other.widgetModelVersion != null)
+ if (other.widgetModelVersion != null) {
return false;
- } else if (!widgetModelVersion.equals(other.widgetModelVersion))
+ }
+ } else if (!widgetModelVersion.equals(other.widgetModelVersion)) {
return false;
+ }
return true;
}
@Test
public void testConstructors() {
Resource res = new Resource();
- assertEquals(null, res.getResourceUUID());
- assertEquals(null, res.getResourceInvariantUUID());
+ assertEquals(null, res.getResourceUuid());
+ assertEquals(null, res.getResourceInvariantUuid());
assertEquals(null, res.getResourceName());
assertEquals(null, res.getResourceType());
assertEquals(null, res.getResourceVersion());
UUID uuid = UUID.randomUUID();
res = new Resource(uuid);
- assertEquals(uuid, res.getResourceUUID());
- assertEquals(null, res.getResourceInvariantUUID());
+ assertEquals(uuid, res.getResourceUuid());
+ assertEquals(null, res.getResourceInvariantUuid());
assertEquals(null, res.getResourceName());
assertEquals(null, res.getResourceType());
assertEquals(null, res.getResourceVersion());
String name = "constTest";
res = new Resource(name, ResourceType.CP);
- assertEquals(null, res.getResourceUUID());
+ assertEquals(null, res.getResourceUuid());
assertEquals(name, res.getResourceName());
assertEquals(ResourceType.CP, res.getResourceType());
- assertEquals(null, res.getResourceInvariantUUID());
+ assertEquals(null, res.getResourceInvariantUuid());
assertEquals(null, res.getResourceVersion());
uuid = UUID.randomUUID();
name = "constTestUUID";
String version = "0.0.1";
res = new Resource(uuid, uuidInvariant, name, version, ResourceType.VF);
- assertEquals(uuid, res.getResourceUUID());
- assertEquals(uuidInvariant, res.getResourceInvariantUUID());
+ assertEquals(uuid, res.getResourceUuid());
+ assertEquals(uuidInvariant, res.getResourceInvariantUuid());
assertEquals(name, res.getResourceName());
assertEquals(ResourceType.VF, res.getResourceType());
assertEquals(version, res.getResourceVersion());
Resource r2 = new Resource(res);
- assertEquals(uuid, r2.getResourceUUID());
- assertEquals(uuidInvariant, r2.getResourceInvariantUUID());
+ assertEquals(uuid, r2.getResourceUuid());
+ assertEquals(uuidInvariant, r2.getResourceInvariantUuid());
assertEquals(name, r2.getResourceName());
assertEquals(ResourceType.VF, r2.getResourceType());
assertEquals(version, r2.getResourceVersion());
public void testUuid() {
Resource res = new Resource();
UUID uuid = UUID.randomUUID();
- res.setResourceUUID(uuid);
- assertEquals(uuid, res.getResourceUUID());
+ res.setResourceUuid(uuid);
+ assertEquals(uuid, res.getResourceUuid());
}
@Test
public void testInvariantUuid() {
Resource res = new Resource();
UUID uuid = UUID.randomUUID();
- res.setResourceInvariantUUID(uuid);
- assertEquals(uuid, res.getResourceInvariantUUID());
+ res.setResourceInvariantUuid(uuid);
+ assertEquals(uuid, res.getResourceInvariantUuid());
}
@Test
public void testConstructors() {
ResourceInstance ri = new ResourceInstance();
assertEquals(null, ri.getResourceInstanceName());
- assertEquals(null, ri.getResourceUUID());
+ assertEquals(null, ri.getResourceUuid());
assertEquals(null, ri.getResourceInvariantUUID());
assertEquals(null, ri.getResourceName());
assertEquals(null, ri.getResourceType());
ResourceInstance ri2 = new ResourceInstance((ResourceInstance) null);
assertEquals(null, ri2.getResourceInstanceName());
- assertEquals(null, ri2.getResourceUUID());
+ assertEquals(null, ri2.getResourceUuid());
assertEquals(null, ri2.getResourceInvariantUUID());
assertEquals(null, ri2.getResourceName());
assertEquals(null, ri2.getResourceType());
ri2 = new ResourceInstance(ri);
assertEquals(ri2.getResourceInstanceName(), ri.getResourceInstanceName());
- assertEquals(ri2.getResourceUUID(), ri.getResourceUUID());
+ assertEquals(ri2.getResourceUuid(), ri.getResourceUuid());
assertEquals(ri2.getResourceInvariantUUID(), ri.getResourceInvariantUUID());
assertEquals(ri2.getResourceName(), ri.getResourceName());
assertEquals(ri2.getResourceType(), ri.getResourceType());
public void testUuid() {
ResourceInstance ri = new ResourceInstance();
UUID uuid = UUID.randomUUID();
- ri.setResourceUUID(uuid);
- assertEquals(uuid, ri.getResourceUUID());
+ ri.setResourceUuid(uuid);
+ assertEquals(uuid, ri.getResourceUuid());
}
@Test
* ============LICENSE_START=======================================================
* so
* ================================================================================
- * 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.
package org.onap.policy.so;
+import com.google.gson.annotations.SerializedName;
+
import java.io.Serializable;
import java.time.LocalDateTime;
-import com.google.gson.annotations.SerializedName;
-
public class SOAsyncRequestStatus implements Serializable {
private static final long serialVersionUID = -3283942659786236032L;
* ============LICENSE_START=======================================================
* so
* ================================================================================
- * 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.
package org.onap.policy.so;
-import java.io.Serializable;
-
import com.google.gson.annotations.SerializedName;
+import java.io.Serializable;
+
public class SOCloudConfiguration implements Serializable {
private static final long serialVersionUID = -3283942659786236032L;
* ============LICENSE_START=======================================================
* so
* ================================================================================
- * 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.
package org.onap.policy.so;
-import java.io.Serializable;
-
import com.google.gson.annotations.SerializedName;
+import java.io.Serializable;
+
public class SOInstanceReferences implements Serializable {
private static final long serialVersionUID = -3283942659786236032L;
private long restGetTimeout = GET_REQUEST_WAIT_INTERVAL;
/**
- * Default constructor
+ * Default constructor.
*/
public SOManager() {
restManager = new RESTManager();
/**
* This method makes an asynchronous Rest call to MSO and inserts the response into
* Drools working memory.
- *
+ *
+ * @param requestID request id
* @param wm the Drools working memory
- * @param url the URL to use on the POST request
- * @param urlBase the SO base URL
- * @param username user name for SO requests
- * @param password password for SO requests
+ * @param serviceInstanceId service instance id
+ * @param vnfInstanceId vnf instance id
* @param request the SO request
* @return a concurrent Future for the thread that handles the request
*/
* ============LICENSE_START=======================================================
* so
* ================================================================================
- * 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.
package org.onap.policy.so;
-import java.io.Serializable;
-
import com.google.gson.annotations.SerializedName;
+import java.io.Serializable;
+
public class SOModelInfo implements Serializable {
private static final long serialVersionUID = -3283942659786236032L;
* ============LICENSE_START=======================================================
* so
* ================================================================================
- * 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.
package org.onap.policy.so;
-import java.io.Serializable;
-
import com.google.gson.annotations.SerializedName;
+import java.io.Serializable;
+
public class SOPolicyExceptionHolder implements Serializable {
private static final long serialVersionUID = -3283942659786236032L;
* ============LICENSE_START=======================================================
* so
* ================================================================================
- * 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.
package org.onap.policy.so;
-import java.io.Serializable;
-
import com.google.gson.annotations.SerializedName;
+import java.io.Serializable;
+
public class SORelatedInstance implements Serializable {
private static final long serialVersionUID = -3283942659786236032L;
* ============LICENSE_START=======================================================
* so
* ================================================================================
- * 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.
package org.onap.policy.so;
-import java.io.Serializable;
-
import com.google.gson.annotations.SerializedName;
+import java.io.Serializable;
+
public class SORelatedInstanceListElement implements Serializable {
private static final long serialVersionUID = -3283942659786236032L;
* ============LICENSE_START=======================================================
* so
* ================================================================================
- * 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.
package org.onap.policy.so;
+import com.google.gson.annotations.SerializedName;
+
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.UUID;
-import com.google.gson.annotations.SerializedName;
-
public class SORequest implements Serializable {
private static final long serialVersionUID = -3283942659786236032L;
package org.onap.policy.so;
+import com.google.gson.annotations.SerializedName;
+
import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import com.google.gson.annotations.SerializedName;
public class SORequestDetails implements Serializable {
}
+ /**
+ * Constructor.
+ *
+ * @param soRequestDetails copy object
+ */
public SORequestDetails(SORequestDetails soRequestDetails) {
this.modelInfo = soRequestDetails.modelInfo;
this.cloudConfiguration = soRequestDetails.cloudConfiguration;
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
SORequestDetails other = (SORequestDetails) obj;
if (cloudConfiguration == null) {
- if (other.cloudConfiguration != null)
+ if (other.cloudConfiguration != null) {
return false;
- } else if (!cloudConfiguration.equals(other.cloudConfiguration))
+ }
+ } else if (!cloudConfiguration.equals(other.cloudConfiguration)) {
return false;
+ }
if (configurationParameters == null) {
- if (other.configurationParameters != null)
+ if (other.configurationParameters != null) {
return false;
- } else if (!configurationParameters.equals(other.configurationParameters))
+ }
+ } else if (!configurationParameters.equals(other.configurationParameters)) {
return false;
+ }
if (modelInfo == null) {
- if (other.modelInfo != null)
+ if (other.modelInfo != null) {
return false;
- } else if (!modelInfo.equals(other.modelInfo))
+ }
+ } else if (!modelInfo.equals(other.modelInfo)) {
return false;
+ }
if (relatedInstanceList == null) {
- if (other.relatedInstanceList != null)
+ if (other.relatedInstanceList != null) {
return false;
- } else if (!relatedInstanceList.equals(other.relatedInstanceList))
+ }
+ } else if (!relatedInstanceList.equals(other.relatedInstanceList)) {
return false;
+ }
if (requestInfo == null) {
- if (other.requestInfo != null)
+ if (other.requestInfo != null) {
return false;
- } else if (!requestInfo.equals(other.requestInfo))
+ }
+ } else if (!requestInfo.equals(other.requestInfo)) {
return false;
+ }
if (requestParameters == null) {
- if (other.requestParameters != null)
+ if (other.requestParameters != null) {
return false;
- } else if (!requestParameters.equals(other.requestParameters))
+ }
+ } else if (!requestParameters.equals(other.requestParameters)) {
return false;
+ }
if (subscriberInfo == null) {
- if (other.subscriberInfo != null)
+ if (other.subscriberInfo != null) {
return false;
- } else if (!subscriberInfo.equals(other.subscriberInfo))
+ }
+ } else if (!subscriberInfo.equals(other.subscriberInfo)) {
return false;
+ }
return true;
}
* ============LICENSE_START=======================================================
* so
* ================================================================================
- * 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.
package org.onap.policy.so;
-import java.io.Serializable;
-
import com.google.gson.annotations.SerializedName;
+import java.io.Serializable;
+
public class SORequestError implements Serializable {
private static final long serialVersionUID = -3283942659786236032L;
* ============LICENSE_START=======================================================
* so
* ================================================================================
- * 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.
package org.onap.policy.so;
-import java.io.Serializable;
-
import com.google.gson.annotations.SerializedName;
+import java.io.Serializable;
+
public class SORequestInfo implements Serializable {
private static final long serialVersionUID = -3283942659786236032L;
package org.onap.policy.so;
+import com.google.gson.annotations.SerializedName;
+
import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import com.google.gson.annotations.SerializedName;
public class SORequestParameters implements Serializable {
* ============LICENSE_START=======================================================
* so
* ================================================================================
- * 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.
package org.onap.policy.so;
-import java.io.Serializable;
-
import com.google.gson.annotations.SerializedName;
+import java.io.Serializable;
+
public class SORequestReferences implements Serializable {
private static final long serialVersionUID = -3283942659786236032L;
* ============LICENSE_START=======================================================
* so
* ================================================================================
- * 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.
package org.onap.policy.so;
-import java.io.Serializable;
-
import com.google.gson.annotations.SerializedName;
+import java.io.Serializable;
+
public class SORequestStatus implements Serializable {
- /**
- *
- */
private static final long serialVersionUID = -3283942659786236032L;
@SerializedName("percentProgress")
* ============LICENSE_START=======================================================
* so
* ================================================================================
- * 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.
package org.onap.policy.so;
-import java.io.Serializable;
-
import com.google.gson.annotations.SerializedName;
+import java.io.Serializable;
+
public class SOResponse implements Serializable {
private static final long serialVersionUID = -3283942659786236032L;
* ============LICENSE_START=======================================================
* so
* ================================================================================
- * 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.
package org.onap.policy.so;
-import java.io.Serializable;
-
import com.google.gson.annotations.SerializedName;
+import java.io.Serializable;
+
public class SOResponseWrapper implements Serializable {
private static final long serialVersionUID = 7673023687132889069L;
return result;
}
- public void setRequestID(String requestID) {
- this.requestID = requestID;
+ public void setRequestID(String requestId) {
+ this.requestID = requestId;
}
- public void setSoResponse(SOResponse sOResponse) {
- soResponse = sOResponse;
+ public void setSoResponse(SOResponse response) {
+ soResponse = response;
}
@Override
* ============LICENSE_START=======================================================
* so
* ================================================================================
- * 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.
package org.onap.policy.so;
+import com.google.gson.annotations.SerializedName;
+
import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
-import com.google.gson.annotations.SerializedName;
-
public class SOServiceExceptionHolder implements Serializable {
private static final long serialVersionUID = -3283942659786236032L;
* ============LICENSE_START=======================================================
* so
* ================================================================================
- * 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.
package org.onap.policy.so;
-import java.io.Serializable;
-
import com.google.gson.annotations.SerializedName;
+import java.io.Serializable;
+
public class SOSubscriberInfo implements Serializable {
private static final long serialVersionUID = -3283942659786236032L;
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.policy.so;
import java.util.Collection;
}
@Override
- public void removeEventListener(RuleRuntimeEventListener listener) {
+ public void addEventListener(AgendaEventListener listener) {
}
@Override
- public Collection<RuleRuntimeEventListener> getRuleRuntimeEventListeners() {
- return null;
+ public void addEventListener(KieBaseEventListener listener) {
}
@Override
- public void addEventListener(AgendaEventListener listener) {
+ public void removeEventListener(RuleRuntimeEventListener listener) {
}
@Override
}
@Override
- public Collection<AgendaEventListener> getAgendaEventListeners() {
- return null;
+ public void removeEventListener(KieBaseEventListener listener) {
}
@Override
- public void addEventListener(KieBaseEventListener listener) {
+ public Collection<RuleRuntimeEventListener> getRuleRuntimeEventListeners() {
+ return null;
}
@Override
- public void removeEventListener(KieBaseEventListener listener) {
+ public Collection<AgendaEventListener> getAgendaEventListeners() {
+ return null;
}
@Override
}
@Override
- public void dispose() {
+ public FactHandle insert(Object object) {
+ return null;
}
@Override
- public String getEntryPointId() {
- return null;
+ public void dispose() {
}
@Override
- public FactHandle insert(Object object) {
+ public String getEntryPointId() {
return null;
}
package org.onap.policy.so;
+import com.google.gson.Gson;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
-import com.google.gson.Gson;
@Path("/SO")
public class TestSoDummyServer {
private static Map<String, SOResponse> ongoingRequestMap = new ConcurrentHashMap<>();
+ /**
+ * Stats method.
+ *
+ * @return response
+ */
@GET
@Path("/Stats")
public Response serviceGetStats() {
+ ",\"POST\": " + postMessagesReceived + ",\"PUT\": " + putMessagesReceived + "}").build();
}
+ /**
+ * Get stat type.
+ *
+ * @param statType the stat type
+ * @return http response
+ */
@GET
@Path("/OneStat/{statType}")
public Response serviceGetStat(@PathParam("statType") final String statType) {
return Response.status(200).entity("{\"TYPE\": " + statType + "}").build();
}
+ /**
+ * Post to service instantiation.
+ *
+ * @param jsonString string to send
+ * @return http response
+ */
@POST
@Path("/serviceInstantiation/v7")
public Response servicePostRequest(final String jsonString) {
return null;
}
+ /**
+ * Post.
+ *
+ * @param serviceInstanceId service instance id
+ * @param vnfInstanceId vnf instance id
+ * @param jsonString json body
+ * @return http response
+ */
@POST
@Path("/serviceInstantiation/v7/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules/scaleOut")
public Response servicePostRequestVfModules(@PathParam("serviceInstanceId") final String serviceInstanceId,
return null;
}
+ /**
+ * Get instance ID.
+ *
+ * @param nsInstanceId node instance id
+ * @return http response
+ */
@GET
@Path("/orchestrationRequests/v5/{nsInstanceId}")
public Response soRequestStatus(@PathParam("nsInstanceId") final String nsInstanceId) {
* TestSOManager
* ================================================================================
* Copyright (C) 2018 Ericsson. 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.
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.policy.so;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+
import java.io.IOException;
import java.net.URI;
import java.util.UUID;
import org.junit.Test;
import org.onap.policy.drools.system.PolicyEngine;
-public class TestSOManager {
+public class TestSoManager {
private static final String BASE_URI = "http://localhost:46553/TestSOManager";
private static final String BASE_SO_URI = BASE_URI + "/SO";
private static HttpServer server;
* ============LICENSE_START=======================================================
* so
* ================================================================================
- *
+ * Copyright (C) 2018 Ericsson. 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.
assertEquals(subscriberInfo, obj.getSubscriberInfo());
}
- @Test
- public void testSOMRequestDetailsMethods() {
- SORequestDetails details = new SORequestDetails();
- assertNotNull(details);
- assertNotEquals(0, details.hashCode());
-
- SOCloudConfiguration cloudConfiguration = new SOCloudConfiguration();
- details.setCloudConfiguration(cloudConfiguration);
- assertEquals(cloudConfiguration, details.getCloudConfiguration());
- assertNotEquals(0, details.hashCode());
-
- SOModelInfo modelInfo = new SOModelInfo();
- details.setModelInfo(modelInfo);
- assertEquals(modelInfo, details.getModelInfo());
- assertNotEquals(0, details.hashCode());
-
- List<SORelatedInstanceListElement> relatedInstanceList = new ArrayList<>();
- details.setRelatedInstanceList(relatedInstanceList);
- assertEquals(relatedInstanceList, details.getRelatedInstanceList());
- assertNotEquals(0, details.hashCode());
-
- SORequestInfo requestInfo = new SORequestInfo();
- details.setRequestInfo(requestInfo);
- assertEquals(requestInfo, details.getRequestInfo());
- assertNotEquals(0, details.hashCode());
-
- SORequestParameters requestParameters = new SORequestParameters();
- details.setRequestParameters(requestParameters);
- assertEquals(requestParameters, details.getRequestParameters());
- assertNotEquals(0, details.hashCode());
-
- SOSubscriberInfo subscriberInfo = new SOSubscriberInfo();
- details.setSubscriberInfo(subscriberInfo);
- assertEquals(subscriberInfo, details.getSubscriberInfo());
- assertNotEquals(0, details.hashCode());
-
- assertEquals("SORequestDetails [modelInfo=org.onap.policy.so", details.toString().substring(0, 46));
-
- SORequestDetails copiedDetails = new SORequestDetails(details);
+ @Test
+ public void testSoMRequestDetailsMethods() {
+ SORequestDetails details = new SORequestDetails();
+ assertNotNull(details);
+ assertNotEquals(0, details.hashCode());
+
+ SOCloudConfiguration cloudConfiguration = new SOCloudConfiguration();
+ details.setCloudConfiguration(cloudConfiguration);
+ assertEquals(cloudConfiguration, details.getCloudConfiguration());
+ assertNotEquals(0, details.hashCode());
+
+ SOModelInfo modelInfo = new SOModelInfo();
+ details.setModelInfo(modelInfo);
+ assertEquals(modelInfo, details.getModelInfo());
+ assertNotEquals(0, details.hashCode());
+
+ List<SORelatedInstanceListElement> relatedInstanceList = new ArrayList<>();
+ details.setRelatedInstanceList(relatedInstanceList);
+ assertEquals(relatedInstanceList, details.getRelatedInstanceList());
+ assertNotEquals(0, details.hashCode());
+
+ SORequestInfo requestInfo = new SORequestInfo();
+ details.setRequestInfo(requestInfo);
+ assertEquals(requestInfo, details.getRequestInfo());
+ assertNotEquals(0, details.hashCode());
+
+ SORequestParameters requestParameters = new SORequestParameters();
+ details.setRequestParameters(requestParameters);
+ assertEquals(requestParameters, details.getRequestParameters());
+ assertNotEquals(0, details.hashCode());
+
+ SOSubscriberInfo subscriberInfo = new SOSubscriberInfo();
+ details.setSubscriberInfo(subscriberInfo);
+ assertEquals(subscriberInfo, details.getSubscriberInfo());
+ assertNotEquals(0, details.hashCode());
+
+ assertEquals("SORequestDetails [modelInfo=org.onap.policy.so", details.toString().substring(0, 46));
+
+ SORequestDetails copiedDetails = new SORequestDetails(details);
assertTrue(details.equals(details));
assertTrue(details.equals(copiedDetails));
assertFalse(details.equals(copiedDetails));
copiedDetails.setRequestInfo(requestInfo);
assertTrue(details.equals(copiedDetails));
-
+
details.setRequestParameters(null);
assertFalse(details.equals(copiedDetails));
copiedDetails.setRequestParameters(null);
assertFalse(details.equals(copiedDetails));
copiedDetails.setRequestParameters(requestParameters);
assertTrue(details.equals(copiedDetails));
-
+
details.setSubscriberInfo(null);
assertFalse(details.equals(copiedDetails));
copiedDetails.setSubscriberInfo(null);
assertFalse(details.equals(copiedDetails));
copiedDetails.setSubscriberInfo(subscriberInfo);
assertTrue(details.equals(copiedDetails));
-
+
details.setRelatedInstanceList(null);
assertFalse(details.equals(copiedDetails));
- copiedDetails.setRelatedInstanceList(null);
+ copiedDetails.setRelatedInstanceList(null);
assertTrue(details.equals(copiedDetails));
details.setRelatedInstanceList(relatedInstanceList);
assertFalse(details.equals(copiedDetails));
- copiedDetails.setRelatedInstanceList(relatedInstanceList);
+ copiedDetails.setRelatedInstanceList(relatedInstanceList);
assertTrue(details.equals(copiedDetails));
- }
+ }
}
obj.setRequestID("id2");
assertEquals("id2", obj.getRequestID());
}
-
- @Test
- public void testSOResponseWrapperMethods() {
- String requestID = UUID.randomUUID().toString();
- SOResponse response = new SOResponse();
-
- SOResponseWrapper responseWrapper = new SOResponseWrapper(response, requestID);
- assertNotNull(responseWrapper);
- assertNotEquals(0, responseWrapper.hashCode());
-
- assertEquals(response, responseWrapper.getSoResponse());
-
- assertNotEquals(0, responseWrapper.hashCode());
-
- assertEquals("SOResponseWrapper [SOResponse=org.onap.policy.", responseWrapper.toString().substring(0, 46));
-
- SOResponseWrapper identicalResponseWrapper = new SOResponseWrapper(response, requestID);
+
+ @Test
+ public void testSoResponseWrapperMethods() {
+ String requestId = UUID.randomUUID().toString();
+ SOResponse response = new SOResponse();
+
+ SOResponseWrapper responseWrapper = new SOResponseWrapper(response, requestId);
+ assertNotNull(responseWrapper);
+ assertNotEquals(0, responseWrapper.hashCode());
+
+ assertEquals(response, responseWrapper.getSoResponse());
+
+ assertNotEquals(0, responseWrapper.hashCode());
+
+ assertEquals("SOResponseWrapper [SOResponse=org.onap.policy.", responseWrapper.toString().substring(0, 46));
+
+ SOResponseWrapper identicalResponseWrapper = new SOResponseWrapper(response, requestId);
assertEquals(responseWrapper, responseWrapper);
assertEquals(responseWrapper, identicalResponseWrapper);
assertEquals(new SOResponseWrapper(null, null), new SOResponseWrapper(null, null));
assertNotEquals(new SOResponseWrapper(null, null), identicalResponseWrapper);
- assertNotEquals(0, new SOResponseWrapper(null, null).hashCode());
+ assertNotEquals(0, new SOResponseWrapper(null, null).hashCode());
- identicalResponseWrapper.setSoResponse(new SOResponse());
+ identicalResponseWrapper.setSoResponse(new SOResponse());
assertNotEquals(responseWrapper, identicalResponseWrapper);
identicalResponseWrapper.setSoResponse(response);
assertEquals(responseWrapper, identicalResponseWrapper);
identicalResponseWrapper.setRequestID(UUID.randomUUID().toString());
assertNotEquals(responseWrapper, identicalResponseWrapper);
- identicalResponseWrapper.setRequestID(requestID);
+ identicalResponseWrapper.setRequestID(requestId);
assertEquals(responseWrapper, identicalResponseWrapper);
responseWrapper.setRequestID(null);
assertNotEquals(responseWrapper, identicalResponseWrapper);
identicalResponseWrapper.setRequestID(null);
assertEquals(responseWrapper, identicalResponseWrapper);
- responseWrapper.setRequestID(requestID);
+ responseWrapper.setRequestID(requestId);
assertNotEquals(responseWrapper, identicalResponseWrapper);
- identicalResponseWrapper.setRequestID(requestID);
+ identicalResponseWrapper.setRequestID(requestId);
assertEquals(responseWrapper, identicalResponseWrapper);
- }
+ }
}
* ============LICENSE_START=======================================================
* trafficgenerator
* ================================================================================
- * 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.
package org.onap.policy.vnf.trafficgenerator;
-import java.io.Serializable;
-
import com.google.gson.annotations.SerializedName;
+import java.io.Serializable;
+
public class PGRequest implements Serializable {
- /**
- *
- */
private static final long serialVersionUID = -3283942659786236032L;
@SerializedName("pg-streams")
* ============LICENSE_START=======================================================
* trafficgenerator
* ================================================================================
- * 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.
package org.onap.policy.vnf.trafficgenerator;
-import java.io.Serializable;
-
import com.google.gson.annotations.SerializedName;
+import java.io.Serializable;
+
public class PGStream implements Serializable {
- /**
- *
- */
private static final long serialVersionUID = 5567635677419358210L;
@SerializedName("id")
* ============LICENSE_START=======================================================
* trafficgenerator
* ================================================================================
- * 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.
package org.onap.policy.vnf.trafficgenerator;
+import com.google.gson.annotations.SerializedName;
+
import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
-import com.google.gson.annotations.SerializedName;
-
public class PGStreams implements Serializable {
- /**
- *
- */
private static final long serialVersionUID = 5567635677419358210L;
@SerializedName("pg-stream")
* ============LICENSE_START=======================================================
* trafficgenerator
* ================================================================================
- * 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.
package org.onap.policy.vnf.trafficgenerator;
-
import org.junit.Test;
+
import org.onap.policy.vnf.trafficgenerator.PGRequest;
import org.onap.policy.vnf.trafficgenerator.PGStream;
import org.onap.policy.vnf.trafficgenerator.PGStreams;
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2017 Intel Corp. All rights reserved.
+ * Modifications Copyright (C) 2018 AT&T Corporation. 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.
package org.onap.policy.vfc;
-import java.io.Serializable;
-
import com.google.gson.annotations.SerializedName;
+import java.io.Serializable;
+
public class VFCHealActionVmInfo implements Serializable {
- private static final long serialVersionUID = 3208673205100673119L;
+ private static final long serialVersionUID = 3208673205100673119L;
- @SerializedName("vmid")
- private String vmid;
+ @SerializedName("vmid")
+ private String vmid;
- @SerializedName("vmname")
- private String vmname;
+ @SerializedName("vmname")
+ private String vmname;
- public VFCHealActionVmInfo() {
- // Default constructor for VFCHealActionVmInfo
- }
+ public VFCHealActionVmInfo() {
+ // Default constructor for VFCHealActionVmInfo
+ }
- public String getVmid() {
- return vmid;
- }
+ public String getVmid() {
+ return vmid;
+ }
- public void setVmid(String vmid) {
- this.vmid = vmid;
- }
+ public void setVmid(String vmid) {
+ this.vmid = vmid;
+ }
- public String getVmname() {
- return vmname;
- }
+ public String getVmname() {
+ return vmname;
+ }
- public void setVmname(String vmname) {
- this.vmname = vmname;
- }
+ public void setVmname(String vmname) {
+ this.vmname = vmname;
+ }
}
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2017 Intel Corp. All rights reserved.
+ * Modifications Copyright (C) 2018 AT&T Corporation. 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.
package org.onap.policy.vfc;
-import java.io.Serializable;
-
import com.google.gson.annotations.SerializedName;
+import java.io.Serializable;
+
public class VFCHealAdditionalParams implements Serializable {
- private static final long serialVersionUID = 2656694137285096191L;
+ private static final long serialVersionUID = 2656694137285096191L;
- @SerializedName("action")
- private String action;
+ @SerializedName("action")
+ private String action;
- @SerializedName("actionvminfo")
- private VFCHealActionVmInfo actionInfo;
+ @SerializedName("actionvminfo")
+ private VFCHealActionVmInfo actionInfo;
- public VFCHealAdditionalParams() {
- // Default constructor for VFCHealAdditionalParams
- }
+ public VFCHealAdditionalParams() {
+ // Default constructor for VFCHealAdditionalParams
+ }
- public String getAction() {
- return action;
- }
+ public String getAction() {
+ return action;
+ }
- public void setAction(String action) {
- this.action = action;
- }
+ public void setAction(String action) {
+ this.action = action;
+ }
- public VFCHealActionVmInfo getActionInfo() {
- return actionInfo;
- }
+ public VFCHealActionVmInfo getActionInfo() {
+ return actionInfo;
+ }
- public void setActionInfo(VFCHealActionVmInfo actionInfo) {
- this.actionInfo = actionInfo;
- }
+ public void setActionInfo(VFCHealActionVmInfo actionInfo) {
+ this.actionInfo = actionInfo;
+ }
}
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2017 Intel Corp. All rights reserved.
+ * Modifications Copyright (C) 2018 AT&T Corporation. 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.
package org.onap.policy.vfc;
-import java.io.Serializable;
-
import com.google.gson.annotations.SerializedName;
+import java.io.Serializable;
+
public class VFCHealRequest implements Serializable {
- private static final long serialVersionUID = -7341931593089709247L;
+ private static final long serialVersionUID = -7341931593089709247L;
- @SerializedName("vnfInstanceId")
- private String vnfInstanceId;
+ @SerializedName("vnfInstanceId")
+ private String vnfInstanceId;
- @SerializedName("cause")
- private String cause;
+ @SerializedName("cause")
+ private String cause;
- @SerializedName("additionalParams")
- private VFCHealAdditionalParams additionalParams;
+ @SerializedName("additionalParams")
+ private VFCHealAdditionalParams additionalParams;
- public VFCHealRequest() {
- // Default constructor for VFCHealRequest
- }
+ public VFCHealRequest() {
+ // Default constructor for VFCHealRequest
+ }
- public String getVnfInstanceId() {
- return vnfInstanceId;
- }
+ public String getVnfInstanceId() {
+ return vnfInstanceId;
+ }
- public void setVnfInstanceId(String vnfInstanceId) {
- this.vnfInstanceId = vnfInstanceId;
- }
+ public void setVnfInstanceId(String vnfInstanceId) {
+ this.vnfInstanceId = vnfInstanceId;
+ }
- public String getCause() {
- return cause;
- }
+ public String getCause() {
+ return cause;
+ }
- public void setCause(String cause) {
- this.cause = cause;
- }
+ public void setCause(String cause) {
+ this.cause = cause;
+ }
- public VFCHealAdditionalParams getAdditionalParams() {
- return additionalParams;
- }
+ public VFCHealAdditionalParams getAdditionalParams() {
+ return additionalParams;
+ }
- public void setAdditionalParams(VFCHealAdditionalParams additionalParams) {
- this.additionalParams = additionalParams;
- }
+ public void setAdditionalParams(VFCHealAdditionalParams additionalParams) {
+ this.additionalParams = additionalParams;
+ }
}
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2017-2018 Intel Corp, AT&T. All rights reserved.
+ * Modifications Copyright (C) 2018 AT&T Corporation. 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.
// The REST manager used for processing REST calls for this VFC manager
private RESTManager restManager;
+ /**
+ * Constructor.
+ *
+ * @param wm Drools working memory
+ * @param request request
+ */
public VFCManager(WorkingMemory wm, VFCRequest request) {
if (wm == null || request == null) {
throw new IllegalArgumentException(
PolicyEngine.manager.getEnvironmentProperty("vfc.password"));
}
+ /**
+ * Set the parameters.
+ *
+ * @param baseUrl base URL
+ * @param name username
+ * @param pwd password
+ */
public void setVFCParams(String baseUrl, String name, String pwd) {
vfcUrlBase = baseUrl + "/api/nslcm/v1";
username = name;
}
/**
- * Protected setter for rest manager to allow mocked rest manager to be used for testing
+ * Protected setter for rest manager to allow mocked rest manager to be used for testing.
*
* @param restManager the test REST manager
*/
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2017 Intel Corp. All rights reserved.
+ * Modifications Copyright (C) 2018 AT&T Corporation. 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.
package org.onap.policy.vfc;
+import com.google.gson.annotations.SerializedName;
+
import java.io.Serializable;
import java.util.UUID;
-import com.google.gson.annotations.SerializedName;
-
public class VFCRequest implements Serializable {
private static final long serialVersionUID = 3736300970326332512L;
private VFCHealRequest healRequest;
public VFCRequest() {
- // Default constructor for VFCRequest
+ // Default constructor for VFCRequest
}
- public String getNSInstanceId() {
- return nsInstanceId;
- }
+ public String getNSInstanceId() {
+ return nsInstanceId;
+ }
- public void setNSInstanceId(String nsInstanceId) {
- this.nsInstanceId = nsInstanceId;
- }
+ public void setNSInstanceId(String nsInstanceId) {
+ this.nsInstanceId = nsInstanceId;
+ }
- public UUID getRequestId() {
- return requestId;
- }
+ public UUID getRequestId() {
+ return requestId;
+ }
- public void setRequestId(UUID requestId) {
- this.requestId = requestId;
- }
+ public void setRequestId(UUID requestId) {
+ this.requestId = requestId;
+ }
- public VFCHealRequest getHealRequest() {
- return healRequest;
- }
+ public VFCHealRequest getHealRequest() {
+ return healRequest;
+ }
- public void setHealRequest(VFCHealRequest healRequest) {
- this.healRequest = healRequest;
- }
+ public void setHealRequest(VFCHealRequest healRequest) {
+ this.healRequest = healRequest;
+ }
}
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2017 Intel Corp. All rights reserved.
+ * Modifications Copyright (C) 2018 AT&T Corporation. 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.
package org.onap.policy.vfc;
-import java.io.Serializable;
-
import com.google.gson.annotations.SerializedName;
+import java.io.Serializable;
+
public class VFCResponse implements Serializable {
private static final long serialVersionUID = 9151443891238218455L;
private transient String requestId;
public VFCResponse() {
- // Default constructor for VFCResponse
+ // Default constructor for VFCResponse
}
- public String getJobId() {
- return jobId;
- }
+ public String getJobId() {
+ return jobId;
+ }
- public void setJobId(String jobId) {
- this.jobId = jobId;
- }
+ public void setJobId(String jobId) {
+ this.jobId = jobId;
+ }
- public VFCResponseDescriptor getResponseDescriptor() {
- return responseDescriptor;
- }
+ public VFCResponseDescriptor getResponseDescriptor() {
+ return responseDescriptor;
+ }
- public void setResponseDescriptor(VFCResponseDescriptor responseDescriptor) {
- this.responseDescriptor = responseDescriptor;
- }
+ public void setResponseDescriptor(VFCResponseDescriptor responseDescriptor) {
+ this.responseDescriptor = responseDescriptor;
+ }
- public String getRequestId() {
- return requestId;
- }
+ public String getRequestId() {
+ return requestId;
+ }
- public void setRequestId(String requestId) {
- this.requestId = requestId;
- }
+ public void setRequestId(String requestId) {
+ this.requestId = requestId;
+ }
}
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2017 Intel Corp. All rights reserved.
+ * Modifications Copyright (C) 2018 AT&T Corporation. 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.
package org.onap.policy.vfc;
+import com.google.gson.annotations.SerializedName;
+
import java.io.Serializable;
import java.util.List;
-import com.google.gson.annotations.SerializedName;
public class VFCResponseDescriptor implements Serializable {
private List<VFCResponseDescriptor> responseHistoryList;
public VFCResponseDescriptor() {
- // Default constructor for VFCResponseDescriptor
+ // Default constructor for VFCResponseDescriptor
}
public String getStatus() {
- return status;
+ return status;
}
- public String getProgress() {
- return progress;
- }
+ public String getProgress() {
+ return progress;
+ }
- public void setProgress(String progress) {
- this.progress = progress;
- }
+ public void setProgress(String progress) {
+ this.progress = progress;
+ }
- public String getStatusDescription() {
- return statusDescription;
- }
+ public String getStatusDescription() {
+ return statusDescription;
+ }
- public void setStatusDescription(String statusDescription) {
- this.statusDescription = statusDescription;
- }
+ public void setStatusDescription(String statusDescription) {
+ this.statusDescription = statusDescription;
+ }
- public String getErrorCode() {
- return errorCode;
- }
+ public String getErrorCode() {
+ return errorCode;
+ }
- public void setErrorCode(String errorCode) {
- this.errorCode = errorCode;
- }
+ public void setErrorCode(String errorCode) {
+ this.errorCode = errorCode;
+ }
- public String getResponseId() {
- return responseId;
- }
+ public String getResponseId() {
+ return responseId;
+ }
- public void setResponseId(String responseId) {
- this.responseId = responseId;
- }
+ public void setResponseId(String responseId) {
+ this.responseId = responseId;
+ }
- public List<VFCResponseDescriptor> getResponseHistoryList() {
- return responseHistoryList;
- }
+ public List<VFCResponseDescriptor> getResponseHistoryList() {
+ return responseHistoryList;
+ }
- public void setResponseHistoryList(List<VFCResponseDescriptor> responseHistoryList) {
- this.responseHistoryList = responseHistoryList;
- }
+ public void setResponseHistoryList(List<VFCResponseDescriptor> responseHistoryList) {
+ this.responseHistoryList = responseHistoryList;
+ }
- public void setStatus(String status) {
- this.status = status;
- }
+ public void setStatus(String status) {
+ this.status = status;
+ }
}
import com.google.gson.GsonBuilder;
public final class Serialization {
- private Serialization() {
- }
-
- public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping()
- .setPrettyPrinting()
- .create();
+ private Serialization() {
+ }
+
+ public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping()
+ .setPrettyPrinting()
+ .create();
}
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2017 Intel Corp. All rights reserved.
+ * Modifications Copyright (C) 2018 AT&T Corporation. 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.
responseDescriptor.setErrorCode(null);
responseDescriptor.setResponseId("11");
- response.getResponseDescriptor().setResponseHistoryList(new LinkedList<>());
+ response.getResponseDescriptor().setResponseHistoryList(new LinkedList<>());
response.getResponseDescriptor().getResponseHistoryList().add(responseDescriptor);
body = Serialization.gsonPretty.toJson(response);
+++ /dev/null
-/*-
- * ============LICENSE_START=======================================================
- * vfc
- * ================================================================================
- * Copyright (C) 2018 Ericsson. 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.vfc;
-
-import static org.junit.Assert.*;
-
-import org.junit.Test;
-
-public class TestVFCHealActionVmInfo {
-
- @Test
- public void testVFCHealActionVmInfo() {
- VFCHealActionVmInfo actionInfo = new VFCHealActionVmInfo();
- assertNotNull(actionInfo);
- assertNotEquals(0, actionInfo.hashCode());
-
- String vmid = "ECity";
- actionInfo.setVmid(vmid);
- assertEquals(vmid, actionInfo.getVmid());
-
- String vmName = "Emerald City";
- actionInfo.setVmname(vmName);
- assertEquals(vmName, actionInfo.getVmname());
-
- assertNotEquals(0, actionInfo.hashCode());
- }
-}
+++ /dev/null
-/*-
- * ============LICENSE_START=======================================================
- * vfc
- * ================================================================================
- * Copyright (C) 2018 Ericsson, AT&T. 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.vfc;
-
-import static org.junit.Assert.*;
-import static org.mockito.ArgumentMatchers.anyMap;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.ArgumentMatchers.startsWith;
-import static org.mockito.Mockito.*;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.UUID;
-
-import org.drools.core.WorkingMemory;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.onap.policy.drools.system.PolicyEngine;
-import org.onap.policy.rest.RESTManager;
-import org.onap.policy.rest.RESTManager.Pair;
-import org.onap.policy.vfc.util.Serialization;
-
-public class TestVFCManager {
- private static WorkingMemory mockedWorkingMemory;
-
- private RESTManager mockedRESTManager;
-
- private Pair<Integer, String> httpResponsePutOK;
- private Pair<Integer, String> httpResponseGetOK;
- private Pair<Integer, String> httpResponseBadResponse;
- private Pair<Integer, String> httpResponseErr;
-
- private VFCRequest request;
- private VFCResponse response;
-
- @BeforeClass
- public static void beforeTestVFCManager() {
- mockedWorkingMemory = mock(WorkingMemory.class);
- }
-
- @Before
- public void setupMockedRest() {
- mockedRESTManager = mock(RESTManager.class);
-
- httpResponsePutOK = mockedRESTManager.new Pair<>(202, Serialization.gsonPretty.toJson(response));
- httpResponseGetOK = mockedRESTManager.new Pair<>(200, Serialization.gsonPretty.toJson(response));
- httpResponseBadResponse = mockedRESTManager.new Pair<>(202, Serialization.gsonPretty.toJson(null));
- httpResponseErr = mockedRESTManager.new Pair<>(200, null);
- }
-
- @Before
- public void createRequestAndResponse() {
- VFCHealActionVmInfo actionInfo = new VFCHealActionVmInfo();
- actionInfo.setVmid("TheWizard");
- actionInfo.setVmname("The Wizard of Oz");
-
- VFCHealAdditionalParams additionalParams = new VFCHealAdditionalParams();
- additionalParams.setAction("Go Home");
- additionalParams.setActionInfo(actionInfo);
-
- VFCHealRequest healRequest = new VFCHealRequest();
- healRequest.setAdditionalParams(additionalParams);
- healRequest.setCause("WestWitch");
- healRequest.setVnfInstanceId("EmeraldCity");
-
- UUID requestId = UUID.randomUUID();
- request = new VFCRequest();
- request.setHealRequest(healRequest);
- request.setNSInstanceId("Dorothy");
- request.setRequestId(requestId);
-
- List<VFCResponseDescriptor> responseHistoryList = new ArrayList<>();;
-
- VFCResponseDescriptor responseDescriptor = new VFCResponseDescriptor();
- responseDescriptor.setErrorCode("1234");
- responseDescriptor.setProgress("Follow The Yellow Brick Road");
- responseDescriptor.setResponseHistoryList(responseHistoryList);
- responseDescriptor.setResponseId(UUID.randomUUID().toString());
- responseDescriptor.setStatus("finished");
- responseDescriptor.setStatusDescription("There's no place like home");
-
- response = new VFCResponse();
- response.setJobId("1234");
- response.setRequestId(request.getRequestId().toString());
- response.setResponseDescriptor(responseDescriptor);
- }
-
- @After
- public void tearDown() {
- PolicyEngine.manager.getEnvironment().remove("vfc.password");
- PolicyEngine.manager.getEnvironment().remove("vfc.username");
- PolicyEngine.manager.getEnvironment().remove("vfc.url");
- }
-
- @Test
- public void testVFCInitiation() {
- try {
- new VFCManager(null, null);
- fail("test should throw an exception here");
- }
- catch (IllegalArgumentException e) {
- assertEquals("the parameters \"wm\" and \"request\" on the VFCManager constructor may not be null", e.getMessage());
- }
-
- try {
- new VFCManager(mockedWorkingMemory, null);
- fail("test should throw an exception here");
- }
- catch (IllegalArgumentException e) {
- assertEquals("the parameters \"wm\" and \"request\" on the VFCManager constructor may not be null", e.getMessage());
- }
-
- try {
- new VFCManager(mockedWorkingMemory, request);
- fail("test should throw an exception here");
- }
- catch (IllegalArgumentException e) {
- assertEquals("The value of policy engine manager environment property \"vfc.url\" may not be null", e.getMessage());
- }
-
- // add url; username & password are not required
- PolicyEngine.manager.getEnvironment().put("vfc.url", "http://somewhere.over.the.rainbow");
- new VFCManager(mockedWorkingMemory, request);
-
- // url & username, but no password
- PolicyEngine.manager.getEnvironment().put("vfc.username", "Dorothy");
-
- // url, username, and password
- PolicyEngine.manager.getEnvironment().put("vfc.password", "Toto");
- new VFCManager(mockedWorkingMemory, request);
- }
-
- @Test
- public void testVFCExecutionException() throws InterruptedException {
- PolicyEngine.manager.getEnvironment().put("vfc.url", "http://somewhere.over.the.rainbow");
- PolicyEngine.manager.getEnvironment().put("vfc.username", "Dorothy");
- PolicyEngine.manager.getEnvironment().put("vfc.password", "Exception");
-
- VFCManager manager = new VFCManager(mockedWorkingMemory, request);
- manager.setRestManager(mockedRESTManager);
-
- Thread managerThread = new Thread(manager);
- managerThread.start();
-
- when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("Exception"), anyMap(), anyString(), anyString()))
- .thenThrow(new RuntimeException("OzException"));
-
- while (managerThread.isAlive()) {
- Thread.sleep(100);
- }
-
- PolicyEngine.manager.getEnvironment().remove("vfc.password");
- PolicyEngine.manager.getEnvironment().remove("vfc.username");
- PolicyEngine.manager.getEnvironment().remove("vfc.url");
- }
-
- @Test
- public void testVFCExecutionNull() throws InterruptedException {
- PolicyEngine.manager.getEnvironment().put("vfc.url", "http://somewhere.over.the.rainbow");
- PolicyEngine.manager.getEnvironment().put("vfc.username", "Dorothy");
- PolicyEngine.manager.getEnvironment().put("vfc.password", "Null");
-
- VFCManager manager = new VFCManager(mockedWorkingMemory, request);
- manager.setRestManager(mockedRESTManager);
-
- Thread managerThread = new Thread(manager);
- managerThread.start();
-
- when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("Null"), anyMap(), anyString(), anyString()))
- .thenReturn(null);
-
- while (managerThread.isAlive()) {
- Thread.sleep(100);
- }
-
- PolicyEngine.manager.getEnvironment().remove("vfc.password");
- PolicyEngine.manager.getEnvironment().remove("vfc.username");
- PolicyEngine.manager.getEnvironment().remove("vfc.url");
- }
-
- @Test
- public void testVFCExecutionError0() throws InterruptedException {
- PolicyEngine.manager.getEnvironment().put("vfc.url", "http://somewhere.over.the.rainbow");
- PolicyEngine.manager.getEnvironment().put("vfc.username", "Dorothy");
- PolicyEngine.manager.getEnvironment().put("vfc.password", "Error0");
-
- VFCManager manager = new VFCManager(mockedWorkingMemory, request);
- manager.setRestManager(mockedRESTManager);
-
- Thread managerThread = new Thread(manager);
- managerThread.start();
-
- when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("Error0"), anyMap(), anyString(), anyString()))
- .thenReturn(httpResponseErr);
-
- while (managerThread.isAlive()) {
- Thread.sleep(100);
- }
-
- PolicyEngine.manager.getEnvironment().remove("vfc.password");
- PolicyEngine.manager.getEnvironment().remove("vfc.username");
- PolicyEngine.manager.getEnvironment().remove("vfc.url");
- }
-
- @Test
- public void testVFCExecutionBadResponse() throws InterruptedException {
- PolicyEngine.manager.getEnvironment().put("vfc.url", "http://somewhere.over.the.rainbow");
- PolicyEngine.manager.getEnvironment().put("vfc.username", "Dorothy");
- PolicyEngine.manager.getEnvironment().put("vfc.password", "BadResponse");
-
- VFCManager manager = new VFCManager(mockedWorkingMemory, request);
- manager.setRestManager(mockedRESTManager);
-
- Thread managerThread = new Thread(manager);
- managerThread.start();
-
- when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("OK"), anyMap(), anyString(), anyString()))
- .thenReturn(httpResponseBadResponse);
-
- while (managerThread.isAlive()) {
- Thread.sleep(100);
- }
-
- PolicyEngine.manager.getEnvironment().remove("vfc.password");
- PolicyEngine.manager.getEnvironment().remove("vfc.username");
- PolicyEngine.manager.getEnvironment().remove("vfc.url");
- }
-
- @Test
- public void testVFCExecutionOK() throws InterruptedException {
- PolicyEngine.manager.getEnvironment().put("vfc.url", "http://somewhere.over.the.rainbow");
- PolicyEngine.manager.getEnvironment().put("vfc.username", "Dorothy");
- PolicyEngine.manager.getEnvironment().put("vfc.password", "OK");
-
- VFCManager manager = new VFCManager(mockedWorkingMemory, request);
- manager.setRestManager(mockedRESTManager);
-
- Thread managerThread = new Thread(manager);
- managerThread.start();
-
- when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("OK"), anyMap(), anyString(), anyString()))
- .thenReturn(httpResponsePutOK);
-
- when(mockedRESTManager.get(endsWith("1234"), eq("Dorothy"), eq("OK"), anyMap()))
- .thenReturn(httpResponseGetOK);
-
- while (managerThread.isAlive()) {
- Thread.sleep(100);
- }
-
- PolicyEngine.manager.getEnvironment().remove("vfc.password");
- PolicyEngine.manager.getEnvironment().remove("vfc.username");
- PolicyEngine.manager.getEnvironment().remove("vfc.url");
- }
-}
+++ /dev/null
-/*-
- * ============LICENSE_START=======================================================
- * vfc
- * ================================================================================
- * Copyright (C) 2018 Ericsson. 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.vfc;
-
-import static org.junit.Assert.*;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.junit.Test;
-
-public class TestVFCResponseDescriptor {
-
- @Test
- public void testVFCResponseDescriptor() {
- VFCResponseDescriptor descriptor = new VFCResponseDescriptor();
- assertNotNull(descriptor);
- assertNotEquals(0, descriptor.hashCode());
-
- String errorCode = "WitchIsDead";
- descriptor.setErrorCode(errorCode);
- assertEquals(errorCode, descriptor.getErrorCode());
-
- String progress = "Visited Wizard";
- descriptor.setProgress(progress);
- assertEquals(progress, descriptor.getProgress());
-
- List<VFCResponseDescriptor> responseHistoryList = new ArrayList<>();
- descriptor.setResponseHistoryList(responseHistoryList);
- assertEquals(responseHistoryList, descriptor.getResponseHistoryList());
-
- String responseId = "WishHard";
- descriptor.setResponseId(responseId);
- assertEquals(responseId, descriptor.getResponseId());
-
- String status = "Back in Kansas";
- descriptor.setStatus(status);
- assertEquals(status, descriptor.getStatus());
-
- String statusDescription = "Back on the prairie";
- descriptor.setStatusDescription(statusDescription);
- assertEquals(statusDescription, descriptor.getStatusDescription());
-
- assertNotEquals(0, descriptor.hashCode());
- }
-}
* vfc
* ================================================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2018 AT&T Corporation. 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.
package org.onap.policy.vfc;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
import org.junit.Test;
-public class TestVFCResponse {
-
- @Test
- public void testVFCResponse() {
- VFCResponse response = new VFCResponse();
- assertNotNull(response);
- assertNotEquals(0, response.hashCode());
-
- String jobId = "GetToOz";
- response.setJobId(jobId);
- assertEquals(jobId, response.getJobId());
-
- String requestId = "Get Home";
- response.setRequestId(requestId);
- assertEquals(requestId, response.getRequestId());
-
- VFCResponseDescriptor responseDescriptor = new VFCResponseDescriptor();
- response.setResponseDescriptor(responseDescriptor);
- assertEquals(responseDescriptor, response.getResponseDescriptor());
-
- assertNotEquals(0, response.hashCode());
- }
+public class TestVfcHealActionVmInfo {
+
+ @Test
+ public void testVfcHealActionVmInfo() {
+ VFCHealActionVmInfo actionInfo = new VFCHealActionVmInfo();
+ assertNotNull(actionInfo);
+ assertNotEquals(0, actionInfo.hashCode());
+
+ String vmid = "ECity";
+ actionInfo.setVmid(vmid);
+ assertEquals(vmid, actionInfo.getVmid());
+
+ String vmName = "Emerald City";
+ actionInfo.setVmname(vmName);
+ assertEquals(vmName, actionInfo.getVmname());
+
+ assertNotEquals(0, actionInfo.hashCode());
+ }
}
* vfc
* ================================================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2018 AT&T Corporation. 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.
package org.onap.policy.vfc;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
import org.junit.Test;
-public class TestVFCHealRequest {
-
- @Test
- public void testVFCHealRequest() {
- VFCHealRequest request = new VFCHealRequest();
- assertNotNull(request);
- assertNotEquals(0, request.hashCode());
-
- String vnfInstanceId = "Go To Oz";
- request.setVnfInstanceId(vnfInstanceId);
- assertEquals(vnfInstanceId, request.getVnfInstanceId());
-
- String cause = "West Witch";
- request.setCause(cause);
- assertEquals(cause, request.getCause());
-
- VFCHealAdditionalParams additionalParams= new VFCHealAdditionalParams();
- request.setAdditionalParams(additionalParams);
- assertEquals(additionalParams, request.getAdditionalParams());
-
- assertNotEquals(0, request.hashCode());
- }
+public class TestVfcHealAdditionalParams {
+
+ @Test
+ public void testVfcHealAdditionalParameters() {
+ VFCHealAdditionalParams additionalParams = new VFCHealAdditionalParams();
+ assertNotNull(additionalParams);
+ assertNotEquals(0, additionalParams.hashCode());
+
+ String action = "Go Home";
+ additionalParams.setAction(action);
+ assertEquals(action, additionalParams.getAction());
+
+ VFCHealActionVmInfo actionInfo = new VFCHealActionVmInfo();
+ additionalParams.setActionInfo(actionInfo );
+ assertEquals(actionInfo, additionalParams.getActionInfo());
+
+ assertNotEquals(0, additionalParams.hashCode());
+ }
}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * vfc
+ * ================================================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2018 AT&T Corporation. 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.vfc;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+
+public class TestVfcHealRequest {
+
+ @Test
+ public void testVfcHealRequest() {
+ VFCHealRequest request = new VFCHealRequest();
+ assertNotNull(request);
+ assertNotEquals(0, request.hashCode());
+
+ String vnfInstanceId = "Go To Oz";
+ request.setVnfInstanceId(vnfInstanceId);
+ assertEquals(vnfInstanceId, request.getVnfInstanceId());
+
+ String cause = "West Witch";
+ request.setCause(cause);
+ assertEquals(cause, request.getCause());
+
+ VFCHealAdditionalParams additionalParams = new VFCHealAdditionalParams();
+ request.setAdditionalParams(additionalParams);
+ assertEquals(additionalParams, request.getAdditionalParams());
+
+ assertNotEquals(0, request.hashCode());
+ }
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * vfc
+ * ================================================================================
+ * Copyright (C) 2018 Ericsson, AT&T. All rights reserved.
+ * Modifications Copyright (C) 2018 AT&T Corporation. 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.vfc;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import static org.mockito.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.endsWith;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.startsWith;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import org.drools.core.WorkingMemory;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.onap.policy.drools.system.PolicyEngine;
+import org.onap.policy.rest.RESTManager;
+import org.onap.policy.rest.RESTManager.Pair;
+import org.onap.policy.vfc.util.Serialization;
+
+public class TestVfcManager {
+ private static WorkingMemory mockedWorkingMemory;
+
+ private RESTManager mockedRestManager;
+
+ private Pair<Integer, String> httpResponsePutOk;
+ private Pair<Integer, String> httpResponseGetOk;
+ private Pair<Integer, String> httpResponseBadResponse;
+ private Pair<Integer, String> httpResponseErr;
+
+ private VFCRequest request;
+ private VFCResponse response;
+
+ @BeforeClass
+ public static void beforeTestVfcManager() {
+ mockedWorkingMemory = mock(WorkingMemory.class);
+ }
+
+ /**
+ * Set up the mocked REST manager.
+ */
+ @Before
+ public void setupMockedRest() {
+ mockedRestManager = mock(RESTManager.class);
+
+ httpResponsePutOk = mockedRestManager.new Pair<>(202, Serialization.gsonPretty.toJson(response));
+ httpResponseGetOk = mockedRestManager.new Pair<>(200, Serialization.gsonPretty.toJson(response));
+ httpResponseBadResponse = mockedRestManager.new Pair<>(202, Serialization.gsonPretty.toJson(null));
+ httpResponseErr = mockedRestManager.new Pair<>(200, null);
+ }
+
+ /**
+ * Create the request and response before.
+ */
+ @Before
+ public void createRequestAndResponse() {
+ VFCHealActionVmInfo actionInfo = new VFCHealActionVmInfo();
+ actionInfo.setVmid("TheWizard");
+ actionInfo.setVmname("The Wizard of Oz");
+
+ VFCHealAdditionalParams additionalParams = new VFCHealAdditionalParams();
+ additionalParams.setAction("Go Home");
+ additionalParams.setActionInfo(actionInfo);
+
+ VFCHealRequest healRequest = new VFCHealRequest();
+ healRequest.setAdditionalParams(additionalParams);
+ healRequest.setCause("WestWitch");
+ healRequest.setVnfInstanceId("EmeraldCity");
+
+ final UUID requestId = UUID.randomUUID();
+ request = new VFCRequest();
+ request.setHealRequest(healRequest);
+ request.setNSInstanceId("Dorothy");
+ request.setRequestId(requestId);
+
+ List<VFCResponseDescriptor> responseHistoryList = new ArrayList<>();;
+
+ VFCResponseDescriptor responseDescriptor = new VFCResponseDescriptor();
+ responseDescriptor.setErrorCode("1234");
+ responseDescriptor.setProgress("Follow The Yellow Brick Road");
+ responseDescriptor.setResponseHistoryList(responseHistoryList);
+ responseDescriptor.setResponseId(UUID.randomUUID().toString());
+ responseDescriptor.setStatus("finished");
+ responseDescriptor.setStatusDescription("There's no place like home");
+
+ response = new VFCResponse();
+ response.setJobId("1234");
+ response.setRequestId(request.getRequestId().toString());
+ response.setResponseDescriptor(responseDescriptor);
+ }
+
+ /**
+ * Remove the environnment.
+ */
+ @After
+ public void tearDown() {
+ PolicyEngine.manager.getEnvironment().remove("vfc.password");
+ PolicyEngine.manager.getEnvironment().remove("vfc.username");
+ PolicyEngine.manager.getEnvironment().remove("vfc.url");
+ }
+
+ @Test
+ public void testVfcInitiation() {
+ try {
+ new VFCManager(null, null);
+ fail("test should throw an exception here");
+ }
+ catch (IllegalArgumentException e) {
+ assertEquals("the parameters \"wm\" and \"request\" on the VFCManager constructor may not be null",
+ e.getMessage());
+ }
+
+ try {
+ new VFCManager(mockedWorkingMemory, null);
+ fail("test should throw an exception here");
+ }
+ catch (IllegalArgumentException e) {
+ assertEquals("the parameters \"wm\" and \"request\" on the VFCManager constructor may not be null",
+ e.getMessage());
+ }
+
+ try {
+ new VFCManager(mockedWorkingMemory, request);
+ fail("test should throw an exception here");
+ }
+ catch (IllegalArgumentException e) {
+ assertEquals("The value of policy engine manager environment property \"vfc.url\" may not be null",
+ e.getMessage());
+ }
+
+ // add url; username & password are not required
+ PolicyEngine.manager.getEnvironment().put("vfc.url", "http://somewhere.over.the.rainbow");
+ new VFCManager(mockedWorkingMemory, request);
+
+ // url & username, but no password
+ PolicyEngine.manager.getEnvironment().put("vfc.username", "Dorothy");
+
+ // url, username, and password
+ PolicyEngine.manager.getEnvironment().put("vfc.password", "Toto");
+ new VFCManager(mockedWorkingMemory, request);
+ }
+
+ @Test
+ public void testVfcExecutionException() throws InterruptedException {
+ PolicyEngine.manager.getEnvironment().put("vfc.url", "http://somewhere.over.the.rainbow");
+ PolicyEngine.manager.getEnvironment().put("vfc.username", "Dorothy");
+ PolicyEngine.manager.getEnvironment().put("vfc.password", "Exception");
+
+ VFCManager manager = new VFCManager(mockedWorkingMemory, request);
+ manager.setRestManager(mockedRestManager);
+
+ Thread managerThread = new Thread(manager);
+ managerThread.start();
+
+ when(mockedRestManager.post(
+ startsWith("http://somewhere.over.the.rainbow"),
+ eq("Dorothy"),
+ eq("Exception"),
+ anyMap(),
+ anyString(),
+ anyString()))
+ .thenThrow(new RuntimeException("OzException"));
+
+ while (managerThread.isAlive()) {
+ Thread.sleep(100);
+ }
+
+ PolicyEngine.manager.getEnvironment().remove("vfc.password");
+ PolicyEngine.manager.getEnvironment().remove("vfc.username");
+ PolicyEngine.manager.getEnvironment().remove("vfc.url");
+ }
+
+ @Test
+ public void testVfcExecutionNull() throws InterruptedException {
+ PolicyEngine.manager.getEnvironment().put("vfc.url", "http://somewhere.over.the.rainbow");
+ PolicyEngine.manager.getEnvironment().put("vfc.username", "Dorothy");
+ PolicyEngine.manager.getEnvironment().put("vfc.password", "Null");
+
+ VFCManager manager = new VFCManager(mockedWorkingMemory, request);
+ manager.setRestManager(mockedRestManager);
+
+ Thread managerThread = new Thread(manager);
+ managerThread.start();
+
+ when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"),
+ eq("Dorothy"), eq("Null"), anyMap(), anyString(), anyString()))
+ .thenReturn(null);
+
+ while (managerThread.isAlive()) {
+ Thread.sleep(100);
+ }
+
+ PolicyEngine.manager.getEnvironment().remove("vfc.password");
+ PolicyEngine.manager.getEnvironment().remove("vfc.username");
+ PolicyEngine.manager.getEnvironment().remove("vfc.url");
+ }
+
+ @Test
+ public void testVfcExecutionError0() throws InterruptedException {
+ PolicyEngine.manager.getEnvironment().put("vfc.url", "http://somewhere.over.the.rainbow");
+ PolicyEngine.manager.getEnvironment().put("vfc.username", "Dorothy");
+ PolicyEngine.manager.getEnvironment().put("vfc.password", "Error0");
+
+ VFCManager manager = new VFCManager(mockedWorkingMemory, request);
+ manager.setRestManager(mockedRestManager);
+
+ Thread managerThread = new Thread(manager);
+ managerThread.start();
+
+ when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"),
+ eq("Dorothy"), eq("Error0"), anyMap(), anyString(), anyString()))
+ .thenReturn(httpResponseErr);
+
+ while (managerThread.isAlive()) {
+ Thread.sleep(100);
+ }
+
+ PolicyEngine.manager.getEnvironment().remove("vfc.password");
+ PolicyEngine.manager.getEnvironment().remove("vfc.username");
+ PolicyEngine.manager.getEnvironment().remove("vfc.url");
+ }
+
+ @Test
+ public void testVfcExecutionBadResponse() throws InterruptedException {
+ PolicyEngine.manager.getEnvironment().put("vfc.url", "http://somewhere.over.the.rainbow");
+ PolicyEngine.manager.getEnvironment().put("vfc.username", "Dorothy");
+ PolicyEngine.manager.getEnvironment().put("vfc.password", "BadResponse");
+
+ VFCManager manager = new VFCManager(mockedWorkingMemory, request);
+ manager.setRestManager(mockedRestManager);
+
+ Thread managerThread = new Thread(manager);
+ managerThread.start();
+
+ when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"),
+ eq("Dorothy"), eq("OK"), anyMap(), anyString(), anyString()))
+ .thenReturn(httpResponseBadResponse);
+
+ while (managerThread.isAlive()) {
+ Thread.sleep(100);
+ }
+
+ PolicyEngine.manager.getEnvironment().remove("vfc.password");
+ PolicyEngine.manager.getEnvironment().remove("vfc.username");
+ PolicyEngine.manager.getEnvironment().remove("vfc.url");
+ }
+
+ @Test
+ public void testVfcExecutionOk() throws InterruptedException {
+ PolicyEngine.manager.getEnvironment().put("vfc.url", "http://somewhere.over.the.rainbow");
+ PolicyEngine.manager.getEnvironment().put("vfc.username", "Dorothy");
+ PolicyEngine.manager.getEnvironment().put("vfc.password", "OK");
+
+ VFCManager manager = new VFCManager(mockedWorkingMemory, request);
+ manager.setRestManager(mockedRestManager);
+
+ Thread managerThread = new Thread(manager);
+ managerThread.start();
+
+ when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"),
+ eq("Dorothy"), eq("OK"), anyMap(), anyString(), anyString()))
+ .thenReturn(httpResponsePutOk);
+
+ when(mockedRestManager.get(endsWith("1234"), eq("Dorothy"), eq("OK"), anyMap()))
+ .thenReturn(httpResponseGetOk);
+
+ while (managerThread.isAlive()) {
+ Thread.sleep(100);
+ }
+
+ PolicyEngine.manager.getEnvironment().remove("vfc.password");
+ PolicyEngine.manager.getEnvironment().remove("vfc.username");
+ PolicyEngine.manager.getEnvironment().remove("vfc.url");
+ }
+}
* vfc
* ================================================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2018 AT&T Corporation. 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.
package org.onap.policy.vfc;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
import java.util.UUID;
import org.junit.Test;
-public class TestVFCRequest {
-
- @Test
- public void testVFCRequest() {
- VFCRequest request = new VFCRequest();
- assertNotNull(request);
- assertNotEquals(0, request.hashCode());
-
- String nsInstanceId = "Dorothy";
- request.setNSInstanceId(nsInstanceId);
- assertEquals(nsInstanceId, request.getNSInstanceId());
-
- UUID requestId = UUID.randomUUID();
- request.setRequestId(requestId);
- assertEquals(requestId, request.getRequestId());
-
- VFCHealRequest healRequest = new VFCHealRequest();
- request.setHealRequest(healRequest);
- assertEquals(healRequest, request.getHealRequest());
-
- assertNotEquals(0, request.hashCode());
- }
+public class TestVfcRequest {
+
+ @Test
+ public void testVfcRequest() {
+ VFCRequest request = new VFCRequest();
+ assertNotNull(request);
+ assertNotEquals(0, request.hashCode());
+
+ String nsInstanceId = "Dorothy";
+ request.setNSInstanceId(nsInstanceId);
+ assertEquals(nsInstanceId, request.getNSInstanceId());
+
+ UUID requestId = UUID.randomUUID();
+ request.setRequestId(requestId);
+ assertEquals(requestId, request.getRequestId());
+
+ VFCHealRequest healRequest = new VFCHealRequest();
+ request.setHealRequest(healRequest);
+ assertEquals(healRequest, request.getHealRequest());
+
+ assertNotEquals(0, request.hashCode());
+ }
}
* vfc
* ================================================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2018 AT&T Corporation. 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.
package org.onap.policy.vfc;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
import org.junit.Test;
-public class TestVFCHealAdditionalParams {
-
- @Test
- public void testVFCHealAdditionalParameters() {
- VFCHealAdditionalParams additionalParams = new VFCHealAdditionalParams();
- assertNotNull(additionalParams);
- assertNotEquals(0, additionalParams.hashCode());
-
- String action = "Go Home";
- additionalParams.setAction(action);
- assertEquals(action, additionalParams.getAction());
-
- VFCHealActionVmInfo actionInfo = new VFCHealActionVmInfo();
- additionalParams.setActionInfo(actionInfo );
- assertEquals(actionInfo, additionalParams.getActionInfo());
-
- assertNotEquals(0, additionalParams.hashCode());
- }
+public class TestVfcResponse {
+
+ @Test
+ public void testVfcResponse() {
+ VFCResponse response = new VFCResponse();
+ assertNotNull(response);
+ assertNotEquals(0, response.hashCode());
+
+ String jobId = "GetToOz";
+ response.setJobId(jobId);
+ assertEquals(jobId, response.getJobId());
+
+ String requestId = "Get Home";
+ response.setRequestId(requestId);
+ assertEquals(requestId, response.getRequestId());
+
+ VFCResponseDescriptor responseDescriptor = new VFCResponseDescriptor();
+ response.setResponseDescriptor(responseDescriptor);
+ assertEquals(responseDescriptor, response.getResponseDescriptor());
+
+ assertNotEquals(0, response.hashCode());
+ }
}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * vfc
+ * ================================================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2018 AT&T Corporation. 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.vfc;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+
+public class TestVfcResponseDescriptor {
+
+ @Test
+ public void testVfcResponseDescriptor() {
+ VFCResponseDescriptor descriptor = new VFCResponseDescriptor();
+ assertNotNull(descriptor);
+ assertNotEquals(0, descriptor.hashCode());
+
+ String errorCode = "WitchIsDead";
+ descriptor.setErrorCode(errorCode);
+ assertEquals(errorCode, descriptor.getErrorCode());
+
+ String progress = "Visited Wizard";
+ descriptor.setProgress(progress);
+ assertEquals(progress, descriptor.getProgress());
+
+ List<VFCResponseDescriptor> responseHistoryList = new ArrayList<>();
+ descriptor.setResponseHistoryList(responseHistoryList);
+ assertEquals(responseHistoryList, descriptor.getResponseHistoryList());
+
+ String responseId = "WishHard";
+ descriptor.setResponseId(responseId);
+ assertEquals(responseId, descriptor.getResponseId());
+
+ String status = "Back in Kansas";
+ descriptor.setStatus(status);
+ assertEquals(status, descriptor.getStatus());
+
+ String statusDescription = "Back on the prairie";
+ descriptor.setStatusDescription(statusDescription);
+ assertEquals(statusDescription, descriptor.getStatusDescription());
+
+ assertNotEquals(0, descriptor.hashCode());
+ }
+}
* vfc
* ================================================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2018 AT&T Corporation. 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.
package org.onap.policy.vfc.util;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertNotNull;
import org.junit.Test;
public class TestSerialization {
- @Test
- public void test() {
- assertNotNull(Serialization.gsonPretty);
- }
+ @Test
+ public void test() {
+ assertNotNull(Serialization.gsonPretty);
+ }
}
* ============LICENSE_START=======================================================
* policy-yaml
* ================================================================================
- * 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.
&& callback != null) {
callback.onError("Missing controlLoopName");
}
- if ((!controlLoop.getVersion().contentEquals(ControlLoop.getVERSION())) && callback != null) {
+ if ((!controlLoop.getVersion().contentEquals(ControlLoop.getCompilerVersion())) && callback != null) {
callback.onError("Unsupported version for this compiler");
}
if (controlLoop.getTrigger_policy() == null || controlLoop.getTrigger_policy().length() < 1) {
package org.onap.policy.controlloop.guard.compiler;
-
import java.io.InputStream;
+
import java.util.HashSet;
import java.util.List;
import java.util.Set;
// Private Constructor
}
- public static ControlLoopGuard compile(ControlLoopGuard cLGuard,
+ /**
+ * Compile the control loop guard.
+ *
+ * @param clGuard the guard
+ * @param callback callback routine
+ * @return the guard object
+ * @throws CompilerException compilation exception
+ */
+ public static ControlLoopGuard compile(ControlLoopGuard clGuard,
ControlLoopCompilerCallback callback) throws CompilerException {
//
// Ensure ControlLoopGuard has at least one guard policies
//
- validateControlLoopGuard(cLGuard, callback);
+ validateControlLoopGuard(clGuard, callback);
//
// Ensure each guard policy has at least one constraints and all guard policies are unique
//
- validateGuardPolicies(cLGuard.getGuards(), callback);
+ validateGuardPolicies(clGuard.getGuards(), callback);
//
// Ensure constraints for each guard policy are unique
//
- validateConstraints(cLGuard.getGuards(), callback);
+ validateConstraints(clGuard.getGuards(), callback);
- return cLGuard;
+ return clGuard;
}
+ /**
+ * Compile the control loop guard.
+ *
+ * @param yamlSpecification yaml specification as a stream
+ * @param callback callback method
+ * @return guard object
+ * @throws CompilerException throws compile exception
+ */
public static ControlLoopGuard compile(InputStream yamlSpecification,
ControlLoopCompilerCallback callback) throws CompilerException {
Yaml yaml = new Yaml(new Constructor(ControlLoopGuard.class));
return ControlLoopGuardCompiler.compile((ControlLoopGuard) obj, callback);
}
- private static void validateControlLoopGuard(ControlLoopGuard cLGuard,
+ private static void validateControlLoopGuard(ControlLoopGuard clGuard,
ControlLoopCompilerCallback callback) throws CompilerException {
- if (cLGuard == null) {
+ if (clGuard == null) {
if (callback != null) {
callback.onError("ControlLoop Guard cannot be null");
}
throw new CompilerException("ControlLoop Guard cannot be null");
}
- if (cLGuard.getGuard() == null && callback != null) {
+ if (clGuard.getGuard() == null && callback != null) {
callback.onError("Guard version cannot be null");
}
- if (cLGuard.getGuards() == null) {
+ if (clGuard.getGuards() == null) {
if (callback != null) {
callback.onError("ControlLoop Guard should have at least one guard policies");
}
- } else if (cLGuard.getGuards().isEmpty() && callback != null) {
+ } else if (clGuard.getGuards().isEmpty() && callback != null) {
callback.onError("ControlLoop Guard should have at least one guard policies");
}
}
* ============LICENSE_START=======================================================
* policy-yaml
* ================================================================================
- * 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.
// Empty Constructor.
}
- public static String getVERSION() {
+ public static String getCompilerVersion() {
return ControlLoop.COMPILER_VERSION;
}
this.pnf = pnf;
}
+ /**
+ * Constructor.
+ *
+ * @param controlLoop copy object
+ */
public ControlLoop(ControlLoop controlLoop) {
this.controlLoopName = controlLoop.controlLoopName;
this.services = new LinkedList<>();
* ============LICENSE_START=======================================================
* policy-yaml
* ================================================================================
- * 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.
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
ControlLoopPolicy other = (ControlLoopPolicy) obj;
if (controlLoop == null) {
- if (other.controlLoop != null)
+ if (other.controlLoop != null) {
return false;
- } else if (!controlLoop.equals(other.controlLoop))
+ }
+ } else if (!controlLoop.equals(other.controlLoop)) {
return false;
+ }
if (policies == null) {
- if (other.policies != null)
+ if (other.policies != null) {
return false;
- } else if (!policies.equals(other.policies))
+ }
+ } else if (!policies.equals(other.policies)) {
return false;
+ }
return true;
}
this.result = result;
}
+ /**
+ * Converts to a result object.
+ *
+ * @param result input string
+ * @return result object
+ */
public static FinalResult toResult(String result) {
if (result.equalsIgnoreCase(FINAL_SUCCESS.toString())) {
return FINAL_SUCCESS;
return null;
}
+ /**
+ * Check if the result really is a result.
+ *
+ * @param result string
+ * @param finalResult result object
+ * @return true if a result
+ */
public static boolean isResult(String result, FinalResult finalResult) {
FinalResult toResult = FinalResult.toResult(result);
if (toResult == null) {
* ============LICENSE_START=======================================================
* policy-yaml
* ================================================================================
- * 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.
public class OperationsAccumulateParams implements Serializable {
- /**
- *
- */
private static final long serialVersionUID = -3597358159130168247L;
private String period;
result = prime * result + ((limit == null) ? 0 : limit.hashCode());
return result;
}
+
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
OperationsAccumulateParams other = (OperationsAccumulateParams) obj;
if (period == null) {
- if (other.period != null)
+ if (other.period != null) {
return false;
- } else if (!period.equals(other.period))
+ }
+ } else if (!period.equals(other.period)) {
return false;
+ }
if (limit == null) {
- if (other.limit != null)
+ if (other.limit != null) {
return false;
- } else if (!limit.equals(other.limit))
+ }
+ } else if (!limit.equals(other.limit)) {
return false;
+ }
return true;
}
this.id = id;
}
+ /**
+ * Constructor.
+ *
+ * @param name name
+ * @param actor actor
+ * @param recipe recipe
+ * @param payload payload
+ * @param target target
+ */
public Policy(String name, String actor, String recipe, Map<String, String> payload, Target target) {
this.name = name;
this.actor = actor;
}
}
+ /**
+ * Constructor.
+ *
+ * @param name name
+ * @param actor actor
+ * @param recipe recipe
+ * @param payload payload
+ * @param target target
+ * @param retries retries
+ * @param timeout timeout
+ */
public Policy(String name, String actor, String recipe, Map<String, String> payload, Target target,
Integer retries, Integer timeout) {
this(name, actor, recipe, payload, target);
this.timeout = timeout;
}
+ /**
+ * Constructor.
+ *
+ * @param id id
+ * @param name name
+ * @param description description
+ * @param actor actor
+ * @param payload payload
+ * @param target target
+ * @param recipe recipe
+ * @param retries retries
+ * @param timeout timeout
+ */
public Policy(String id, String name, String description, String actor, Map<String, String> payload,
Target target, String recipe, Integer retries, Integer timeout) {
this(name, actor, recipe, payload, target, retries, timeout);
this.description = description;
}
+ /**
+ * Constructor.
+ *
+ * @param policy copy object
+ */
public Policy(Policy policy) {
this.id = policy.id;
this.name = policy.name;
* ============LICENSE_START=======================================================
* policy-yaml
* ================================================================================
- * 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.
return this.result;
}
+ /**
+ * Convert to a result.
+ *
+ * @param result result string
+ * @return Result object
+ */
public static PolicyResult toResult(String result) {
if (result.equalsIgnoreCase(SUCCESS.toString())) {
return SUCCESS;
* ============LICENSE_START=======================================================
* policy-yaml
* ================================================================================
- * 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.
public class Target implements Serializable {
- /**
- *
- */
private static final long serialVersionUID = 2180988443264988319L;
- private String resourceID;
+ private String resourceId;
private TargetType type;
public Target() {
}
public String getResourceID() {
- return resourceID;
+ return resourceId;
}
- public void setResourceID(String resourceID) {
- this.resourceID = resourceID;
+ public void setResourceID(String resourceId) {
+ this.resourceId = resourceId;
}
public TargetType getType() {
this.type = type;
}
- public Target(String resourceID) {
- this.resourceID = resourceID;
+ public Target(String resourceId) {
+ this.resourceId = resourceId;
}
- public Target(TargetType type, String resourceID) {
+ public Target(TargetType type, String resourceId) {
this.type = type;
- this.resourceID = resourceID;
+ this.resourceId = resourceId;
}
public Target(Target target) {
this.type = target.type;
- this.resourceID = target.resourceID;
+ this.resourceId = target.resourceId;
}
@Override
public String toString() {
- return "Target [type=" + type + ", resourceID=" + resourceID + "]";
+ return "Target [type=" + type + ", resourceId=" + resourceId + "]";
}
@Override
final int prime = 31;
int result = 1;
result = prime * result + ((type == null) ? 0 : type.hashCode());
- result = prime * result + ((resourceID == null) ? 0 : resourceID.hashCode());
+ result = prime * result + ((resourceId == null) ? 0 : resourceId.hashCode());
return result;
}
+
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
Target other = (Target) obj;
if (type == null) {
- if (other.type != null)
+ if (other.type != null) {
return false;
- } else if (!type.equals(other.type))
+ }
+ } else if (!type.equals(other.type)) {
return false;
- if (resourceID == null) {
- if (other.resourceID != null)
+ }
+ if (resourceId == null) {
+ if (other.resourceId != null) {
return false;
- } else if (!resourceID.equals(other.resourceID))
+ }
+ } else if (!resourceId.equals(other.resourceId)) {
return false;
+ }
return true;
}
}
* ============LICENSE_START=======================================================
* policy-yaml
* ================================================================================
- * 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.
public interface ControlLoopPolicyBuilder {
/**
- * Adds one or more services to the ControlLoop
+ * Adds one or more services to the ControlLoop.
*
- *
- * @param service
- * @return
- * @throws BuilderException
+ * @param services service to add
+ * @return builder object
+ * @throws BuilderException builder exception
*/
public ControlLoopPolicyBuilder addService(Service... services) throws BuilderException;
/**
- * @param services
- * @return
- * @throws BuilderException
+ * Remove service.
+ *
+ * @param services to remove
+ * @return builder object
+ * @throws BuilderException builder exception
*/
public ControlLoopPolicyBuilder removeService(Service... services) throws BuilderException;
/**
- * @return
- * @throws BuilderException
+ * Remove all the services.
+ *
+ * @return builder object
+ * @throws BuilderException builder exception
*/
public ControlLoopPolicyBuilder removeAllServices() throws BuilderException;
/**
- * Adds one or more resources to the ControlLoop
- *
+ * Adds one or more resources to the ControlLoop.
*
- * @param resource
- * @return
- * @throws BuilderException
+ * @return builder object
+ * @throws BuilderException builder exception
*/
public ControlLoopPolicyBuilder addResource(Resource... resources) throws BuilderException;
/**
- * @param resources
- * @return
- * @throws BuilderException
+ * Remove the resources.
+ *
+ * @param resources resources to be removed
+ * @return object
+ * @throws BuilderException builder exception
*/
public ControlLoopPolicyBuilder removeResource(Resource... resources) throws BuilderException;
/**
- * @return
- * @throws BuilderException
+ * Remove all resources.
+ *
+ * @return object
+ * @throws BuilderException builder exception
*/
public ControlLoopPolicyBuilder removeAllResources() throws BuilderException;
/**
- * @param pnf
- * @return
- * @throws BuilderException
+ * Set the PNF.
+ *
+ * @param pnf input pnf
+ * @return builder object
+ * @throws BuilderException builder exception
*/
public ControlLoopPolicyBuilder setPNF(Pnf pnf) throws BuilderException;
/**
- * @return
- * @throws BuilderException
+ * Remove PNF.
+ *
+ * @return the object
+ * @throws BuilderException builder exception
*/
public ControlLoopPolicyBuilder removePNF() throws BuilderException;
/**
- * @param abatement
- * @return
- * @throws BuilderException
+ * Set the abatement.
+ *
+ * @param abatement whether abatement is possible
+ * @return object
+ * @throws BuilderException builder exception
*/
public ControlLoopPolicyBuilder setAbatement(Boolean abatement) throws BuilderException;
* Sets the overall timeout value for the Control Loop. If any operational policies have retries
* and timeouts, then this overall timeout value should exceed all those values.
*
- * @param timeout
- * @return
- * @throws BuilderException
+ * @param timeout timeout value
+ * @return control loop policy builder
+ * @throws BuilderException builder exception
*/
public ControlLoopPolicyBuilder setTimeout(Integer timeout) throws BuilderException;
* Platform.
*
*
- * @param name
- * @param description
- * @param actor
- * @param target
- * @param recipe
- * @param retries
- * @param timeout
- * @return Policy
- * @throws BuilderException
+ * @param name name
+ * @param description description
+ * @param actor actor
+ * @param target target
+ * @param recipe recipe
+ * @param retries retries
+ * @param timeout timeout
+ * @return Policy object
+ * @throws BuilderException builder exception
*/
public Policy setTriggerPolicy(String name, String description, String actor, Target target, String recipe,
Map<String, String> payload, Integer retries, Integer timeout) throws BuilderException;
/**
- *
* Changes the trigger policy to point to another existing Policy.
*
- *
- * @param id
- * @return ControlLoop
- * @throws BuilderException
+ * @param id the id
+ * @return ControlLoop object
+ * @throws BuilderException build exception
*/
public ControlLoop setTriggerPolicy(String id) throws BuilderException;
/**
- * @return
+ * Is an open loop.
+ *
+ * @return true or false
*/
public boolean isOpenLoop();
/**
- * @return
- * @throws BuilderException
+ * Get the trigger policy.
+ *
+ * @return the policy object
+ * @throws BuilderException if there is a builder exception
*/
public Policy getTriggerPolicy() throws BuilderException;
/**
* Creates a policy that is chained to the result of another Policy.
*
- *
- * @param name
- * @param description
- * @param actor
- * @param target
- * @param recipe
- * @param retries
- * @param timeout
- * @param policyID
- * @param results
- * @return
- * @throws BuilderException
+ * @param name name
+ * @param description description
+ * @param actor actor
+ * @param target target
+ * @param recipe recipe
+ * @param retries retries
+ * @param timeout timeout
+ * @param policyId id
+ * @param results results
+ * @return Policy that was set
+ * @throws BuilderException builder exception
*/
public Policy setPolicyForPolicyResult(String name, String description, String actor, Target target, String recipe,
- Map<String, String> payload, Integer retries, Integer timeout, String policyID, PolicyResult... results)
+ Map<String, String> payload, Integer retries, Integer timeout, String policyId, PolicyResult... results)
throws BuilderException;
/**
* Sets the policy result(s) to an existing Operational Policy.
*
- *
- * @param policyResultID
- * @param policyID
- * @param results
- * @return
- * @throws BuilderException
+ * @param policyResultId result ID
+ * @param policyId id
+ * @param results results
+ * @return Policy that was set
+ * @throws BuilderException builder exception
*/
- public Policy setPolicyForPolicyResult(String policyResultID, String policyID, PolicyResult... results)
+ public Policy setPolicyForPolicyResult(String policyResultId, String policyId, PolicyResult... results)
throws BuilderException;
/**
* their result reset to the appropriate default FINAL_* result.
*
*
- * @param policyID
- * @return
- * @throws BuilderException
+ * @param policyID id for the policy
+ * @return true if removed else false
+ * @throws BuilderException builder exception
*/
public boolean removePolicy(String policyID) throws BuilderException;
/**
* Resets a policy's results to defualt FINAL_* codes.
*
- *
- * @return Policy
+ * @return Policy object
* @throws BuilderException - Policy does not exist
*/
public Policy resetPolicyResults(String policyID) throws BuilderException;
public ControlLoopPolicyBuilder removeAllPolicies();
/**
- * Adds an operationsAccumulateParams to an existing operational policy
+ * Adds an operationsAccumulateParams to an existing operational policy.
*
* @return Policy
* @throws BuilderException - Policy does not exist
* @param services - Zero or more services associated with this resource. Should come from
* ASDC, but if not available use serviceName to distinguish.
* @return ControlLoopPolicyBuilder object
- * @throws BuilderException
+ * @throws BuilderException builder exception
*/
public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout,
Resource resource, Service... services) throws BuilderException {
}
/**
- * @param controlLoopName
- * @param timeout
- * @param service
- * @param resources
- * @return
- * @throws BuilderException
+ * Build the control loop.
+ *
+ * @param controlLoopName control loop id
+ * @param timeout timeout
+ * @param service service
+ * @param resources resources
+ * @return builder object
+ * @throws BuilderException builder exception
*/
public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout,
Service service, Resource... resources) throws BuilderException {
}
/**
+ * Build control loop.
+ *
* @param controlLoopName - Per Closed Loop AID v1.0, unique string for the closed loop.
* @param timeout - Overall timeout for the Closed Loop to execute.
* @param pnf - Physical Network Function. Should come from AIC, but if not available use
* well-known name to distinguish. Eg. eNodeB
* @return ControlLoopPolicyBuilder object
- * @throws BuilderException
+ * @throws BuilderException builder exception
*/
public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout, Pnf pnf)
throws BuilderException {
* ============LICENSE_START=======================================================
* policy-yaml
* ================================================================================
- * 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.
package org.onap.policy.controlloop.policy.builder;
public enum MessageLevel {
- INFO,
- WARNING,
- ERROR,
- EXCEPTION
- ;
-
+ INFO,
+ WARNING,
+ ERROR,
+ EXCEPTION;
}
* ============LICENSE_START=======================================================
* policy-yaml
* ================================================================================
- * 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.
private static Logger logger = LoggerFactory.getLogger(ControlLoopPolicyBuilderImpl.class.getName());
private ControlLoopPolicy controlLoopPolicy;
+ /**
+ * Constructor.
+ *
+ * @param controlLoopName control loop id
+ * @param timeout timeout value
+ */
public ControlLoopPolicyBuilderImpl(String controlLoopName, Integer timeout) {
controlLoopPolicy = new ControlLoopPolicy();
ControlLoop controlLoop = new ControlLoop();
controlLoopPolicy.setControlLoop(controlLoop);
}
+ /**
+ * Constructor.
+ *
+ * @param controlLoopName control loop id
+ * @param timeout timeout value
+ * @param resource resource
+ * @param services services
+ * @throws BuilderException builder exception
+ */
public ControlLoopPolicyBuilderImpl(String controlLoopName, Integer timeout, Resource resource, Service... services)
throws BuilderException {
this(controlLoopName, timeout);
this.setPNF(pnf);
}
+ /**
+ * Constructor.
+ *
+ * @param controlLoopName control loop id
+ * @param timeout timeout
+ * @param service service
+ * @param resources resources
+ * @throws BuilderException builder exception
+ */
public ControlLoopPolicyBuilderImpl(String controlLoopName, Integer timeout, Service service, Resource[] resources)
throws BuilderException {
this(controlLoopName, timeout);
if (resource == null) {
throw new BuilderException("Resource must not be null");
}
- if (resource.getResourceUUID() == null && Strings.isNullOrEmpty(resource.getResourceName())) {
+ if (resource.getResourceUuid() == null && Strings.isNullOrEmpty(resource.getResourceName())) {
throw new BuilderException("Invalid resource - need either resourceUUID or resourceName");
}
if (controlLoopPolicy.getControlLoop().getResources() == null) {
return new Policy(trigger);
}
+ @Override
+ public ControlLoop setTriggerPolicy(String id) throws BuilderException {
+ if (id == null) {
+ throw new BuilderException("Id must not be null");
+ }
+ Policy trigger = this.findPolicy(id);
+ if (trigger == null) {
+ throw new BuilderException(UNKNOWN_POLICY + id);
+ } else {
+ this.controlLoopPolicy.getControlLoop().setTrigger_policy(id);
+ }
+ return new ControlLoop(this.controlLoopPolicy.getControlLoop());
+ }
+
@Override
public Policy setPolicyForPolicyResult(String name, String description, String actor, Target target, String recipe,
- Map<String, String> payload, Integer retries, Integer timeout, String policyID, PolicyResult... results)
+ Map<String, String> payload, Integer retries, Integer timeout, String policyId, PolicyResult... results)
throws BuilderException {
//
// Find the existing policy
//
- Policy existingPolicy = this.findPolicy(policyID);
+ Policy existingPolicy = this.findPolicy(policyId);
if (existingPolicy == null) {
- throw new BuilderException(UNKNOWN_POLICY + policyID);
+ throw new BuilderException(UNKNOWN_POLICY + policyId);
}
//
// Create the new Policy
return new Policy(newPolicy);
}
+ @Override
+ public Policy setPolicyForPolicyResult(String policyResultId, String policyId, PolicyResult... results)
+ throws BuilderException {
+ //
+ // Find the existing policy
+ //
+ Policy existingPolicy = this.findPolicy(policyId);
+ if (existingPolicy == null) {
+ throw new BuilderException(policyId + " does not exist");
+ }
+ if (this.findPolicy(policyResultId) == null) {
+ throw new BuilderException("Operational policy " + policyResultId + " does not exist");
+ }
+ //
+ // Connect the results
+ //
+ for (PolicyResult result : results) {
+ switch (result) {
+ case FAILURE:
+ existingPolicy.setFailure(policyResultId);
+ break;
+ case FAILURE_EXCEPTION:
+ existingPolicy.setFailure_exception(policyResultId);
+ break;
+ case FAILURE_RETRIES:
+ existingPolicy.setFailure_retries(policyResultId);
+ break;
+ case FAILURE_TIMEOUT:
+ existingPolicy.setFailure_timeout(policyResultId);
+ break;
+ case FAILURE_GUARD:
+ existingPolicy.setFailure_guard(policyResultId);
+ break;
+ case SUCCESS:
+ existingPolicy.setSuccess(policyResultId);
+ break;
+ default:
+ throw new BuilderException("Invalid PolicyResult " + result);
+ }
+ }
+ return new Policy(this.findPolicy(policyResultId));
+ }
+
private class BuilderCompilerCallback implements ControlLoopCompilerCallback {
private ResultsImpl results = new ResultsImpl();
if (resource == null) {
throw new BuilderException("Resource must not be null");
}
- if (resource.getResourceUUID() == null && Strings.isNullOrEmpty(resource.getResourceName())) {
+ if (resource.getResourceUuid() == null && Strings.isNullOrEmpty(resource.getResourceName())) {
throw new BuilderException("Invalid resource - need either a resourceUUID or resourceName");
}
boolean removed = controlLoopPolicy.getControlLoop().getResources().remove(resource);
return Integer.valueOf(sum);
}
- @Override
- public ControlLoop setTriggerPolicy(String id) throws BuilderException {
- if (id == null) {
- throw new BuilderException("Id must not be null");
- }
- Policy trigger = this.findPolicy(id);
- if (trigger == null) {
- throw new BuilderException(UNKNOWN_POLICY + id);
- } else {
- this.controlLoopPolicy.getControlLoop().setTrigger_policy(id);
- }
- return new ControlLoop(this.controlLoopPolicy.getControlLoop());
- }
-
@Override
public boolean isOpenLoop() {
return this.controlLoopPolicy.getControlLoop().getTrigger_policy()
}
@Override
- public Policy setPolicyForPolicyResult(String policyResultID, String policyID, PolicyResult... results)
- throws BuilderException {
- //
- // Find the existing policy
- //
- Policy existingPolicy = this.findPolicy(policyID);
- if (existingPolicy == null) {
- throw new BuilderException(policyID + " does not exist");
- }
- if (this.findPolicy(policyResultID) == null) {
- throw new BuilderException("Operational policy " + policyResultID + " does not exist");
- }
- //
- // Connect the results
- //
- for (PolicyResult result : results) {
- switch (result) {
- case FAILURE:
- existingPolicy.setFailure(policyResultID);
- break;
- case FAILURE_EXCEPTION:
- existingPolicy.setFailure_exception(policyResultID);
- break;
- case FAILURE_RETRIES:
- existingPolicy.setFailure_retries(policyResultID);
- break;
- case FAILURE_TIMEOUT:
- existingPolicy.setFailure_timeout(policyResultID);
- break;
- case FAILURE_GUARD:
- existingPolicy.setFailure_guard(policyResultID);
- break;
- case SUCCESS:
- existingPolicy.setSuccess(policyResultID);
- break;
- default:
- throw new BuilderException("Invalid PolicyResult " + result);
- }
- }
- return new Policy(this.findPolicy(policyResultID));
- }
-
- @Override
- public boolean removePolicy(String policyID) throws BuilderException {
- Policy existingPolicy = this.findPolicy(policyID);
+ public boolean removePolicy(String policyId) throws BuilderException {
+ Policy existingPolicy = this.findPolicy(policyId);
if (existingPolicy == null) {
- throw new BuilderException(UNKNOWN_POLICY + policyID);
+ throw new BuilderException(UNKNOWN_POLICY + policyId);
}
//
// Check if the policy to remove is trigger_policy
//
- if (this.controlLoopPolicy.getControlLoop().getTrigger_policy().equals(policyID)) {
+ if (this.controlLoopPolicy.getControlLoop().getTrigger_policy().equals(policyId)) {
this.controlLoopPolicy.getControlLoop().setTrigger_policy(FinalResult.FINAL_OPENLOOP.toString());
} else {
- updateChainedPoliciesForPolicyRemoval(policyID);
+ updateChainedPoliciesForPolicyRemoval(policyId);
}
//
// remove the policy
private void updateChainedPoliciesForPolicyRemoval(String idOfPolicyBeingRemoved) {
for (Policy policy : this.controlLoopPolicy.getPolicies()) {
- int index = this.controlLoopPolicy.getPolicies().indexOf(policy);
+ final int index = this.controlLoopPolicy.getPolicies().indexOf(policy);
if (policy.getSuccess().equals(idOfPolicyBeingRemoved)) {
policy.setSuccess(FinalResult.FINAL_SUCCESS.toString());
}
}
@Override
- public Policy resetPolicyResults(String policyID) throws BuilderException {
- Policy existingPolicy = this.findPolicy(policyID);
+ public Policy resetPolicyResults(String policyId) throws BuilderException {
+ Policy existingPolicy = this.findPolicy(policyId);
if (existingPolicy == null) {
- throw new BuilderException(UNKNOWN_POLICY + policyID);
+ throw new BuilderException(UNKNOWN_POLICY + policyId);
}
//
// reset policy results
}
@Override
- public Policy addOperationsAccumulateParams(String policyID, OperationsAccumulateParams operationsAccumulateParams)
+ public Policy addOperationsAccumulateParams(String policyId, OperationsAccumulateParams operationsAccumulateParams)
throws BuilderException {
- Policy existingPolicy = this.findPolicy(policyID);
+ Policy existingPolicy = this.findPolicy(policyId);
if (existingPolicy == null) {
- throw new BuilderException(UNKNOWN_POLICY + policyID);
+ throw new BuilderException(UNKNOWN_POLICY + policyId);
}
//
// Add operationsAccumulateParams to existingPolicy
this.blacklist = blacklist;
}
+ /**
+ * Constructor.
+ *
+ * @param freqLimitPerTarget frequency limit
+ * @param timeWindow time window
+ */
public Constraint(Integer freqLimitPerTarget, Map<String, String> timeWindow) {
this.freqLimitPerTarget = freqLimitPerTarget;
- if(timeWindow!=null){
+ if (timeWindow != null) {
this.timeWindow = Collections.unmodifiableMap(timeWindow);
}
}
this.blacklist = new LinkedList<>(blacklist);
}
+ /**
+ * Constructor.
+ *
+ * @param freqLimitPerTarget frequency limit
+ * @param timeWindow time window
+ * @param blacklist blacklist
+ */
public Constraint(Integer freqLimitPerTarget, Map<String, String> timeWindow, List<String> blacklist) {
this.freqLimitPerTarget = freqLimitPerTarget;
this.timeWindow = Collections.unmodifiableMap(timeWindow);
this.blacklist = new LinkedList<>(blacklist);
}
+ /**
+ * Constructor.
+ *
+ * @param freqLimitPerTarget frequency limit
+ * @param timeWindow time window
+ * @param activeTimeRange active time range
+ */
public Constraint(Integer freqLimitPerTarget, Map<String, String> timeWindow, Map<String, String> activeTimeRange) {
this(freqLimitPerTarget, timeWindow);
if (activeTimeRange != null) {
}
}
+ /**
+ * Constructor.
+ *
+ * @param freqLimitPerTarget frequency limit
+ * @param timeWindow the time window
+ * @param activeTimeRange active time range
+ * @param blacklist incoming blacklist
+ */
public Constraint(Integer freqLimitPerTarget, Map<String, String> timeWindow, Map<String, String> activeTimeRange,
List<String> blacklist) {
this(freqLimitPerTarget, timeWindow);
if (activeTimeRange != null) {
this.activeTimeRange = Collections.unmodifiableMap(activeTimeRange);
}
- if(blacklist != null){
+ if (blacklist != null) {
this.blacklist = new LinkedList<>(blacklist);
}
}
+ /**
+ * Constructor.
+ *
+ * @param constraint objec to copy
+ */
public Constraint(Constraint constraint) {
this.freqLimitPerTarget = constraint.freqLimitPerTarget;
this.timeWindow = constraint.timeWindow;
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
Constraint other = (Constraint) obj;
return equalsMayBeNull(freqLimitPerTarget, other.freqLimitPerTarget)
- && equalsMayBeNull(timeWindow, other.timeWindow)
- && equalsMayBeNull(activeTimeRange, other.activeTimeRange)
- && equalsMayBeNull(blacklist, other.blacklist);
+ && equalsMayBeNull(timeWindow, other.timeWindow)
+ && equalsMayBeNull(activeTimeRange, other.activeTimeRange)
+ && equalsMayBeNull(blacklist, other.blacklist);
}
- private boolean equalsMayBeNull(final Object obj1, final Object obj2){
- if ( obj1 == null ) {
+ private boolean equalsMayBeNull(final Object obj1, final Object obj2) {
+ if (obj1 == null) {
return obj2 == null;
}
- return obj1.equals(obj2);
+ return obj1.equals(obj2);
}
}
* ============LICENSE_START=======================================================
* policy-yaml
* ================================================================================
- * 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.
this.guards = guards;
}
- public ControlLoopGuard(ControlLoopGuard cLGuard) {
+ public ControlLoopGuard(ControlLoopGuard clGuard) {
this.guard = new Guard();
- this.guards = new LinkedList<>(cLGuard.guards);
+ this.guards = new LinkedList<>(clGuard.guards);
}
@Override
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
ControlLoopGuard other = (ControlLoopGuard) obj;
if (guard == null) {
- if (other.guard != null)
+ if (other.guard != null) {
return false;
- } else if (!guard.equals(other.guard))
+ }
+ } else if (!guard.equals(other.guard)) {
return false;
+ }
if (guards == null) {
- if (other.guards != null)
+ if (other.guards != null) {
return false;
- } else if (!guards.equals(other.guards))
+ }
+ } else if (!guards.equals(other.guards)) {
return false;
+ }
return true;
}
* ============LICENSE_START=======================================================
* policy-yaml
* ================================================================================
- * 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.
public String toString() {
return "Guard [version=" + version + "]";
}
+
@Override
public int hashCode() {
final int prime = 31;
result = prime * result + ((version == null) ? 0 : version.hashCode());
return result;
}
+
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
Guard other = (Guard) obj;
if (version == null) {
- if (other.version != null)
+ if (other.version != null) {
return false;
- } else if (!version.equals(other.version))
+ }
+ } else if (!version.equals(other.version)) {
return false;
+ }
return true;
}
}
this.matchParameters = matchParameters;
}
+ /**
+ * Constructor.
+ *
+ * @param id id
+ * @param name name
+ * @param description description
+ * @param matchParameters match parameters
+ */
public GuardPolicy(String id, String name, String description, MatchParameters matchParameters) {
this(name, matchParameters);
this.id = id;
this.description = description;
}
+ /**
+ * Constructor.
+ *
+ * @param name name
+ * @param matchParameters match parameters
+ * @param limitConstraints limit constraints
+ */
public GuardPolicy(String name, MatchParameters matchParameters, List<Constraint> limitConstraints) {
this(name, matchParameters);
if (limitConstraints != null) {
this.id = id;
}
+ /**
+ * Constructor.
+ *
+ * @param policy copy object
+ */
public GuardPolicy(GuardPolicy policy) {
this.id = policy.id;
this.name = policy.name;
* ============LICENSE_START=======================================================
* policy-yaml
* ================================================================================
- * 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.
this.recipe = recipe;
}
+ /**
+ * Constructor.
+ *
+ * @param actor actor
+ * @param recipe recipe
+ * @param targets targets
+ */
public MatchParameters(String actor, String recipe, List<String> targets) {
this(actor, recipe);
if (targets != null) {
this.controlLoopName = controlLoopName;
}
+ /**
+ * Constructor.
+ *
+ * @param matchParameters match parameters
+ */
public MatchParameters(MatchParameters matchParameters) {
this.controlLoopName = matchParameters.controlLoopName;
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
MatchParameters other = (MatchParameters) obj;
return equalsMayBeNull(actor, other.actor)
- && equalsMayBeNull(controlLoopName, other.controlLoopName)
- && equalsMayBeNull(recipe, other.recipe)
- && equalsMayBeNull(targets, other.targets);
+ && equalsMayBeNull(controlLoopName, other.controlLoopName)
+ && equalsMayBeNull(recipe, other.recipe)
+ && equalsMayBeNull(targets, other.targets);
}
- private boolean equalsMayBeNull(final Object obj1, final Object obj2){
- if ( obj1 == null ) {
+ private boolean equalsMayBeNull(final Object obj1, final Object obj2) {
+ if (obj1 == null) {
return obj2 == null;
}
- return obj1.equals(obj2);
+ return obj1.equals(obj2);
}
}
public interface ControlLoopGuardBuilder {
/**
- * Adds one or more guard policies to the Control Loop Guard
+ * Adds one or more guard policies to the Control Loop Guard.
*
- *
- * @param policies
- * @return
- * @throws BuilderException
+ * @param policies policies to add
+ * @return builder object
+ * @throws BuilderException builder exception
*/
public ControlLoopGuardBuilder addGuardPolicy(GuardPolicy... policies) throws BuilderException;
/**
- * Removes one or more guard policies from the Control Loop Guard
- *
+ * Removes one or more guard policies from the Control Loop Guard.
*
- * @param policies
- * @return
- * @throws BuilderException
+ * @param policies policies to add
+ * @return builder object
+ * @throws BuilderException builder exception
*/
public ControlLoopGuardBuilder removeGuardPolicy(GuardPolicy... policies) throws BuilderException;
/**
- * Removes all guard policies from the Control Loop Guard
- *
+ * Removes all guard policies from the Control Loop Guard.
*
- * @param
- * @return
- * @throws BuilderException
+ * @return builder object
+ * @throws BuilderException builder exception
*/
public ControlLoopGuardBuilder removeAllGuardPolicies() throws BuilderException;
/**
- * Adds one or more time limit constraints to the guard policy
- *
+ * Adds one or more time limit constraints to the guard policy.
*
* @param id (guard policy id)
- * @param constraints
- * @return
- * @throws BuilderException
+ * @param constraints the constraints to add
+ * @return builder object
+ * @throws BuilderException builder exception
*/
public ControlLoopGuardBuilder addLimitConstraint(String id, Constraint... constraints) throws BuilderException;
/**
- * Removes one or more time limit constraints from the guard policy
- *
+ * Removes one or more time limit constraints from the guard policy.
*
* @param id (guard policy id)
- * @param constraints
- * @return
- * @throws BuilderException
+ * @param constraints constraints to remove
+ * @return builder object
+ * @throws BuilderException builder exception
*/
public ControlLoopGuardBuilder removeLimitConstraint(String id, Constraint... constraints) throws BuilderException;
/**
- * Removes all time limit constraints from the guard policy
- *
+ * Removes all time limit constraints from the guard policy.
*
* @param id (guard policy id)
- * @return
- * @throws BuilderException
+ * @return builder object
+ * @throws BuilderException builder exception
*/
public ControlLoopGuardBuilder removeAllLimitConstraints(String id) throws BuilderException;
private static final String THE_ID_OF_TARGET_GUARD_POLICY_MUST_NOT_BE_NULL =
"The id of target guard policy must not be null";
private static Logger logger = LoggerFactory.getLogger(ControlLoopGuardBuilderImpl.class.getName());
- private ControlLoopGuard cLGuard;
+ private ControlLoopGuard clGuard;
public ControlLoopGuardBuilderImpl(Guard guard) {
- cLGuard = new ControlLoopGuard();
- cLGuard.setGuard(guard);
+ clGuard = new ControlLoopGuard();
+ clGuard.setGuard(guard);
}
@Override
if (!policy.isValid()) {
throw new BuilderException("Invalid guard policy - some required fields are missing");
}
- if (cLGuard.getGuards() == null) {
- cLGuard.setGuards(new LinkedList<>());
+ if (clGuard.getGuards() == null) {
+ clGuard.setGuards(new LinkedList<>());
}
- cLGuard.getGuards().add(policy);
+ clGuard.getGuards().add(policy);
}
return this;
}
if (policies == null) {
throw new BuilderException("GuardPolicy must not be null");
}
- if (cLGuard.getGuards() == null) {
+ if (clGuard.getGuards() == null) {
throw new BuilderException("No existing guard policies to remove");
}
for (GuardPolicy policy : policies) {
if (!policy.isValid()) {
throw new BuilderException("Invalid guard policy - some required fields are missing");
}
- boolean removed = cLGuard.getGuards().remove(policy);
+ boolean removed = clGuard.getGuards().remove(policy);
if (!removed) {
throw new BuilderException("Unknown guard policy: " + policy.getName());
}
@Override
public ControlLoopGuardBuilder removeAllGuardPolicies() throws BuilderException {
- cLGuard.getGuards().clear();
+ clGuard.getGuards().clear();
return this;
}
private boolean addLimitConstraints(String id, Constraint... constraints) throws BuilderException {
boolean exist = false;
- for (GuardPolicy policy: cLGuard.getGuards()) {
+ for (GuardPolicy policy: clGuard.getGuards()) {
//
// We could have only one guard policy matching the id
//
private boolean removeConstraints(String id, Constraint... constraints) throws BuilderException {
boolean exist = false;
- for (GuardPolicy policy: cLGuard.getGuards()) {
+ for (GuardPolicy policy: clGuard.getGuards()) {
//
// We could have only one guard policy matching the id
//
@Override
public ControlLoopGuardBuilder removeAllLimitConstraints(String id) throws BuilderException {
- if (cLGuard.getGuards() == null || cLGuard.getGuards().isEmpty()) {
+ if (clGuard.getGuards() == null || clGuard.getGuards().isEmpty()) {
throw new BuilderException("No guard policies exist");
}
if (id == null) {
throw new BuilderException(THE_ID_OF_TARGET_GUARD_POLICY_MUST_NOT_BE_NULL);
}
boolean exist = false;
- for (GuardPolicy policy: cLGuard.getGuards()) {
+ for (GuardPolicy policy: clGuard.getGuards()) {
if (policy.getId().equals(id)) {
exist = true;
policy.getLimit_constraints().clear();
@Override
public ControlLoopGuard getControlLoopGuard() {
- return new ControlLoopGuard(this.cLGuard);
+ return new ControlLoopGuard(this.clGuard);
}
options.setDefaultFlowStyle(FlowStyle.BLOCK);
options.setPrettyFlow(true);
Yaml yaml = new Yaml(options);
- String dumpedYaml = yaml.dump(cLGuard);
+ String dumpedYaml = yaml.dump(clGuard);
//
// This is our callback class for our compiler
//
// Compile it
//
try {
- ControlLoopGuardCompiler.compile(cLGuard, callback);
+ ControlLoopGuardCompiler.compile(clGuard, callback);
} catch (CompilerException e) {
logger.error(e.getMessage() + e);
callback.results.addMessage(new MessageImpl(e.getMessage(), MessageLevel.EXCEPTION));
package org.onap.policy.controlloop.compiler;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.File;
import java.io.FileInputStream;
return test(testFile, null);
}
+ /**
+ * Does the actual test.
+ *
+ * @param testFile test file
+ * @param controlLoopCompilerCallback callback method
+ * @return the policy object
+ * @throws Exception exception
+ */
public ControlLoopPolicy test(String testFile,
ControlLoopCompilerCallback controlLoopCompilerCallback) throws Exception {
try (InputStream is = new FileInputStream(new File(testFile))) {
}
}
+ /**
+ * Does the actual test.
+ *
+ * @param testFile input test file
+ * @throws Exception exception thrown
+ */
public void test(String testFile) throws Exception {
try (InputStream is = new FileInputStream(new File(testFile))) {
ControlLoopGuardCompiler.compile(is, null);
* ============LICENSE_START=======================================================
* policy-yaml unit test
* ================================================================================
- * 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.
//
// Test add services
//
- Service vSCP = new Service("vSCP");
- Service vUSP = new Service("vUSP");
- Service vTrinity = new Service("Trinity");
- builder = builder.addService(vSCP, vUSP, vTrinity);
+ Service scp = new Service("vSCP");
+ Service usp = new Service("vUSP");
+ Service trinity = new Service("Trinity");
+ builder = builder.addService(scp, usp, trinity);
assertTrue(builder.getControlLoop().getServices().size() == 3);
//
// Test remove services
//
- builder = builder.removeService(vSCP);
+ builder = builder.removeService(scp);
assertTrue(builder.getControlLoop().getServices().size() == 2);
builder = builder.removeAllServices();
assertTrue(builder.getControlLoop().getServices().size() == 0);
//
// Test add resources
//
- Resource vCTS = new Resource("vCTS", ResourceType.VF);
- Resource vCOM = new Resource("vCTS", ResourceType.VF);
- Resource vRAR = new Resource("vCTS", ResourceType.VF);
- builder = builder.addResource(vCTS, vCOM, vRAR);
+ Resource cts = new Resource("vCTS", ResourceType.VF);
+ Resource com = new Resource("vCTS", ResourceType.VF);
+ Resource rar = new Resource("vCTS", ResourceType.VF);
+ builder = builder.addResource(cts, com, rar);
assertTrue(builder.getControlLoop().getResources().size() == 3);
//
// Test remove resources
//
- builder = builder.removeResource(vCTS);
+ builder = builder.removeResource(cts);
assertTrue(builder.getControlLoop().getResources().size() == 2);
builder = builder.removeAllResources();
assertTrue(builder.getControlLoop().getResources().size() == 0);
}
@Test
- public void testAddServiceWithUUID() throws BuilderException {
+ public void testAddServiceWithUuid() throws BuilderException {
ControlLoopPolicyBuilder builder =
ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
UUID uuid = UUID.randomUUID();
- Service serviceWithUUID = new Service(uuid);
- builder.addService(serviceWithUUID);
+ Service serviceWithUuid = new Service(uuid);
+ builder.addService(serviceWithUuid);
assertTrue(builder.getControlLoop().getServices().size() == 1);
}
}
@Test
- public void testAddAndRemoveResourceWithUUID() throws BuilderException {
+ public void testAddAndRemoveResourceWithUuid() throws BuilderException {
ControlLoopPolicyBuilder builder =
ControlLoopPolicyBuilder.Factory.buildControlLoop(UUID.randomUUID().toString(), 2400);
UUID uuid = UUID.randomUUID();
- Resource resourceWithUUID = new Resource(uuid);
- builder.addResource(resourceWithUUID);
+ Resource resourceWithUuid = new Resource(uuid);
+ builder.addResource(resourceWithUuid);
assertTrue(builder.getControlLoop().getResources().size() == 1);
- builder.removeResource(resourceWithUUID);
+ builder.removeResource(resourceWithUuid);
assertTrue(builder.getControlLoop().getResources().size() == 0);
}
@Test
public void testControlLoopWithInitialResourceAndServices() {
try {
- Resource vCTS = new Resource("vCTS", ResourceType.VF);
- Service vSCP = new Service("vSCP");
- Service vUSP = new Service("vUSP");
+ Resource cts = new Resource("vCTS", ResourceType.VF);
+ Service scp = new Service("vSCP");
+ Service usp = new Service("vUSP");
ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory
- .buildControlLoop(UUID.randomUUID().toString(), 2400, vCTS, vSCP, vUSP);
+ .buildControlLoop(UUID.randomUUID().toString(), 2400, cts, scp, usp);
assertTrue(builder.getControlLoop().getResources().size() == 1);
assertTrue(builder.getControlLoop().getServices().size() == 2);
} catch (BuilderException e) {
@Test
public void testControlLoopWithInitialResourcesAndService() {
try {
- Resource vCTS = new Resource("vCTS", ResourceType.VF);
- Resource vCOM = new Resource("vCTS", ResourceType.VF);
- Service vSCP = new Service("vSCP");
+ Resource cts = new Resource("vCTS", ResourceType.VF);
+ Resource com = new Resource("vCTS", ResourceType.VF);
+ Service scp = new Service("vSCP");
ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory
- .buildControlLoop(UUID.randomUUID().toString(), 2400, vSCP, vCTS, vCOM);
+ .buildControlLoop(UUID.randomUUID().toString(), 2400, scp, cts, com);
assertTrue(builder.getControlLoop().getServices().size() == 1);
assertTrue(builder.getControlLoop().getResources().size() == 2);
} catch (BuilderException e) {
//
// Create another policy and chain it to the results of trigger policy
//
- Policy onRestartFailurePolicy2 =
+ final Policy onRestartFailurePolicy2 =
builder.setPolicyForPolicyResult("Rebuild VM", "If the restart fails, rebuild it.", "APPC",
new Target(TargetType.VM), "Rebuild", null, 2, 600, triggerPolicy.getId(),
PolicyResult.FAILURE, PolicyResult.FAILURE_RETRIES, PolicyResult.FAILURE_TIMEOUT);
//
// Test set the policy results to an existing operational policy
//
- onRestartFailurePolicy2 =
+ Policy onRestartFailurePolicy3 =
builder.setPolicyForPolicyResult(onRestartFailurePolicy2.getId(), triggerPolicy.getId(),
PolicyResult.FAILURE, PolicyResult.FAILURE_RETRIES, PolicyResult.FAILURE_TIMEOUT);
- assertTrue(builder.getTriggerPolicy().getFailure().equals(onRestartFailurePolicy2.getId()));
- assertTrue(builder.getTriggerPolicy().getFailure_retries().equals(onRestartFailurePolicy2.getId()));
- assertTrue(builder.getTriggerPolicy().getFailure_timeout().equals(onRestartFailurePolicy2.getId()));
+ assertTrue(builder.getTriggerPolicy().getFailure().equals(onRestartFailurePolicy3.getId()));
+ assertTrue(builder.getTriggerPolicy().getFailure_retries().equals(onRestartFailurePolicy3.getId()));
+ assertTrue(builder.getTriggerPolicy().getFailure_timeout().equals(onRestartFailurePolicy3.getId()));
//
// Test set the policy result for success to an existing operational policy
//
- onRestartFailurePolicy2 =
+ Policy onRestartFailurePolicy4 =
builder.setPolicyForPolicyResult(onRestartFailurePolicy2.getId(), triggerPolicy.getId(),
PolicyResult.FAILURE, PolicyResult.FAILURE_EXCEPTION, PolicyResult.FAILURE_GUARD,
PolicyResult.FAILURE_RETRIES, PolicyResult.FAILURE_TIMEOUT, PolicyResult.SUCCESS);
- assertTrue(builder.getTriggerPolicy().getFailure().equals(onRestartFailurePolicy2.getId()));
- assertTrue(builder.getTriggerPolicy().getFailure_exception().equals(onRestartFailurePolicy2.getId()));
- assertTrue(builder.getTriggerPolicy().getFailure_guard().equals(onRestartFailurePolicy2.getId()));
- assertTrue(builder.getTriggerPolicy().getFailure_retries().equals(onRestartFailurePolicy2.getId()));
- assertTrue(builder.getTriggerPolicy().getFailure_timeout().equals(onRestartFailurePolicy2.getId()));
- assertTrue(builder.getTriggerPolicy().getSuccess().equals(onRestartFailurePolicy2.getId()));
+ assertTrue(builder.getTriggerPolicy().getFailure().equals(onRestartFailurePolicy4.getId()));
+ assertTrue(builder.getTriggerPolicy().getFailure_exception().equals(onRestartFailurePolicy4.getId()));
+ assertTrue(builder.getTriggerPolicy().getFailure_guard().equals(onRestartFailurePolicy4.getId()));
+ assertTrue(builder.getTriggerPolicy().getFailure_retries().equals(onRestartFailurePolicy4.getId()));
+ assertTrue(builder.getTriggerPolicy().getFailure_timeout().equals(onRestartFailurePolicy4.getId()));
+ assertTrue(builder.getTriggerPolicy().getSuccess().equals(onRestartFailurePolicy4.getId()));
//
// Test remove all existing operational policies
//
// Set the first invalid trigger policy
//
- Policy policy1 = builder.setTriggerPolicy("Restart the VM",
+ final Policy policy1 = builder.setTriggerPolicy("Restart the VM",
"Upon getting the trigger event, restart the VM", null, null, "Instantiate", null, 2, 300);
Results results = builder.buildSpecification();
//
// Check that ERRORs are in results for invalid policy arguments
//
- boolean invalid_actor = false;
- boolean invalid_recipe = false;
- boolean invalid_target = false;
+ boolean invalidActor = false;
+ boolean invalidRecipe = false;
+ boolean invalidTarget = false;
for (Message m : results.getMessages()) {
if (m.getMessage().equals("Policy actor is null") && m.getLevel() == MessageLevel.ERROR) {
- invalid_actor = true;
+ invalidActor = true;
}
if (m.getMessage().equals("Policy recipe is invalid") && m.getLevel() == MessageLevel.ERROR) {
- invalid_recipe = true;
+ invalidRecipe = true;
}
if (m.getMessage().equals("Policy target is null") && m.getLevel() == MessageLevel.ERROR) {
- invalid_target = true;
+ invalidTarget = true;
}
}
//
- assertTrue(invalid_actor);
- assertTrue(invalid_recipe);
- assertTrue(invalid_target);
+ assertTrue(invalidActor);
+ assertTrue(invalidRecipe);
+ assertTrue(invalidTarget);
//
// Remove the invalid policy
//
//
// Set a valid trigger policy
//
- policy1 = builder.setTriggerPolicy("Rebuild VM", "If the restart fails, rebuild it.", "APPC",
+ Policy policy1a = builder.setTriggerPolicy("Rebuild VM", "If the restart fails, rebuild it.", "APPC",
new Target(TargetType.VM), "Rebuild", null, 1, 600);
//
// Set a second valid trigger policy
//
- Policy policy2 =
+ final Policy policy2 =
builder.setTriggerPolicy("Restart the VM", "Upon getting the trigger event, restart the VM", "APPC",
new Target(TargetType.VM), "Restart", null, 2, 300);
//
results = builder.buildSpecification();
boolean unreachable = false;
for (Message m : results.getMessages()) {
- if (m.getMessage().equals("Policy " + policy1.getId() + " is not reachable.")
+ if (m.getMessage().equals("Policy " + policy1a.getId() + " is not reachable.")
&& m.getLevel() == MessageLevel.WARNING) {
unreachable = true;
break;
}
assertTrue(unreachable);
//
- // Set policy1 for the failure results of policy2
+ // Set policy1a for the failure results of policy2
//
- policy1 = builder.setPolicyForPolicyResult(policy1.getId(), policy2.getId(), PolicyResult.FAILURE,
+ policy1a = builder.setPolicyForPolicyResult(policy1a.getId(), policy2.getId(), PolicyResult.FAILURE,
PolicyResult.FAILURE_RETRIES, PolicyResult.FAILURE_TIMEOUT);
results = builder.buildSpecification();
- boolean invalid_timeout = false;
+ boolean invalidTimeout = false;
for (Message m : results.getMessages()) {
if (m.getMessage()
.equals("controlLoop overall timeout is less than the sum of operational policy timeouts.")
&& m.getLevel() == MessageLevel.ERROR) {
- invalid_timeout = true;
+ invalidTimeout = true;
break;
}
}
- assertTrue(invalid_timeout);
+ assertTrue(invalidTimeout);
//
// Remove policy2 (revert controlLoop back to open loop)
//
@Test
- public void test() {
+ public void test1() {
this.test("src/test/resources/v1.0.0/policy_Test.yaml");
}
}
}
+ /**
+ * Does the actual test.
+ *
+ * @param testFile input file
+ */
public void test(String testFile) {
try (InputStream is = new FileInputStream(new File(testFile))) {
//
package org.onap.policy.controlloop.policy;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.File;
import java.io.FileInputStream;
private static final Logger logger = LoggerFactory.getLogger(ControlLoopPolicyTest.class);
@Test
- public void test() {
+ public void test1() {
this.test("src/test/resources/v1.0.0/policy_Test.yaml");
}
}
@Test
- public void testvDNS() {
+ public void testvdns() {
this.test("src/test/resources/v2.0.0/policy_ONAP_demo_vDNS.yaml");
}
@Test
public void testvFirewall() {
// Chenfei to fix this.
- // this.test("src/test/resources/v2.0.0/policy_ONAP_demo_vFirewall.yaml");
+ // this.test("src/test/resources/v2.0.0/policy_ONAP_demo_vFirewall.yaml");
}
@Test
- public void testvCPE() {
+ public void testvcpe() {
this.test("src/test/resources/v2.0.0/policy_ONAP_UseCase_vCPE.yaml");
}
@Test
- public void testVOLTE() {
+ public void testvolte() {
this.test("src/test/resources/v2.0.0/policy_ONAP_UseCase_VOLTE.yaml");
}
+ /**
+ * Does the actual test.
+ *
+ * @param testFile input file
+ */
public void test(String testFile) {
try (InputStream is = new FileInputStream(new File(testFile))) {
//
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. 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.
ControlLoop controlLoop2 = new ControlLoop();
controlLoop2.setControlLoopName(controlLoopName);
controlLoop2.setVersion(version);
- Service controlLoop2_service1 = new Service("service1");
- Service controlLoop2_service2 = new Service("service2");
- List<Service> controlLoop2_services = new ArrayList<>();
- controlLoop2_services.add(controlLoop2_service1);
- controlLoop2_services.add(controlLoop2_service2);
- controlLoop2.setServices(controlLoop2_services);
- Resource controlLoop2_resource1 = new Resource("resource1", ResourceType.VF);
- Resource controlLoop2_resource2 = new Resource("resource2", ResourceType.VFC);
- List<Resource> controlLoop2_resources = new ArrayList<>();
- controlLoop2_resources.add(controlLoop2_resource1);
- controlLoop2_resources.add(controlLoop2_resource2);
- controlLoop2.setResources(controlLoop2_resources);
+ Service controlLoop2Service1 = new Service("service1");
+ Service controlLoop2Service2 = new Service("service2");
+ List<Service> controlLoop2Services = new ArrayList<>();
+ controlLoop2Services.add(controlLoop2Service1);
+ controlLoop2Services.add(controlLoop2Service2);
+ controlLoop2.setServices(controlLoop2Services);
+ Resource controlLoop2Resource1 = new Resource("resource1", ResourceType.VF);
+ Resource controlLoop2Resource2 = new Resource("resource2", ResourceType.VFC);
+ List<Resource> controlLoop2Resources = new ArrayList<>();
+ controlLoop2Resources.add(controlLoop2Resource1);
+ controlLoop2Resources.add(controlLoop2Resource2);
+ controlLoop2.setResources(controlLoop2Resources);
controlLoop2.setPnf(pnf);
controlLoop2.setTrigger_policy(triggerPolicy);
controlLoop2.setTimeout(timeout);
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. 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.
package org.onap.policy.controlloop.policy;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import org.junit.Test;
@Test
public void testEqualsAndHashCode() {
- String period = "15m";
- Integer limit = 10;
+ final String period = "15m";
+ final Integer limit = 10;
OperationsAccumulateParams operationsAccumulateParams1 = new OperationsAccumulateParams();
OperationsAccumulateParams operationsAccumulateParams2 = new OperationsAccumulateParams();
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. 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.
package org.onap.policy.controlloop.policy.guard;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.HashMap;
activeTimeRange.put("timeWindowKey", "timeWindowValue");
Constraint constraint = new Constraint();
constraint.setActive_time_range(activeTimeRange);;
- assertEquals(activeTimeRange, constraint.getActive_time_range());
+ assertEquals(activeTimeRange, constraint.getActive_time_range());
}
@Test
blacklist.add("blacklist item");
Constraint constraint = new Constraint();
constraint.setBlacklist(blacklist);
- assertEquals(blacklist, constraint.getBlacklist());
+ assertEquals(blacklist, constraint.getBlacklist());
}
@Test
@Test
public void testIsValid() {
Integer freqLimitPerTarget = 10;
- Map<String, String> timeWindow = new HashMap<>();
+ final Map<String, String> timeWindow = new HashMap<>();
Constraint constraint = new Constraint();
assertTrue(constraint.isValid());
@Test
public void testEquals() {
Integer freqLimitPerTarget = 10;
- Map<String, String> timeWindow = new HashMap<>();
- Map<String, String> activeTimeRange = new HashMap<>();
+ final Map<String, String> timeWindow = new HashMap<>();
+ final Map<String, String> activeTimeRange = new HashMap<>();
List<String> blacklist = new ArrayList<>();
blacklist.add("blacklist item");
// Assert there is no guard policies yet
//
Results results = builder.buildSpecification();
- boolean no_guard_policies = false;
+ boolean noGuardPolicies = false;
for (Message m : results.getMessages()) {
if (m.getMessage().equals("ControlLoop Guard should have at least one guard policies")
&& m.getLevel() == MessageLevel.ERROR) {
- no_guard_policies = true;
+ noGuardPolicies = true;
break;
}
}
- assertTrue(no_guard_policies);
+ assertTrue(noGuardPolicies);
//
// Add a guard policy without limit constraint
//
// Assert there is no limit constraint associated with the only guard policy
//
results = builder.buildSpecification();
- boolean no_constraint = false;
+ boolean noConstraint = false;
for (Message m : results.getMessages()) {
if (m.getMessage().equals("Guard policy guardpolicy1 does not have any limit constraint")
&& m.getLevel() == MessageLevel.ERROR) {
- no_constraint = true;
+ noConstraint = true;
break;
}
}
- assertTrue(no_constraint);
+ assertTrue(noConstraint);
//
// Add a constraint to policy1
//
- Map<String, String> active_time_range = new HashMap<String, String>();
- active_time_range.put("start", "00:00:00-05:00");
- active_time_range.put("end", "23:59:59-05:00");
+ Map<String, String> activeTimeRange = new HashMap<String, String>();
+ activeTimeRange.put("start", "00:00:00-05:00");
+ activeTimeRange.put("end", "23:59:59-05:00");
List<String> blacklist = new LinkedList<String>();
blacklist.add("eNodeB_common_id1");
blacklist.add("eNodeB_common_id2");
- Map<String, String> time_window = new HashMap<String, String>();
- time_window.put("value", "10");
- time_window.put("units", "minute");
- Constraint cons = new Constraint(5, time_window, active_time_range, blacklist);
+ Map<String, String> timeWindow = new HashMap<String, String>();
+ timeWindow.put("value", "10");
+ timeWindow.put("units", "minute");
+ Constraint cons = new Constraint(5, timeWindow, activeTimeRange, blacklist);
builder = builder.addLimitConstraint(policy1.getId(), cons);
//
// Add a duplicate constraint to policy1
// Assert there are duplicate constraints associated with the only guard policy
//
results = builder.buildSpecification();
- boolean duplicate_constraint = false;
+ boolean duplicateConstraint = false;
for (Message m : results.getMessages()) {
if (m.getMessage().equals("Guard policy guardpolicy1 has duplicate limit constraints")
&& m.getLevel() == MessageLevel.WARNING) {
- duplicate_constraint = true;
+ duplicateConstraint = true;
break;
}
}
- assertTrue(duplicate_constraint);
+ assertTrue(duplicateConstraint);
//
// Remove the duplicate constraint
//
// Assert there are duplicate guard policies
//
results = builder.buildSpecification();
- boolean duplicate_guard_policy = false;
+ boolean duplicateGuardPolicy = false;
for (Message m : results.getMessages()) {
if (m.getMessage().equals("There are duplicate guard policies")
&& m.getLevel() == MessageLevel.WARNING) {
- duplicate_guard_policy = true;
+ duplicateGuardPolicy = true;
break;
}
}
- assertTrue(duplicate_guard_policy);
+ assertTrue(duplicateGuardPolicy);
//
// Remove the duplicate guard policy
//
this.test("src/test/resources/v2.0.0-guard/policy_guard_appc_restart.yaml");
}
+ /**
+ * Do the actual test.
+ *
+ * @param testFile input test file
+ */
public void test(String testFile) {
try (InputStream is = new FileInputStream(new File(testFile))) {
//
package org.onap.policy.controlloop.policy.guard;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.File;
import java.io.FileInputStream;
private static final Logger logger = LoggerFactory.getLogger(ControlLoopGuardTest.class);
@Test
- public void testGuardvDNS() {
+ public void testGuardvdns() {
this.test("src/test/resources/v2.0.0-guard/policy_guard_ONAP_demo_vDNS.yaml");
}
@Test
- public void testGuardvUSP() {
+ public void testGuardvusp() {
this.test("src/test/resources/v2.0.0-guard/policy_guard_appc_restart.yaml");
}
@Test
- public void testConstructorControlLoopGuard(){
+ public void testConstructorControlLoopGuard() {
Guard guard1 = new Guard();
GuardPolicy guardPolicy1 = new GuardPolicy();
GuardPolicy guardPolicy2 = new GuardPolicy();
@Test
public void testEqualsAndHashCode() {
- Guard guard1 = new Guard();
+ final Guard guard1 = new Guard();
GuardPolicy guardPolicy1 = new GuardPolicy();
GuardPolicy guardPolicy2 = new GuardPolicy();
LinkedList<GuardPolicy> guardPolicies = new LinkedList<>();
assertFalse(controlLoopGuard.equals(""));
}
+ /**
+ * Does the actual test.
+ *
+ * @param testFile input file
+ */
public void test(String testFile) {
try (InputStream is = new FileInputStream(new File(testFile))) {
//
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. 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.
@Test
public void testEquals() {
- String id = "guard id";
- String name = "guard name";
- String description = "guard description";
+ final String id = "guard id";
+ final String name = "guard name";
+ final String description = "guard description";
GuardPolicy guardPolicy1 = new GuardPolicy(id);
GuardPolicy guardPolicy2 = new GuardPolicy();
assertFalse(guardPolicy1.equals(guardPolicy2));
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
+
import java.util.HashMap;
import java.util.UUID;
import org.junit.AfterClass;
limitations under the License.
============LICENSE_END=========================================================
-->
-<Policy xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" PolicyId="urn:com:att:xacml:policy:id:25e12b06-11d5-4895-b2a2-6f6c594de069" Version="1" RuleCombiningAlgId="urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-unless-deny">
- <Description>Policy for frequency limiter.</Description>
- <Target>
- <AnyOf>
- <AllOf>
- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
+<Policy xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17"
+ PolicyId="urn:com:att:xacml:policy:id:25e12b06-11d5-4895-b2a2-6f6c594de069"
+ Version="1"
+ RuleCombiningAlgId="urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-unless-deny">
+ <Description>Policy for frequency limiter.</Description>
+ <Target>
+ <AnyOf>
+ <AllOf>
+ <Match
+ MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
<!-- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">.*</AttributeValue>-->
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">${clname}</AttributeValue>
- <AttributeDesignator Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" AttributeId="urn:oasis:names:tc:xacml:1.0:clname:clname-id" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false"/>
- </Match>
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#string">${clname}</AttributeValue>
+ <AttributeDesignator
+ Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
+ AttributeId="urn:oasis:names:tc:xacml:1.0:clname:clname-id"
+ DataType="http://www.w3.org/2001/XMLSchema#string"
+ MustBePresent="false" />
+ </Match>
- <!-- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">-->
- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">${actor}</AttributeValue>
- <AttributeDesignator Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" AttributeId="urn:oasis:names:tc:xacml:1.0:actor:actor-id" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false"/>
- </Match>
- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">${recipe}</AttributeValue>
- <AttributeDesignator Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action" AttributeId="urn:oasis:names:tc:xacml:1.0:operation:operation-id" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false"/>
- </Match>
- </AllOf>
- </AnyOf>
- </Target>
- <Rule RuleId="urn:com:att:xacml:rule:id:e1e8c5c0-e2ba-47d5-9289-6c015305ed21" Effect="Deny">
- <Description>DENY - only if target is in black list and guard is active.</Description>
- <Condition>
- <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:and">
- <VariableReference VariableId="isGuardActive"/>
- <VariableReference VariableId="isInBlackList"/>
- </Apply>
- </Condition>
- </Rule>
- <VariableDefinition VariableId="isInBlackList">
- <Apply FunctionId="urn:oasis:names:tc:xacml:3.0:function:any-of">
- <Function FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal"/>
- <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-one-and-only">
- <AttributeDesignator Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource" AttributeId="urn:oasis:names:tc:xacml:1.0:target:target-id" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false"/>
- </Apply>
- <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-bag">
- ${blackListElement}
- <!-- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">vserver.vserver-name</AttributeValue>-->
- </Apply>
- </Apply>
- </VariableDefinition>
- <VariableDefinition VariableId="isGuardActive">
- <Apply FunctionId="urn:oasis:names:tc:xacml:2.0:function:time-in-range">
- <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:time-one-and-only">
- <AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:environment:current-time" DataType="http://www.w3.org/2001/XMLSchema#time" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:environment" MustBePresent="false"/>
- </Apply>
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveStart}</AttributeValue>
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveEnd}</AttributeValue>
- </Apply>
- </VariableDefinition>
+ <!-- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">-->
+ <Match
+ MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#string">${actor}</AttributeValue>
+ <AttributeDesignator
+ Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
+ AttributeId="urn:oasis:names:tc:xacml:1.0:actor:actor-id"
+ DataType="http://www.w3.org/2001/XMLSchema#string"
+ MustBePresent="false" />
+ </Match>
+ <Match
+ MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#string">${recipe}</AttributeValue>
+ <AttributeDesignator
+ Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action"
+ AttributeId="urn:oasis:names:tc:xacml:1.0:operation:operation-id"
+ DataType="http://www.w3.org/2001/XMLSchema#string"
+ MustBePresent="false" />
+ </Match>
+ </AllOf>
+ </AnyOf>
+ </Target>
+ <Rule
+ RuleId="urn:com:att:xacml:rule:id:e1e8c5c0-e2ba-47d5-9289-6c015305ed21"
+ Effect="Deny">
+ <Description>DENY - only if target is in black list and guard is
+ active.</Description>
+ <Condition>
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:1.0:function:and">
+ <VariableReference
+ VariableId="isGuardActive" />
+ <VariableReference
+ VariableId="isInBlackList" />
+ </Apply>
+ </Condition>
+ </Rule>
+ <VariableDefinition VariableId="isInBlackList">
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:3.0:function:any-of">
+ <Function
+ FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal" />
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-one-and-only">
+ <AttributeDesignator
+ Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
+ AttributeId="urn:oasis:names:tc:xacml:1.0:target:target-id"
+ DataType="http://www.w3.org/2001/XMLSchema#string"
+ MustBePresent="false" />
+ </Apply>
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-bag">
+ ${blackListElement}
+ <!-- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">vserver.vserver-name</AttributeValue>-->
+ </Apply>
+ </Apply>
+ </VariableDefinition>
+ <VariableDefinition VariableId="isGuardActive">
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:2.0:function:time-in-range">
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:1.0:function:time-one-and-only">
+ <AttributeDesignator
+ AttributeId="urn:oasis:names:tc:xacml:1.0:environment:current-time"
+ DataType="http://www.w3.org/2001/XMLSchema#time"
+ Category="urn:oasis:names:tc:xacml:3.0:attribute-category:environment"
+ MustBePresent="false" />
+ </Apply>
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveStart}</AttributeValue>
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveEnd}</AttributeValue>
+ </Apply>
+ </VariableDefinition>
</Policy>
limitations under the License.
============LICENSE_END=========================================================
-->
-<Policy xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" PolicyId="urn:com:att:xacml:policy:id:25e12b06-11d5-4895-b2a2-6f6c594de069" Version="1" RuleCombiningAlgId="urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-unless-deny">
- <Description>Policy for frequency limiter.</Description>
- <Target>
- <AnyOf>
- <AllOf>
-
- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
+<Policy xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17"
+ PolicyId="urn:com:att:xacml:policy:id:25e12b06-11d5-4895-b2a2-6f6c594de069"
+ Version="1"
+ RuleCombiningAlgId="urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-unless-deny">
+ <Description>Policy for frequency limiter.</Description>
+ <Target>
+ <AnyOf>
+ <AllOf>
+
+ <Match
+ MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
<!-- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">.*</AttributeValue>-->
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">${clname}</AttributeValue>
- <AttributeDesignator Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" AttributeId="urn:oasis:names:tc:xacml:1.0:clname:clname-id" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false"/>
- </Match>
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#string">${clname}</AttributeValue>
+ <AttributeDesignator
+ Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
+ AttributeId="urn:oasis:names:tc:xacml:1.0:clname:clname-id"
+ DataType="http://www.w3.org/2001/XMLSchema#string"
+ MustBePresent="false" />
+ </Match>
- <!-- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">-->
- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">${actor}</AttributeValue>
- <AttributeDesignator Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" AttributeId="urn:oasis:names:tc:xacml:1.0:actor:actor-id" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false"/>
- </Match>
- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">${recipe}</AttributeValue>
- <AttributeDesignator Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action" AttributeId="urn:oasis:names:tc:xacml:1.0:operation:operation-id" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false"/>
- </Match>
-
- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">${targets}</AttributeValue>
- <AttributeDesignator Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource" AttributeId="urn:oasis:names:tc:xacml:1.0:target:target-id" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false"/>
- </Match>
-
- </AllOf>
- </AnyOf>
- </Target>
- <Rule RuleId="urn:com:att:xacml:rule:id:e1e8c5c0-e2ba-47d5-9289-6c015305ed21" Effect="Deny">
- <Description>DENY - only if number of operations performed in the past is larger than the limit and the Guard is active.</Description>
- <Condition>
- <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:and">
- <VariableReference VariableId="isGuardActive"/>
- <VariableReference VariableId="isHistoryGreaterThanLimit"/>
- </Apply>
- </Condition>
- </Rule>
- <VariableDefinition VariableId="isGuardActive">
- <Apply FunctionId="urn:oasis:names:tc:xacml:2.0:function:time-in-range">
- <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:time-one-and-only">
- <AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:environment:current-time" DataType="http://www.w3.org/2001/XMLSchema#time" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:environment" MustBePresent="false"/>
- </Apply>
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveStart}</AttributeValue>
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveEnd}</AttributeValue>
- </Apply>
- </VariableDefinition>
- <VariableDefinition VariableId="isHistoryGreaterThanLimit">
- <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:integer-greater-than-or-equal">
- <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:integer-one-and-only">
- <AttributeDesignator Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource" AttributeId="com:att:research:xacml:test:sql:resource:operations:count" DataType="http://www.w3.org/2001/XMLSchema#integer" Issuer="com:att:research:xacml:guard:historydb:tw:${twValue}:${twUnits}" MustBePresent="false"/>
- </Apply>
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#integer">${limit}</AttributeValue>
- </Apply>
- </VariableDefinition>
+ <!-- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">-->
+ <Match
+ MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#string">${actor}</AttributeValue>
+ <AttributeDesignator
+ Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
+ AttributeId="urn:oasis:names:tc:xacml:1.0:actor:actor-id"
+ DataType="http://www.w3.org/2001/XMLSchema#string"
+ MustBePresent="false" />
+ </Match>
+ <Match
+ MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#string">${recipe}</AttributeValue>
+ <AttributeDesignator
+ Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action"
+ AttributeId="urn:oasis:names:tc:xacml:1.0:operation:operation-id"
+ DataType="http://www.w3.org/2001/XMLSchema#string"
+ MustBePresent="false" />
+ </Match>
+
+ <Match
+ MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#string">${targets}</AttributeValue>
+ <AttributeDesignator
+ Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
+ AttributeId="urn:oasis:names:tc:xacml:1.0:target:target-id"
+ DataType="http://www.w3.org/2001/XMLSchema#string"
+ MustBePresent="false" />
+ </Match>
+
+ </AllOf>
+ </AnyOf>
+ </Target>
+ <Rule
+ RuleId="urn:com:att:xacml:rule:id:e1e8c5c0-e2ba-47d5-9289-6c015305ed21"
+ Effect="Deny">
+ <Description>DENY - only if number of operations performed in
+ the past is larger than the limit and the Guard is active.</Description>
+ <Condition>
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:1.0:function:and">
+ <VariableReference
+ VariableId="isGuardActive" />
+ <VariableReference
+ VariableId="isHistoryGreaterThanLimit" />
+ </Apply>
+ </Condition>
+ </Rule>
+ <VariableDefinition VariableId="isGuardActive">
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:2.0:function:time-in-range">
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:1.0:function:time-one-and-only">
+ <AttributeDesignator
+ AttributeId="urn:oasis:names:tc:xacml:1.0:environment:current-time"
+ DataType="http://www.w3.org/2001/XMLSchema#time"
+ Category="urn:oasis:names:tc:xacml:3.0:attribute-category:environment"
+ MustBePresent="false" />
+ </Apply>
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveStart}</AttributeValue>
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveEnd}</AttributeValue>
+ </Apply>
+ </VariableDefinition>
+ <VariableDefinition
+ VariableId="isHistoryGreaterThanLimit">
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:1.0:function:integer-greater-than-or-equal">
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:1.0:function:integer-one-and-only">
+ <AttributeDesignator
+ Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
+ AttributeId="com:att:research:xacml:test:sql:resource:operations:count"
+ DataType="http://www.w3.org/2001/XMLSchema#integer"
+ Issuer="com:att:research:xacml:guard:historydb:tw:${twValue}:${twUnits}"
+ MustBePresent="false" />
+ </Apply>
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#integer">${limit}</AttributeValue>
+ </Apply>
+ </VariableDefinition>
</Policy>
limitations under the License.
============LICENSE_END=========================================================
-->
-<Policy xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" PolicyId="urn:com:att:xacml:policy:id:25e12b06-11d5-4895-b2a2-6f6c594de069" Version="1" RuleCombiningAlgId="urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-unless-deny">
- <Description>Policy for frequency limiter.</Description>
- <Target>
- <AnyOf>
- <AllOf>
- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">${actor}</AttributeValue>
- <AttributeDesignator Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" AttributeId="urn:oasis:names:tc:xacml:1.0:actor:actor-id" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false"/>
- </Match>
- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">${recipe}</AttributeValue>
- <AttributeDesignator Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action" AttributeId="urn:oasis:names:tc:xacml:1.0:operation:operation-id" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="false"/>
- </Match>
- </AllOf>
- </AnyOf>
- </Target>
- <Rule RuleId="urn:com:att:xacml:rule:id:e1e8c5c0-e2ba-47d5-9289-6c015305ed21" Effect="Deny">
- <Description>DENY - only if number of operations performed in the past is larger than the limit and the Guard is active.</Description>
- <Condition>
- <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:and">
- <VariableReference VariableId="isGuardActive"/>
- <VariableReference VariableId="isHistoryGreaterThanLimit"/>
- </Apply>
- </Condition>
- </Rule>
- <VariableDefinition VariableId="isGuardActive">
- <Apply FunctionId="urn:oasis:names:tc:xacml:2.0:function:time-in-range">
- <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:time-one-and-only">
- <AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:environment:current-time" DataType="http://www.w3.org/2001/XMLSchema#time" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:environment" MustBePresent="false"/>
- </Apply>
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveStart}</AttributeValue>
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveEnd}</AttributeValue>
- </Apply>
- </VariableDefinition>
- <VariableDefinition VariableId="isHistoryGreaterThanLimit">
- <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:integer-greater-than-or-equal">
- <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:integer-one-and-only">
- <AttributeDesignator Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource" AttributeId="com:att:research:xacml:test:sql:resource:operations:count" DataType="http://www.w3.org/2001/XMLSchema#integer" Issuer="com:att:research:xacml:test:sql:${timeWindow}" MustBePresent="false"/>
- </Apply>
- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#integer">${limit}</AttributeValue>
- </Apply>
- </VariableDefinition>
+<Policy xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17"
+ PolicyId="urn:com:att:xacml:policy:id:25e12b06-11d5-4895-b2a2-6f6c594de069"
+ Version="1"
+ RuleCombiningAlgId="urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-unless-deny">
+ <Description>Policy for frequency limiter.</Description>
+ <Target>
+ <AnyOf>
+ <AllOf>
+ <Match
+ MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#string">${actor}</AttributeValue>
+ <AttributeDesignator
+ Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
+ AttributeId="urn:oasis:names:tc:xacml:1.0:actor:actor-id"
+ DataType="http://www.w3.org/2001/XMLSchema#string"
+ MustBePresent="false" />
+ </Match>
+ <Match
+ MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#string">${recipe}</AttributeValue>
+ <AttributeDesignator
+ Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action"
+ AttributeId="urn:oasis:names:tc:xacml:1.0:operation:operation-id"
+ DataType="http://www.w3.org/2001/XMLSchema#string"
+ MustBePresent="false" />
+ </Match>
+ </AllOf>
+ </AnyOf>
+ </Target>
+ <Rule
+ RuleId="urn:com:att:xacml:rule:id:e1e8c5c0-e2ba-47d5-9289-6c015305ed21"
+ Effect="Deny">
+ <Description>DENY - only if number of operations performed in
+ the past is larger than the limit and the Guard is active.</Description>
+ <Condition>
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:1.0:function:and">
+ <VariableReference
+ VariableId="isGuardActive" />
+ <VariableReference
+ VariableId="isHistoryGreaterThanLimit" />
+ </Apply>
+ </Condition>
+ </Rule>
+ <VariableDefinition VariableId="isGuardActive">
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:2.0:function:time-in-range">
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:1.0:function:time-one-and-only">
+ <AttributeDesignator
+ AttributeId="urn:oasis:names:tc:xacml:1.0:environment:current-time"
+ DataType="http://www.w3.org/2001/XMLSchema#time"
+ Category="urn:oasis:names:tc:xacml:3.0:attribute-category:environment"
+ MustBePresent="false" />
+ </Apply>
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveStart}</AttributeValue>
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveEnd}</AttributeValue>
+ </Apply>
+ </VariableDefinition>
+ <VariableDefinition
+ VariableId="isHistoryGreaterThanLimit">
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:1.0:function:integer-greater-than-or-equal">
+ <Apply
+ FunctionId="urn:oasis:names:tc:xacml:1.0:function:integer-one-and-only">
+ <AttributeDesignator
+ Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
+ AttributeId="com:att:research:xacml:test:sql:resource:operations:count"
+ DataType="http://www.w3.org/2001/XMLSchema#integer"
+ Issuer="com:att:research:xacml:test:sql:${timeWindow}"
+ MustBePresent="false" />
+ </Apply>
+ <AttributeValue
+ DataType="http://www.w3.org/2001/XMLSchema#integer">${limit}</AttributeValue>
+ </Apply>
+ </VariableDefinition>
</Policy>
public class ControlLoopFailureTest implements TopicListener {
- private static final Logger logger = LoggerFactory.getLogger(VCPEControlLoopTest.class);
+ private static final Logger logger = LoggerFactory.getLogger(ControlLoopFailureTest.class);
private static List<? extends TopicSink> noopTopics;
static {
/* Set environment properties */
- Util.setAAIProps();
+ Util.setAaiProps();
Util.setGuardProps();
- Util.setPUProp();
+ Util.setPuProp();
}
+ /**
+ * Setup simulator.
+ */
@BeforeClass
public static void setUpSimulator() {
PolicyEngine.manager.configure(new Properties());
*/
try {
kieSession = startSession(
- "../archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl",
+ "../archetype-cl-amsterdam/src/main/resources/archetype-resources"
+ + "/src/main/resources/__closedLoopControlName__.drl",
"src/test/resources/yaml/policy_ControlLoop_vCPE.yaml",
"service=ServiceDemo;resource=Res1Demo;type=operational", "CL_vCPE",
"org.onap.closed_loop.ServiceDemo:VNFS:1.0.0");
}
}
+ /**
+ * Tear down simulator.
+ */
@AfterClass
public static void tearDownSimulator() {
/*
* Simulate an onset event the policy engine will receive from DCAE to kick off processing
* through the rules
*/
- sendEvent(pair.a, requestId, ControlLoopEventStatus.ONSET, "vnf01");
+ sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET, "vnf01");
/*
* Send a second event requesting an action for a different target entity
*/
- sendEvent(pair.a, requestId2, ControlLoopEventStatus.ONSET, "vnf02");
+ sendEvent(pair.first, requestId2, ControlLoopEventStatus.ONSET, "vnf02");
/*
* Send a second event for a different target to ensure there are no problems with obtaining
* @param policyName name of the policy
* @param policyVersion version of the policy
* @return the kieSession to be used to insert facts
- * @throws IOException
+ * @throws IOException throws IO exception
*/
private static KieSession startSession(String droolsTemplate, String yamlFile, String policyScope,
String policyName, String policyVersion) throws IOException {
*/
pair = Util.loadYaml(yamlFile);
assertNotNull(pair);
- assertNotNull(pair.a);
- assertNotNull(pair.a.getControlLoop());
- assertNotNull(pair.a.getControlLoop().getControlLoopName());
- assertTrue(pair.a.getControlLoop().getControlLoopName().length() > 0);
+ assertNotNull(pair.first);
+ assertNotNull(pair.first.getControlLoop());
+ assertNotNull(pair.first.getControlLoop().getControlLoopName());
+ assertTrue(pair.first.getControlLoop().getControlLoopName().length() > 0);
/*
* Construct a kie session
*/
- final KieSession kieSession = Util.buildContainer(droolsTemplate, pair.a.getControlLoop().getControlLoopName(),
- policyScope, policyName, policyVersion, URLEncoder.encode(pair.b, "UTF-8"));
+ final KieSession kieSession = Util.buildContainer(droolsTemplate,
+ pair.first.getControlLoop().getControlLoopName(),
+ policyScope, policyName, policyVersion, URLEncoder.encode(pair.second, "UTF-8"));
/*
* Retrieve the Policy Engine
*/
logger.debug("============");
- logger.debug(URLEncoder.encode(pair.b, "UTF-8"));
+ logger.debug(URLEncoder.encode(pair.second, "UTF-8"));
logger.debug("============");
return kieSession;
assertNotNull(notification.getMessage());
assertTrue(notification.getMessage().startsWith("actor=APPC"));
if (requestId.equals(notification.getRequestId())) {
- sendEvent(pair.a, requestId, ControlLoopEventStatus.ABATED, "vnf01");
+ sendEvent(pair.first, requestId, ControlLoopEventStatus.ABATED, "vnf01");
} else if (requestId2.equals(notification.getRequestId())) {
- sendEvent(pair.a, requestId2, ControlLoopEventStatus.ABATED, "vnf02");
+ sendEvent(pair.first, requestId2, ControlLoopEventStatus.ABATED, "vnf02");
}
} else if (policyName.endsWith("EVENT.MANAGER")) {
logger.debug("Rule Fired: " + notification.getPolicyName());
* will be denied
*/
if (requestId.equals(appcResponse.getCommonHeader().getRequestId())) {
- sendEvent(pair.a, requestId3, ControlLoopEventStatus.ONSET, "vnf01");
+ sendEvent(pair.first, requestId3, ControlLoopEventStatus.ONSET, "vnf01");
}
kieSession.insert(dmaapResponse);
}
* @param policy the controlLoopName comes from the policy
* @param requestID the requestId for this event
* @param status could be onset or abated
- * @param target, the target entity to take an action on
+ * @param target the target entity to take an action on
*/
- protected void sendEvent(ControlLoopPolicy policy, UUID requestID, ControlLoopEventStatus status, String target) {
+ protected void sendEvent(ControlLoopPolicy policy, UUID requestId, ControlLoopEventStatus status, String target) {
VirtualControlLoopEvent event = new VirtualControlLoopEvent();
event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName());
- event.setRequestId(requestID);
+ event.setRequestId(requestId);
event.setTarget("generic-vnf.vnf-id");
event.setClosedLoopAlarmStart(Instant.now());
event.setAai(new HashMap<>());
* ============LICENSE_START=======================================================
* demo
* ================================================================================
- * 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.
import static org.junit.Assert.fail;
+import com.att.research.xacml.util.XACMLProperties;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import org.kie.api.builder.model.KieModuleModel;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
+import org.onap.policy.common.endpoints.http.server.HttpServletServer;
import org.onap.policy.controlloop.policy.ControlLoopPolicy;
import org.onap.policy.controlloop.policy.guard.ControlLoopGuard;
-import org.onap.policy.common.endpoints.http.server.HttpServletServer;
import org.onap.policy.drools.system.PolicyEngine;
import org.onap.policy.guard.PolicyGuardYamlToXacml;
import org.slf4j.Logger;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
-import com.att.research.xacml.util.XACMLProperties;
public final class Util {
- private static final String OPSHISTPUPROP = "OperationsHistoryPU";
- private static final Logger logger = LoggerFactory.getLogger(Util.class);
-
- public static class Pair<A, B> {
- public final A a;
- public final B b;
-
- public Pair(A a, B b) {
- this.a = a;
- this.b = b;
- }
- }
-
- public static Pair<ControlLoopPolicy, String> loadYaml(String testFile) {
- try (InputStream is = new FileInputStream(new File(testFile))) {
- String contents = IOUtils.toString(is, StandardCharsets.UTF_8);
- //
- // Read the yaml into our Java Object
- //
- Yaml yaml = new Yaml(new Constructor(ControlLoopPolicy.class));
- Object obj = yaml.load(contents);
-
- //String ttt = ((ControlLoopPolicy)obj).policies.getFirst().payload.get("asdas");
- logger.debug(contents);
- //for(Policy policy : ((ControlLoopPolicy)obj).policies){
-
- return new Pair<ControlLoopPolicy, String>((ControlLoopPolicy) obj, contents);
- } catch (FileNotFoundException e) {
- fail(e.getLocalizedMessage());
- } catch (IOException e) {
- fail(e.getLocalizedMessage());
- }
- return null;
- }
-
- public static ControlLoopGuard loadYamlGuard(String testFile) {
- try (InputStream is = new FileInputStream(new File(testFile))) {
- String contents = IOUtils.toString(is, StandardCharsets.UTF_8);
- //
- // Read the yaml into our Java Object
- //
- Yaml yaml = new Yaml(new Constructor(ControlLoopGuard.class));
- Object obj = yaml.load(contents);
- return (ControlLoopGuard) obj;
- } catch (FileNotFoundException e) {
- fail(e.getLocalizedMessage());
- } catch (IOException e) {
- fail(e.getLocalizedMessage());
- }
- return null;
- }
-
- public static HttpServletServer buildAaiSim() throws InterruptedException, IOException {
- return org.onap.policy.simulators.Util.buildAaiSim();
- }
-
- public static HttpServletServer buildSoSim() throws InterruptedException, IOException {
- return org.onap.policy.simulators.Util.buildSoSim();
- }
-
- public static HttpServletServer buildVfcSim() throws InterruptedException, IOException {
- return org.onap.policy.simulators.Util.buildVfcSim();
- }
-
- public static HttpServletServer buildGuardSim() throws InterruptedException, IOException {
+ private static final String OPSHISTPUPROP = "OperationsHistoryPU";
+ private static final Logger logger = LoggerFactory.getLogger(Util.class);
+
+ public static class Pair<A, B> {
+ public final A first;
+ public final B second;
+
+ public Pair(A first, B second) {
+ this.first = first;
+ this.second = second;
+ }
+ }
+
+ /**
+ * Load YAML.
+ *
+ * @param testFile test file to load
+ * @return the Pair of a policy and the yaml contents
+ */
+ public static Pair<ControlLoopPolicy, String> loadYaml(String testFile) {
+ try (InputStream is = new FileInputStream(new File(testFile))) {
+ String contents = IOUtils.toString(is, StandardCharsets.UTF_8);
+ //
+ // Read the yaml into our Java Object
+ //
+ Yaml yaml = new Yaml(new Constructor(ControlLoopPolicy.class));
+ Object obj = yaml.load(contents);
+
+ logger.debug(contents);
+
+ return new Pair<ControlLoopPolicy, String>((ControlLoopPolicy) obj, contents);
+ } catch (FileNotFoundException e) {
+ fail(e.getLocalizedMessage());
+ } catch (IOException e) {
+ fail(e.getLocalizedMessage());
+ }
+ return null;
+ }
+
+ /**
+ * Load the YAML guard policy.
+ *
+ * @param testFile the test file to load
+ * @return return the guard object
+ */
+ public static ControlLoopGuard loadYamlGuard(String testFile) {
+ try (InputStream is = new FileInputStream(new File(testFile))) {
+ String contents = IOUtils.toString(is, StandardCharsets.UTF_8);
+ //
+ // Read the yaml into our Java Object
+ //
+ Yaml yaml = new Yaml(new Constructor(ControlLoopGuard.class));
+ Object obj = yaml.load(contents);
+ return (ControlLoopGuard) obj;
+ } catch (FileNotFoundException e) {
+ fail(e.getLocalizedMessage());
+ } catch (IOException e) {
+ fail(e.getLocalizedMessage());
+ }
+ return null;
+ }
+
+ public static HttpServletServer buildAaiSim() throws InterruptedException, IOException {
+ return org.onap.policy.simulators.Util.buildAaiSim();
+ }
+
+ public static HttpServletServer buildSoSim() throws InterruptedException, IOException {
+ return org.onap.policy.simulators.Util.buildSoSim();
+ }
+
+ public static HttpServletServer buildVfcSim() throws InterruptedException, IOException {
+ return org.onap.policy.simulators.Util.buildVfcSim();
+ }
+
+ public static HttpServletServer buildGuardSim() throws InterruptedException, IOException {
return org.onap.policy.simulators.Util.buildGuardSim();
}
-
- private static String generatePolicy(String ruleContents,
- String closedLoopControlName,
- String policyScope,
- String policyName,
- String policyVersion,
- String controlLoopYaml) {
-
- Pattern p = Pattern.compile("\\$\\{closedLoopControlName\\}");
- Matcher m = p.matcher(ruleContents);
- ruleContents = m.replaceAll(closedLoopControlName);
-
- p = Pattern.compile("\\$\\{policyScope\\}");
- m = p.matcher(ruleContents);
- ruleContents = m.replaceAll(policyScope);
-
- p = Pattern.compile("\\$\\{policyName\\}");
- m = p.matcher(ruleContents);
- ruleContents = m.replaceAll(policyName);
-
- p = Pattern.compile("\\$\\{policyVersion\\}");
- m = p.matcher(ruleContents);
- ruleContents = m.replaceAll(policyVersion);
-
- p = Pattern.compile("\\$\\{controlLoopYaml\\}");
- m = p.matcher(ruleContents);
- ruleContents = m.replaceAll(controlLoopYaml);
-
- return ruleContents;
- }
-
- public static KieSession buildContainer(String droolsTemplate, String closedLoopControlName, String policyScope, String policyName, String policyVersion, String yamlSpecification) throws IOException {
- //
- // Get our Drools Kie factory
- //
+
+ private static String generatePolicy(String ruleContents,
+ String closedLoopControlName,
+ String policyScope,
+ String policyName,
+ String policyVersion,
+ String controlLoopYaml) {
+
+ Pattern pattern = Pattern.compile("\\$\\{closedLoopControlName\\}");
+ Matcher matcher = pattern.matcher(ruleContents);
+ ruleContents = matcher.replaceAll(closedLoopControlName);
+
+ pattern = Pattern.compile("\\$\\{policyScope\\}");
+ matcher = pattern.matcher(ruleContents);
+ ruleContents = matcher.replaceAll(policyScope);
+
+ pattern = Pattern.compile("\\$\\{policyName\\}");
+ matcher = pattern.matcher(ruleContents);
+ ruleContents = matcher.replaceAll(policyName);
+
+ pattern = Pattern.compile("\\$\\{policyVersion\\}");
+ matcher = pattern.matcher(ruleContents);
+ ruleContents = matcher.replaceAll(policyVersion);
+
+ pattern = Pattern.compile("\\$\\{controlLoopYaml\\}");
+ matcher = pattern.matcher(ruleContents);
+ ruleContents = matcher.replaceAll(controlLoopYaml);
+
+ return ruleContents;
+ }
+
+ /**
+ * Build the container.
+ *
+ * @param droolsTemplate template
+ * @param closedLoopControlName control loop id
+ * @param policyScope policy scope
+ * @param policyName policy name
+ * @param policyVersion policy version
+ * @param yamlSpecification incoming yaml specification
+ * @return the Kie session
+ * @throws IOException if the container cannot be built
+ */
+ public static KieSession buildContainer(String droolsTemplate, String closedLoopControlName,
+ String policyScope, String policyName, String policyVersion,
+ String yamlSpecification) throws IOException {
+ //
+ // Get our Drools Kie factory
+ //
KieServices ks = KieServices.Factory.get();
-
- KieModuleModel kModule = ks.newKieModuleModel();
-
- logger.debug("KMODULE:" + System.lineSeparator() + kModule.toXML());
-
+
+ KieModuleModel kieModule = ks.newKieModuleModel();
+
+ logger.debug("KMODULE:" + System.lineSeparator() + kieModule.toXML());
+
//
// Generate our drools rule from our template
//
KieFileSystem kfs = ks.newKieFileSystem();
-
- kfs.writeKModuleXML(kModule.toXML());
+
+ kfs.writeKModuleXML(kieModule.toXML());
{
- Path rule = Paths.get(droolsTemplate);
- String ruleTemplate = new String(Files.readAllBytes(rule));
- String drlContents = generatePolicy(ruleTemplate,
- closedLoopControlName,
- policyScope,
- policyName,
- policyVersion,
- yamlSpecification);
-
- kfs.write("src/main/resources/" + policyName + ".drl", ks.getResources().newByteArrayResource(drlContents.getBytes()));
+ Path rule = Paths.get(droolsTemplate);
+ String ruleTemplate = new String(Files.readAllBytes(rule));
+ String drlContents = generatePolicy(ruleTemplate,
+ closedLoopControlName,
+ policyScope,
+ policyName,
+ policyVersion,
+ yamlSpecification);
+
+ kfs.write("src/main/resources/" + policyName + ".drl",
+ ks.getResources().newByteArrayResource(drlContents.getBytes()));
}
//
// Compile the rule
KieBuilder builder = ks.newKieBuilder(kfs).buildAll();
Results results = builder.getResults();
if (results.hasMessages(Message.Level.ERROR)) {
- for (Message msg : results.getMessages()) {
- logger.error(msg.toString());
- }
- throw new RuntimeException("Drools Rule has Errors");
+ for (Message msg : results.getMessages()) {
+ logger.error(msg.toString());
+ }
+ throw new RuntimeException("Drools Rule has Errors");
+ }
+ for (Message msg : results.getMessages()) {
+ logger.debug(msg.toString());
}
- for (Message msg : results.getMessages()) {
- logger.debug(msg.toString());
- }
- //
- // Create our kie Session and container
- //
+ //
+ // Create our kie Session and container
+ //
ReleaseId releaseId = ks.getRepository().getDefaultReleaseId();
logger.debug(releaseId.toString());
- KieContainer kContainer = ks.newKieContainer(releaseId);
-
- return setupSession(kContainer.newKieSession());
- }
-
- private static KieSession setupSession (KieSession kieSession) {
-
-
- //
- // Create XACML Guard policy from YAML
- // We prepare 4 Guards. Notice that Rebuilds recipe has two Guards (for checking policy combining algorithm)
- //
- PolicyGuardYamlToXacml.fromYamlToXacml("src/test/resources/yaml/policy_guard_appc_restart.yaml",
- "src/main/resources/frequency_limiter_template.xml",
- "src/test/resources/xacml/autogenerated_frequency_limiter_restart.xml");
-
- PolicyGuardYamlToXacml.fromYamlToXacml("src/test/resources/yaml/policy_guard_appc_rebuild.yaml",
- "src/main/resources/frequency_limiter_template.xml",
- "src/test/resources/xacml/autogenerated_frequency_limiter_rebuild.xml");
-
- PolicyGuardYamlToXacml.fromYamlToXacml("src/test/resources/yaml/policy_guard_appc_rebuild_1.yaml",
- "src/main/resources/frequency_limiter_template.xml",
- "src/test/resources/xacml/autogenerated_frequency_limiter_rebuild_1.xml");
-
- PolicyGuardYamlToXacml.fromYamlToXacml("src/test/resources/yaml/policy_guard_appc_migrate.yaml",
- "src/main/resources/frequency_limiter_template.xml",
- "src/test/resources/xacml/autogenerated_frequency_limiter_migrate.xml");
-
- PolicyGuardYamlToXacml.fromYamlToXacml("src/test/resources/yaml/policy_guard_appc_modifyconfig.yaml",
+ KieContainer keyContainer = ks.newKieContainer(releaseId);
+
+ return setupSession(keyContainer.newKieSession());
+ }
+
+ private static KieSession setupSession(KieSession kieSession) {
+
+
+ //
+ // Create XACML Guard policy from YAML
+ // We prepare 4 Guards. Notice that Rebuilds recipe has two Guards (for checking policy combining algorithm)
+ //
+ PolicyGuardYamlToXacml.fromYamlToXacml("src/test/resources/yaml/policy_guard_appc_restart.yaml",
+ "src/main/resources/frequency_limiter_template.xml",
+ "src/test/resources/xacml/autogenerated_frequency_limiter_restart.xml");
+
+ PolicyGuardYamlToXacml.fromYamlToXacml("src/test/resources/yaml/policy_guard_appc_rebuild.yaml",
+ "src/main/resources/frequency_limiter_template.xml",
+ "src/test/resources/xacml/autogenerated_frequency_limiter_rebuild.xml");
+
+ PolicyGuardYamlToXacml.fromYamlToXacml("src/test/resources/yaml/policy_guard_appc_rebuild_1.yaml",
+ "src/main/resources/frequency_limiter_template.xml",
+ "src/test/resources/xacml/autogenerated_frequency_limiter_rebuild_1.xml");
+
+ PolicyGuardYamlToXacml.fromYamlToXacml("src/test/resources/yaml/policy_guard_appc_migrate.yaml",
+ "src/main/resources/frequency_limiter_template.xml",
+ "src/test/resources/xacml/autogenerated_frequency_limiter_migrate.xml");
+
+ PolicyGuardYamlToXacml.fromYamlToXacml("src/test/resources/yaml/policy_guard_appc_modifyconfig.yaml",
"src/main/resources/frequency_limiter_template.xml",
"src/test/resources/xacml/autogenerated_frequency_limiter_modifyconfig.xml");
-
- PolicyGuardYamlToXacml.fromYamlToXacmlBlacklist("src/test/resources/yaml/policy_guard_appc_restart_blacklist.yaml",
- "src/main/resources/blacklist_template.xml",
- "src/test/resources/xacml/autogenerated_blacklist.xml");
-
- //
- // Creating an embedded XACML PDP
- //
- System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, "src/test/resources/xacml/xacml_guard.properties");
-
- return kieSession;
- }
-
- public static void setAAIProps(){
- PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666");
+
+ PolicyGuardYamlToXacml.fromYamlToXacmlBlacklist(
+ "src/test/resources/yaml/policy_guard_appc_restart_blacklist.yaml",
+ "src/main/resources/blacklist_template.xml",
+ "src/test/resources/xacml/autogenerated_blacklist.xml");
+
+ //
+ // Creating an embedded XACML PDP
+ //
+ System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, "src/test/resources/xacml/xacml_guard.properties");
+
+ return kieSession;
+ }
+
+ /**
+ * Set the A&AI properties.
+ */
+ public static void setAaiProps() {
+ PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666");
PolicyEngine.manager.setEnvironmentProperty("aai.username", "AAI");
PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI");
- }
-
- public static void setSOProps(){
- PolicyEngine.manager.setEnvironmentProperty("so.url", "http://localhost:6667");
+ }
+
+ /**
+ * Set the SO properties.
+ */
+ public static void setSoProps() {
+ PolicyEngine.manager.setEnvironmentProperty("so.url", "http://localhost:6667");
PolicyEngine.manager.setEnvironmentProperty("so.username", "SO");
PolicyEngine.manager.setEnvironmentProperty("so.password", "SO");
- }
-
- public static void setGuardProps(){
- /*
- * Guard PDP-x connection Properties
- */
- PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_URL, "http://localhost:6669/pdp/api/getDecision");
- PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_USER, "python");
- PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_PASS, "test");
- PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_CLIENT_USER, "python");
- PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_CLIENT_PASS, "test");
- PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_ENV, "TEST");
- PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_DISABLED, "false");
}
-
- public static void setVFCProps() {
- PolicyEngine.manager.setEnvironmentProperty("vfc.url", "http://localhost:6668");
+
+ /**
+ * Set the Guard properties.
+ */
+ public static void setGuardProps() {
+ /*
+ * Guard PDP-x connection Properties
+ */
+ PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_URL, "http://localhost:6669/pdp/api/getDecision");
+ PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_USER, "python");
+ PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_PASS, "test");
+ PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_CLIENT_USER, "python");
+ PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_CLIENT_PASS, "test");
+ PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_ENV, "TEST");
+ PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_DISABLED, "false");
+ }
+
+ /**
+ * Set the VFC properties.
+ */
+ public static void setVfcProps() {
+ PolicyEngine.manager.setEnvironmentProperty("vfc.url", "http://localhost:6668");
PolicyEngine.manager.setEnvironmentProperty("vfc.username", "VFC");
PolicyEngine.manager.setEnvironmentProperty("vfc.password", "VFC");
- }
- public static void setPUProp(){
- System.setProperty(OPSHISTPUPROP, "TestOperationsHistoryPU");
- }
+ }
+
+ /**
+ * Set the operation history properties.
+ */
+ public static void setPuProp() {
+ System.setProperty(OPSHISTPUPROP, "TestOperationsHistoryPU");
+ }
}
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class VCPEControlLoopTest implements TopicListener {
+public class VcpeControlLoopTest implements TopicListener {
- private static final Logger logger = LoggerFactory.getLogger(VCPEControlLoopTest.class);
+ private static final Logger logger = LoggerFactory.getLogger(VcpeControlLoopTest.class);
private static List<? extends TopicSink> noopTopics;
private static KieSession kieSession;
private static Util.Pair<ControlLoopPolicy, String> pair;
- private UUID requestID;
+ private UUID requestId;
static {
/* Set environment properties */
- Util.setAAIProps();
+ Util.setAaiProps();
Util.setGuardProps();
- Util.setPUProp();
+ Util.setPuProp();
LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, "INFO");
}
+ /**
+ * Setup the simulator.
+ */
@BeforeClass
public static void setUpSimulator() {
PolicyEngine.manager.configure(new Properties());
*/
try {
kieSession = startSession(
- "../archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl",
+ "../archetype-cl-amsterdam/src/main/resources/archetype-resources"
+ + "/src/main/resources/__closedLoopControlName__.drl",
"src/test/resources/yaml/policy_ControlLoop_vCPE.yaml",
"service=ServiceDemo;resource=Res1Demo;type=operational", "CL_vCPE",
"org.onap.closed_loop.ServiceDemo:VNFS:1.0.0");
}
}
+ /**
+ * Tear down the simulator.
+ */
@AfterClass
public static void tearDownSimulator() {
/*
/*
* Create a unique requestId
*/
- requestID = UUID.randomUUID();
+ requestId = UUID.randomUUID();
/*
* Simulate an onset event the policy engine will receive from DCAE to kick off processing
* through the rules
*/
- sendEvent(pair.a, requestID, ControlLoopEventStatus.ONSET, "vCPEInfraVNF13", true);
+ sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET, "vCPEInfraVNF13", true);
kieSession.fireUntilHalt();
/*
* Create a unique requestId
*/
- requestID = UUID.randomUUID();
+ requestId = UUID.randomUUID();
/*
* Simulate an onset event the policy engine will receive from DCAE to kick off processing
* through the rules
*/
- sendEvent(pair.a, requestID, ControlLoopEventStatus.ONSET, "getFail", false);
+ sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET, "getFail", false);
kieSession.fireUntilHalt();
* @param policyName name of the policy
* @param policyVersion version of the policy
* @return the kieSession to be used to insert facts
- * @throws IOException
+ * @throws IOException IO exception
*/
private static KieSession startSession(String droolsTemplate, String yamlFile, String policyScope,
String policyName, String policyVersion) throws IOException {
*/
pair = Util.loadYaml(yamlFile);
assertNotNull(pair);
- assertNotNull(pair.a);
- assertNotNull(pair.a.getControlLoop());
- assertNotNull(pair.a.getControlLoop().getControlLoopName());
- assertTrue(pair.a.getControlLoop().getControlLoopName().length() > 0);
+ assertNotNull(pair.first);
+ assertNotNull(pair.first.getControlLoop());
+ assertNotNull(pair.first.getControlLoop().getControlLoopName());
+ assertTrue(pair.first.getControlLoop().getControlLoopName().length() > 0);
/*
* Construct a kie session
*/
- final KieSession kieSession = Util.buildContainer(droolsTemplate, pair.a.getControlLoop().getControlLoopName(),
- policyScope, policyName, policyVersion, URLEncoder.encode(pair.b, "UTF-8"));
+ final KieSession kieSession = Util.buildContainer(droolsTemplate,
+ pair.first.getControlLoop().getControlLoopName(),
+ policyScope, policyName, policyVersion, URLEncoder.encode(pair.second, "UTF-8"));
/*
* Retrieve the Policy Engine
*/
logger.debug("============");
- logger.debug(URLEncoder.encode(pair.b, "UTF-8"));
+ logger.debug(URLEncoder.encode(pair.second, "UTF-8"));
logger.debug("============");
return kieSession;
assertTrue(ControlLoopNotificationType.OPERATION_SUCCESS.equals(notification.getNotification()));
assertNotNull(notification.getMessage());
assertTrue(notification.getMessage().startsWith("actor=APPC"));
- sendEvent(pair.a, requestID, ControlLoopEventStatus.ABATED);
+ sendEvent(pair.first, requestId, ControlLoopEventStatus.ABATED);
} else if (policyName.endsWith("EVENT.MANAGER")) {
logger.debug("Rule Fired: " + notification.getPolicyName());
if ("getFail".equals(notification.getAai().get("generic-vnf.vnf-name"))) {
* @param requestID the requestId for this event
* @param status could be onset or abated
*/
- protected void sendEvent(ControlLoopPolicy policy, UUID requestID, ControlLoopEventStatus status) {
+ protected void sendEvent(ControlLoopPolicy policy, UUID requestId, ControlLoopEventStatus status) {
VirtualControlLoopEvent event = new VirtualControlLoopEvent();
event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName());
- event.setRequestId(requestID);
+ event.setRequestId(requestId);
event.setTarget("generic-vnf.vnf-name");
event.setClosedLoopAlarmStart(Instant.now());
event.setAai(new HashMap<>());
kieSession.insert(event);
}
- protected void sendEvent(ControlLoopPolicy policy, UUID requestID, ControlLoopEventStatus status, String vnfName,
+ protected void sendEvent(ControlLoopPolicy policy, UUID requestId, ControlLoopEventStatus status, String vnfName,
boolean isEnriched) {
VirtualControlLoopEvent event = new VirtualControlLoopEvent();
event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName());
- event.setRequestId(requestID);
+ event.setRequestId(requestId);
event.setTarget("generic-vnf.vnf-name");
event.setTargetType(ControlLoopTargetType.VNF);
event.setClosedLoopAlarmStart(Instant.now());
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class VDNSControlLoopTest implements TopicListener {
+public class VdnsControlLoopTest implements TopicListener {
- private static final Logger logger = LoggerFactory.getLogger(VDNSControlLoopTest.class);
+ private static final Logger logger = LoggerFactory.getLogger(VdnsControlLoopTest.class);
private static List<? extends TopicSink> noopTopics;
private static KieSession kieSession;
private static Util.Pair<ControlLoopPolicy, String> pair;
- private UUID requestID;
+ private UUID requestId;
static {
/* Set environment properties */
- Util.setAAIProps();
- Util.setSOProps();
+ Util.setAaiProps();
+ Util.setSoProps();
Util.setGuardProps();
- Util.setPUProp();
+ Util.setPuProp();
LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, "INFO");
}
+ /**
+ * Setup the simulator.
+ */
@BeforeClass
public static void setUpSimulator() {
PolicyEngine.manager.configure(new Properties());
*/
try {
kieSession = startSession(
- "../archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl",
+ "../archetype-cl-amsterdam/src/main/resources/archetype-resources/"
+ + "src/main/resources/__closedLoopControlName__.drl",
"src/test/resources/yaml/policy_ControlLoop_SO-test.yaml", "type=operational", "CL_vDNS", "v2.0");
} catch (IOException e) {
e.printStackTrace();
}
}
+ /**
+ * Tear down the simulator.
+ */
@AfterClass
public static void tearDownSimulator() {
/*
* Create a unique requestId
*/
- requestID = UUID.randomUUID();
+ requestId = UUID.randomUUID();
/*
* Simulate an onset event the policy engine will receive from DCAE to kick off processing
* through the rules
*/
- sendEvent(pair.a, requestID, ControlLoopEventStatus.ONSET);
+ sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET);
kieSession.fireUntilHalt();
/*
* Create a unique requestId
*/
- requestID = UUID.randomUUID();
+ requestId = UUID.randomUUID();
/*
* Simulate an onset event the policy engine will receive from DCAE to kick off processing
* through the rules
*/
- sendEvent(pair.a, requestID, ControlLoopEventStatus.ONSET, "error");
+ sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET, "error");
kieSession.fireUntilHalt();
/*
* Create a unique requestId
*/
- requestID = UUID.randomUUID();
+ requestId = UUID.randomUUID();
/*
* Simulate an onset event the policy engine will receive from DCAE to kick off processing
* through the rules
*/
- sendEvent(pair.a, requestID, ControlLoopEventStatus.ONSET, "getFail");
+ sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET, "getFail");
try {
kieSession.fireUntilHalt();
* @param policyName name of the policy
* @param policyVersion version of the policy
* @return the kieSession to be used to insert facts
- * @throws IOException
+ * @throws IOException IO Exception
*/
private static KieSession startSession(String droolsTemplate, String yamlFile, String policyScope,
String policyName, String policyVersion) throws IOException {
*/
pair = Util.loadYaml(yamlFile);
assertNotNull(pair);
- assertNotNull(pair.a);
- assertNotNull(pair.a.getControlLoop());
- assertNotNull(pair.a.getControlLoop().getControlLoopName());
- assertTrue(pair.a.getControlLoop().getControlLoopName().length() > 0);
+ assertNotNull(pair.first);
+ assertNotNull(pair.first.getControlLoop());
+ assertNotNull(pair.first.getControlLoop().getControlLoopName());
+ assertTrue(pair.first.getControlLoop().getControlLoopName().length() > 0);
/*
* Construct a kie session
*/
- final KieSession kieSession = Util.buildContainer(droolsTemplate, pair.a.getControlLoop().getControlLoopName(),
- policyScope, policyName, policyVersion, URLEncoder.encode(pair.b, "UTF-8"));
+ final KieSession kieSession = Util.buildContainer(droolsTemplate,
+ pair.first.getControlLoop().getControlLoopName(),
+ policyScope, policyName, policyVersion, URLEncoder.encode(pair.second, "UTF-8"));
/*
* Retrieve the Policy Engine
*/
logger.debug("============");
- logger.debug(URLEncoder.encode(pair.b, "UTF-8"));
+ logger.debug(URLEncoder.encode(pair.second, "UTF-8"));
logger.debug("============");
return kieSession;
* @param requestID the requestId for this event
* @param status could be onset or abated
*/
- protected void sendEvent(ControlLoopPolicy policy, UUID requestID, ControlLoopEventStatus status) {
+ protected void sendEvent(ControlLoopPolicy policy, UUID requestId, ControlLoopEventStatus status) {
VirtualControlLoopEvent event = new VirtualControlLoopEvent();
event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName());
- event.setRequestId(requestID);
+ event.setRequestId(requestId);
event.setTarget("vserver.vserver-name");
event.setClosedLoopAlarmStart(Instant.now());
event.setAai(new HashMap<>());
kieSession.insert(event);
}
- protected void sendEvent(ControlLoopPolicy policy, UUID requestID, ControlLoopEventStatus status,
+ protected void sendEvent(ControlLoopPolicy policy, UUID requestId, ControlLoopEventStatus status,
String vserverName) {
VirtualControlLoopEvent event = new VirtualControlLoopEvent();
event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName());
- event.setRequestId(requestID);
+ event.setRequestId(requestId);
event.setTarget("vserver.vserver-name");
event.setClosedLoopAlarmStart(Instant.now());
event.setAai(new HashMap<>());
* demo
* ================================================================================
* 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.
import org.slf4j.LoggerFactory;
-public class VFCControlLoopTest implements TopicListener {
+public class VfcControlLoopTest implements TopicListener {
- private static final Logger logger = LoggerFactory.getLogger(VFCControlLoopTest.class);
+ private static final Logger logger = LoggerFactory.getLogger(VfcControlLoopTest.class);
private static List<? extends TopicSink> noopTopics;
private static KieSession kieSession;
private static Util.Pair<ControlLoopPolicy, String> pair;
- private UUID requestID;
+ private UUID requestId;
static {
/* Set environment properties */
- Util.setAAIProps();
- Util.setVFCProps();
+ Util.setAaiProps();
+ Util.setVfcProps();
Util.setGuardProps();
- Util.setPUProp();
+ Util.setPuProp();
LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, "INFO");
}
+ /**
+ * Setup the simulator.
+ */
@BeforeClass
public static void setUpSimulator() {
PolicyEngine.manager.configure(new Properties());
*/
try {
kieSession = startSession(
- "../archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl",
+ "../archetype-cl-amsterdam/src/main/resources/archetype-resources/"
+ + "src/main/resources/__closedLoopControlName__.drl",
"src/test/resources/yaml/policy_ControlLoop_VFC.yaml", "type=operational", "CL_VoLTE", "v2.0");
} catch (IOException e) {
e.printStackTrace();
}
}
+ /**
+ * Tear down the simulator.
+ */
@AfterClass
public static void tearDownSimulator() {
/*
* Create a unique requestId
*/
- requestID = UUID.randomUUID();
+ requestId = UUID.randomUUID();
/*
* Simulate an onset event the policy engine will receive from DCAE to kick off processing
* through the rules
*/
- sendEvent(pair.a, requestID, ControlLoopEventStatus.ONSET);
+ sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET);
kieSession.fireUntilHalt();
/*
* Create a unique requestId
*/
- requestID = UUID.randomUUID();
+ requestId = UUID.randomUUID();
/*
* Simulate an onset event the policy engine will receive from DCAE to kick off processing
*/
VirtualControlLoopEvent event = new VirtualControlLoopEvent();
- event.setClosedLoopControlName(pair.a.getControlLoop().getControlLoopName());
+ event.setClosedLoopControlName(pair.first.getControlLoop().getControlLoopName());
event.setRequestId(UUID.randomUUID());
event.setClosedLoopEventClient("tca.instance00009");
event.setTargetType(ControlLoopTargetType.VM);
* @param policyName name of the policy
* @param policyVersion version of the policy
* @return the kieSession to be used to insert facts
- * @throws IOException
+ * @throws IOException IO Exception
*/
private static KieSession startSession(String droolsTemplate, String yamlFile, String policyScope,
String policyName, String policyVersion) throws IOException {
*/
pair = Util.loadYaml(yamlFile);
assertNotNull(pair);
- assertNotNull(pair.a);
- assertNotNull(pair.a.getControlLoop());
- assertNotNull(pair.a.getControlLoop().getControlLoopName());
- assertTrue(pair.a.getControlLoop().getControlLoopName().length() > 0);
+ assertNotNull(pair.first);
+ assertNotNull(pair.first.getControlLoop());
+ assertNotNull(pair.first.getControlLoop().getControlLoopName());
+ assertTrue(pair.first.getControlLoop().getControlLoopName().length() > 0);
/*
* Construct a kie session
*/
- final KieSession kieSession = Util.buildContainer(droolsTemplate, pair.a.getControlLoop().getControlLoopName(),
- policyScope, policyName, policyVersion, URLEncoder.encode(pair.b, "UTF-8"));
+ final KieSession kieSession = Util.buildContainer(droolsTemplate,
+ pair.first.getControlLoop().getControlLoopName(),
+ policyScope, policyName, policyVersion, URLEncoder.encode(pair.second, "UTF-8"));
/*
* Retrieve the Policy Engine
*/
logger.debug("============");
- logger.debug(URLEncoder.encode(pair.b, "UTF-8"));
+ logger.debug(URLEncoder.encode(pair.second, "UTF-8"));
logger.debug("============");
return kieSession;
* @param requestID the requestId for this event
* @param status could be onset or abated
*/
- protected void sendEvent(ControlLoopPolicy policy, UUID requestID, ControlLoopEventStatus status) {
+ protected void sendEvent(ControlLoopPolicy policy, UUID requestId, ControlLoopEventStatus status) {
VirtualControlLoopEvent event = new VirtualControlLoopEvent();
event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName());
event.setRequestId(UUID.randomUUID());
kieSession.insert(event);
}
+ /**
+ * Dumps the kie session facts.
+ *
+ * @param kieSession input session
+ */
public static void dumpFacts(KieSession kieSession) {
logger.debug("Fact Count: " + kieSession.getFactCount());
for (FactHandle handle : kieSession.getFactHandles()) {
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class VFWControlLoopTest implements TopicListener {
+public class VfwControlLoopTest implements TopicListener {
- private static final Logger logger = LoggerFactory.getLogger(VFWControlLoopTest.class);
+ private static final Logger logger = LoggerFactory.getLogger(VfwControlLoopTest.class);
private static List<? extends TopicSink> noopTopics;
private static KieSession kieSession;
private static Util.Pair<ControlLoopPolicy, String> pair;
- private UUID requestID;
+ private UUID requestId;
static {
/* Set environment properties */
- Util.setAAIProps();
+ Util.setAaiProps();
Util.setGuardProps();
- Util.setPUProp();
+ Util.setPuProp();
LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, "INFO");
}
+ /**
+ * Setup the simulator.
+ */
@BeforeClass
public static void setUpSimulator() {
PolicyEngine.manager.configure(new Properties());
*/
try {
kieSession = startSession(
- "../archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl",
+ "../archetype-cl-amsterdam/src/main/resources/archetype-resources/src/"
+ + "main/resources/__closedLoopControlName__.drl",
"src/test/resources/yaml/policy_ControlLoop_vFW.yaml",
"service=ServiceDemo;resource=Res1Demo;type=operational", "CL_vFW",
"org.onap.closed_loop.ServiceDemo:VNFS:1.0.0");
}
}
+ /**
+ * Tear down the simulator.
+ */
@AfterClass
public static void tearDownSimulator() {
/*
/*
* Create a unique requestId
*/
- requestID = UUID.randomUUID();
+ requestId = UUID.randomUUID();
/*
* Simulate an onset event the policy engine will receive from DCAE to kick off processing
* through the rules
*/
- sendEvent(pair.a, requestID, ControlLoopEventStatus.ONSET);
+ sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET);
try {
kieSession.fireUntilHalt();
/*
* Create a unique requestId
*/
- requestID = UUID.randomUUID();
+ requestId = UUID.randomUUID();
/*
* Simulate an onset event the policy engine will receive from DCAE to kick off processing
* through the rules
*/
- sendEvent(pair.a, requestID, ControlLoopEventStatus.ONSET, "error");
+ sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET, "error");
try {
kieSession.fireUntilHalt();
} catch (Exception e) {
/*
* Create a unique requestId
*/
- requestID = UUID.randomUUID();
+ requestId = UUID.randomUUID();
/*
* Simulate an onset event the policy engine will receive from DCAE to kick off processing
* through the rules
*/
- sendEvent(pair.a, requestID, ControlLoopEventStatus.ONSET, "getFail");
+ sendEvent(pair.first, requestId, ControlLoopEventStatus.ONSET, "getFail");
try {
kieSession.fireUntilHalt();
* @param policyName name of the policy
* @param policyVersion version of the policy
* @return the kieSession to be used to insert facts
- * @throws IOException
+ * @throws IOException IO Exception
*/
private static KieSession startSession(String droolsTemplate, String yamlFile, String policyScope,
String policyName, String policyVersion) throws IOException {
*/
pair = Util.loadYaml(yamlFile);
assertNotNull(pair);
- assertNotNull(pair.a);
- assertNotNull(pair.a.getControlLoop());
- assertNotNull(pair.a.getControlLoop().getControlLoopName());
- assertTrue(pair.a.getControlLoop().getControlLoopName().length() > 0);
+ assertNotNull(pair.first);
+ assertNotNull(pair.first.getControlLoop());
+ assertNotNull(pair.first.getControlLoop().getControlLoopName());
+ assertTrue(pair.first.getControlLoop().getControlLoopName().length() > 0);
/*
* Construct a kie session
*/
- final KieSession kieSession = Util.buildContainer(droolsTemplate, pair.a.getControlLoop().getControlLoopName(),
- policyScope, policyName, policyVersion, URLEncoder.encode(pair.b, "UTF-8"));
+ final KieSession kieSession = Util.buildContainer(droolsTemplate,
+ pair.first.getControlLoop().getControlLoopName(),
+ policyScope, policyName, policyVersion, URLEncoder.encode(pair.second, "UTF-8"));
/*
* Retrieve the Policy Engine
*/
logger.debug("============");
- logger.debug(URLEncoder.encode(pair.b, "UTF-8"));
+ logger.debug(URLEncoder.encode(pair.second, "UTF-8"));
logger.debug("============");
return kieSession;
assertTrue(ControlLoopNotificationType.OPERATION_SUCCESS.equals(notification.getNotification()));
assertNotNull(notification.getMessage());
assertTrue(notification.getMessage().startsWith("actor=APPC"));
- sendEvent(pair.a, requestID, ControlLoopEventStatus.ABATED);
+ sendEvent(pair.first, requestId, ControlLoopEventStatus.ABATED);
} else if (policyName.endsWith("EVENT.MANAGER")) {
logger.debug("Rule Fired: " + notification.getPolicyName());
if ("error".equals(notification.getAai().get("generic-vnf.vnf-name"))) {
* @param requestID the requestId for this event
* @param status could be onset or abated
*/
- protected void sendEvent(ControlLoopPolicy policy, UUID requestID, ControlLoopEventStatus status) {
+ protected void sendEvent(ControlLoopPolicy policy, UUID requestId, ControlLoopEventStatus status) {
VirtualControlLoopEvent event = new VirtualControlLoopEvent();
event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName());
- event.setRequestId(requestID);
+ event.setRequestId(requestId);
event.setTarget("generic-vnf.vnf-name");
event.setClosedLoopAlarmStart(Instant.now());
event.setAai(new HashMap<>());
* @param requestID the requestId for this event
* @param status could be onset or abated
*/
- protected void sendEvent(ControlLoopPolicy policy, UUID requestID, ControlLoopEventStatus status, String vnfId) {
+ protected void sendEvent(ControlLoopPolicy policy, UUID requestId, ControlLoopEventStatus status, String vnfId) {
VirtualControlLoopEvent event = new VirtualControlLoopEvent();
event.setClosedLoopControlName(policy.getControlLoop().getControlLoopName());
- event.setRequestId(requestID);
+ event.setRequestId(requestId);
event.setTarget("generic-vnf.vnf-name");
event.setClosedLoopAlarmStart(Instant.now());
event.setAai(new HashMap<>());
============LICENSE_END=========================================================\r
-->\r
<persistence version="2.1"\r
- xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
- xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">\r
+ xmlns="http://xmlns.jcp.org/xml/ns/persistence"\r
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
+ xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">\r
\r
- <!-- In-mem DB for junit -->\r
- <persistence-unit name="TestOperationsHistoryPU"\r
- transaction-type="RESOURCE_LOCAL">\r
- <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>\r
- <class>org.onap.policy.controlloop.eventmanager.OperationsHistoryDbEntry</class>\r
- <properties>\r
- <property name="eclipselink.ddl-generation" value="create-tables" />\r
- <property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />\r
- <property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test" />\r
- <property name="javax.persistence.jdbc.user" value="sa" />\r
- <property name="javax.persistence.jdbc.password" value="" />\r
- <property name="eclipselink.logging.level" value="CONFIG" />\r
- </properties>\r
- </persistence-unit>\r
+ <!-- In-mem DB for junit -->\r
+ <persistence-unit name="TestOperationsHistoryPU"\r
+ transaction-type="RESOURCE_LOCAL">\r
+ <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>\r
+ <class>org.onap.policy.controlloop.eventmanager.OperationsHistoryDbEntry</class>\r
+ <properties>\r
+ <property name="eclipselink.ddl-generation"\r
+ value="create-tables" />\r
+ <property name="javax.persistence.jdbc.driver"\r
+ value="org.h2.Driver" />\r
+ <property name="javax.persistence.jdbc.url"\r
+ value="jdbc:h2:mem:test" />\r
+ <property name="javax.persistence.jdbc.user"\r
+ value="sa" />\r
+ <property name="javax.persistence.jdbc.password"\r
+ value="" />\r
+ <property name="eclipselink.logging.level"\r
+ value="CONFIG" />\r
+ </properties>\r
+ </persistence-unit>\r
\r
\r
</persistence>\r
</dependency>
</dependencies>
</plugin>
+ <plugin>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>onap-java-style</id>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ <phase>process-sources</phase>
+ <configuration>
+ <!-- Use Google Java Style Guide:
+ https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml
+ with minor changes -->
+ <configLocation>onap-checkstyle/onap-java-style.xml</configLocation>
+ <!-- <sourceDirectory> is needed so that checkstyle ignores the generated sources directory -->
+ <sourceDirectory>${project.build.sourceDirectory}/src/main/java</sourceDirectory>
+ <includeResources>true</includeResources>
+ <includeTestSourceDirectory>true</includeTestSourceDirectory>
+ <includeTestResources>true</includeTestResources>
+ <excludes>
+ </excludes>
+ <consoleOutput>true</consoleOutput>
+ <failOnViolation>true</failOnViolation>
+ <violationSeverity>warning</violationSeverity>
+ </configuration>
+ </execution>
+ </executions>
+ <dependencies>
+ <dependency>
+ <groupId>org.onap.oparent</groupId>
+ <artifactId>checkstyle</artifactId>
+ <version>${oparent.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+ </plugin>
</plugins>
<pluginManagement>
<plugins>