- Native Drools Controller Policy support.
- Move domain policies into the policy-domains project.
- Route legacy/compliant operational policies to one or
all controller supporting the policy's policy type.
- Enhancements to scripts to invoke commands external
to the container.
Issue-ID: POLICY-2388
Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Change-Id: Id41f04d10a28d2ea86bdd41334e499c28d0438ae
Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
dmaap.source.topics=POLICY-PDP-PAP
dmaap.sink.topics=POLICY-PDP-PAP
-dmaap.source.topics.POLICY-PDP-PAP.servers=${env:DMAAP_SERVERS}
-dmaap.source.topics.POLICY-PDP-PAP.effectiveTopic=${env:POLICY_PDP_PAP_TOPIC}
-dmaap.source.topics.POLICY-PDP-PAP.apiKey=${env:POLICY_PDP_PAP_API_KEY}
-dmaap.source.topics.POLICY-PDP-PAP.apiSecret=${env:POLICY_PDP_PAP_API_SECRET}
+dmaap.source.topics.POLICY-PDP-PAP.servers=${envd:DMAAP_SERVERS}
+dmaap.source.topics.POLICY-PDP-PAP.effectiveTopic=${envd:POLICY_PDP_PAP_TOPIC}
+dmaap.source.topics.POLICY-PDP-PAP.apiKey=${envd:POLICY_PDP_PAP_API_KEY}
+dmaap.source.topics.POLICY-PDP-PAP.apiSecret=${envd:POLICY_PDP_PAP_API_SECRET}
dmaap.source.topics.POLICY-PDP-PAP.https=true
-dmaap.sink.topics.POLICY-PDP-PAP.servers=${env:DMAAP_SERVERS}
-dmaap.sink.topics.POLICY-PDP-PAP.effectiveTopic=${env:POLICY_PDP_PAP_TOPIC}
-dmaap.sink.topics.POLICY-PDP-PAP.apiKey=${env:POLICY_PDP_PAP_API_KEY}
-dmaap.sink.topics.POLICY-PDP-PAP.apiSecret=${env:POLICY_PDP_PAP_API_SECRET}
+dmaap.sink.topics.POLICY-PDP-PAP.servers=${envd:DMAAP_SERVERS}
+dmaap.sink.topics.POLICY-PDP-PAP.effectiveTopic=${envd:POLICY_PDP_PAP_TOPIC}
+dmaap.sink.topics.POLICY-PDP-PAP.apiKey=${envd:POLICY_PDP_PAP_API_KEY}
+dmaap.sink.topics.POLICY-PDP-PAP.apiSecret=${envd:POLICY_PDP_PAP_API_SECRET}
dmaap.sink.topics.POLICY-PDP-PAP.https=true
this.policyTypesMap.put(
POLICY_TYPE_DROOLS_CONTROLLER,
- new PolicyTypeNativeController(this, POLICY_TYPE_DROOLS_CONTROLLER));
+ new PolicyTypeNativeDroolsController(this, POLICY_TYPE_DROOLS_CONTROLLER));
this.policyTypesMap.put(
POLICY_TYPE_DROOLS_NATIVE_RULES,
- new PolicyTypeRulesController(this, POLICY_TYPE_DROOLS_NATIVE_RULES));
+ new PolicyTypeNativeArtifactController(this, POLICY_TYPE_DROOLS_NATIVE_RULES));
}
@JsonIgnore
package org.onap.policy.drools.lifecycle;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Function;
import lombok.Getter;
-
+import org.apache.commons.lang3.StringUtils;
+import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.drools.domain.models.legacy.LegacyPolicy;
+import org.onap.policy.drools.domain.models.operational.OperationalPolicy;
import org.onap.policy.drools.system.PolicyController;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Policy Type Drools Controller that delegates to a corresponding
* PolicyController that supports this policy type.
*/
-@Getter
public class PolicyTypeDroolsController implements PolicyTypeController {
+ protected static final ToscaPolicyTypeIdentifier legacyType =
+ new ToscaPolicyTypeIdentifier("onap.policies.controlloop.Operational", "1.0.0");
+
+ protected static final ToscaPolicyTypeIdentifier compliantType =
+ new ToscaPolicyTypeIdentifier("onap.policies.controlloop.operational.common.Drools", "1.0.0");
+
+ private static final Logger logger = LoggerFactory.getLogger(PolicyTypeController.class);
- protected final PolicyController controller;
+ protected final Map<String, PolicyController> controllers = new ConcurrentHashMap<>();
+
+ @Getter
protected final ToscaPolicyTypeIdentifier policyType;
- protected final LifecycleFsm fsm;
+
+ @GsonJsonIgnore
+ @JsonIgnore
+ protected final transient LifecycleFsm fsm;
/**
* Creates a Policy Type Drools Controller.
public PolicyTypeDroolsController(
LifecycleFsm fsm, ToscaPolicyTypeIdentifier policyType, PolicyController controller) {
this.policyType = policyType;
- this.controller = controller;
+ this.controllers.put(controller.getName(), controller);
this.fsm = fsm;
}
@Override
public boolean deploy(ToscaPolicy policy) {
- return fsm.getDomainMaker().isConformant(policy) && this.controller.offer(policy);
+ return perform(policy, (PolicyController controller) -> controller.offer(policy));
}
@Override
public boolean undeploy(ToscaPolicy policy) {
- return controller.getDrools().delete(policy);
+ return perform(policy, (PolicyController controller) -> controller.getDrools().delete(policy));
+ }
+
+ private boolean perform(ToscaPolicy policy, Function<PolicyController, Boolean> operation) {
+ try {
+ List<PolicyController> selected = selectControllers(policy);
+ boolean success = true;
+ for (PolicyController controller : selected) {
+ try {
+ success = operation.apply(controller) && success;
+ } catch (RuntimeException r) {
+ logger.warn("invalid offer to controller: {}", controller);
+ success = false;
+ }
+ }
+ return success && !selected.isEmpty();
+ } catch (CoderException e) {
+ logger.warn("perform: invalid formatted policy: {}", policy, e);
+ return false;
+ }
+ }
+
+ private List<PolicyController> selectControllers(ToscaPolicy policy) throws CoderException {
+ List<PolicyController> selected;
+ if (legacyType.equals(policyType)) {
+ selected = controllers(
+ fsm.getDomainMaker().convertTo(policy, LegacyPolicy.class)
+ .getProperties()
+ .getControllerName());
+ } else if (compliantType.equals(policyType)) {
+ selected = controllers(
+ fsm.getDomainMaker().convertTo(policy, OperationalPolicy.class)
+ .getProperties()
+ .getControllerName());
+ } else {
+ selected = List.copyOf(controllers.values());
+ }
+ return selected;
+ }
+
+ private List<PolicyController> controllers(String controllerName) {
+ if (StringUtils.isBlank(controllerName)) {
+ /* this policy applies to all controllers */
+ return controllers();
+ }
+
+ if (!this.controllers.containsKey(controllerName)) {
+ return List.of();
+ }
+
+ return List.of(this.controllers.get(controllerName));
+ }
+
+ /**
+ * Get all controllers that support the policy type.
+ */
+ public List<PolicyController> controllers() {
+ return List.copyOf(controllers.values());
}
}
import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.drools.controller.DroolsControllerConstants;
-import org.onap.policy.drools.domain.models.nativ.rules.NativeDroolsPolicy;
+import org.onap.policy.drools.domain.models.artifact.NativeArtifactPolicy;
import org.onap.policy.drools.protocol.configuration.DroolsConfiguration;
import org.onap.policy.drools.system.PolicyController;
import org.onap.policy.drools.system.PolicyControllerConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class PolicyTypeRulesController implements PolicyTypeController {
- private static final Logger logger = LoggerFactory.getLogger(PolicyTypeRulesController.class);
+public class PolicyTypeNativeArtifactController implements PolicyTypeController {
+ private static final Logger logger = LoggerFactory.getLogger(PolicyTypeNativeArtifactController.class);
@Getter
protected final ToscaPolicyTypeIdentifier policyType;
@GsonJsonIgnore
@JsonIgnore
- protected final LifecycleFsm fsm;
+ protected final transient LifecycleFsm fsm;
- public PolicyTypeRulesController(LifecycleFsm fsm, ToscaPolicyTypeIdentifier policyType) {
+ public PolicyTypeNativeArtifactController(LifecycleFsm fsm, ToscaPolicyTypeIdentifier policyType) {
this.policyType = policyType;
this.fsm = fsm;
}
@Override
public boolean deploy(ToscaPolicy policy) {
- NativeDroolsPolicy nativePolicy;
+ NativeArtifactPolicy nativePolicy;
PolicyController controller;
try {
- nativePolicy = fsm.getDomainMaker().convertTo(policy, NativeDroolsPolicy.class);
+ nativePolicy = fsm.getDomainMaker().convertTo(policy, NativeArtifactPolicy.class);
controller =
PolicyControllerConstants.getFactory().get(nativePolicy.getProperties().getController().getName());
} catch (CoderException e) {
public boolean undeploy(ToscaPolicy policy) {
PolicyController controller;
try {
- NativeDroolsPolicy nativePolicy = fsm.getDomainMaker().convertTo(policy, NativeDroolsPolicy.class);
+ NativeArtifactPolicy nativePolicy = fsm.getDomainMaker().convertTo(policy, NativeArtifactPolicy.class);
controller =
PolicyControllerConstants.getFactory().get(nativePolicy.getProperties().getController().getName());
} catch (RuntimeException | CoderException e) {
+++ /dev/null
-/*
- * ============LICENSE_START=======================================================
- * ONAP
- * ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.lifecycle;
-
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import lombok.Getter;
-import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
-import org.onap.policy.common.utils.coder.CoderException;
-import org.onap.policy.drools.domain.models.controller.ControllerPolicy;
-import org.onap.policy.drools.system.PolicyControllerConstants;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class PolicyTypeNativeController implements PolicyTypeController {
- private static final Logger logger = LoggerFactory.getLogger(PolicyTypeNativeController.class);
-
- @Getter
- protected final ToscaPolicyTypeIdentifier policyType;
-
- @GsonJsonIgnore
- @JsonIgnore
- protected final LifecycleFsm fsm;
-
- public PolicyTypeNativeController(LifecycleFsm fsm, ToscaPolicyTypeIdentifier policyType) {
- this.policyType = policyType;
- this.fsm = fsm;
- }
-
- @Override
- public boolean deploy(ToscaPolicy policy) {
- // TODO
- return fsm.getDomainMaker().isConformant(policy);
- }
-
- @Override
- public boolean undeploy(ToscaPolicy policy) {
- try {
- ControllerPolicy nativePolicy = fsm.getDomainMaker().convertTo(policy, ControllerPolicy.class);
- PolicyControllerConstants.getFactory().destroy(nativePolicy.getProperties().getControllerName());
- return true;
- } catch (RuntimeException | CoderException e) {
- logger.warn("failed undeploy of policy: {}", policy);
- return false;
- }
- }
-}
--- /dev/null
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.drools.lifecycle;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.stream.Collectors;
+import lombok.Getter;
+import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
+import org.onap.policy.common.endpoints.event.comm.TopicSink;
+import org.onap.policy.common.endpoints.event.comm.TopicSource;
+import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.drools.domain.models.controller.ControllerCustomSerialization;
+import org.onap.policy.drools.domain.models.controller.ControllerEvent;
+import org.onap.policy.drools.domain.models.controller.ControllerPolicy;
+import org.onap.policy.drools.domain.models.controller.ControllerProperties;
+import org.onap.policy.drools.domain.models.controller.ControllerSinkTopic;
+import org.onap.policy.drools.domain.models.controller.ControllerSourceTopic;
+import org.onap.policy.drools.properties.DroolsPropertyConstants;
+import org.onap.policy.drools.system.PolicyController;
+import org.onap.policy.drools.system.PolicyControllerConstants;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PolicyTypeNativeDroolsController implements PolicyTypeController {
+ private static final Logger logger = LoggerFactory.getLogger(PolicyTypeNativeDroolsController.class);
+
+ @Getter
+ protected final ToscaPolicyTypeIdentifier policyType;
+
+ @GsonJsonIgnore
+ @JsonIgnore
+ protected final transient LifecycleFsm fsm;
+
+ public PolicyTypeNativeDroolsController(LifecycleFsm fsm, ToscaPolicyTypeIdentifier policyType) {
+ this.policyType = policyType;
+ this.fsm = fsm;
+ }
+
+ @Override
+ public boolean deploy(ToscaPolicy policy) {
+ Properties controllerProps = new Properties();
+ ControllerPolicy controllerPolicy = toDomainPolicy(policy);
+ if (controllerPolicy == null) {
+ return false;
+ }
+
+ ControllerProperties controllerConfig = controllerPolicy.getProperties();
+
+ boolean success =
+ configControllerName(controllerConfig, controllerProps)
+ && configControllerSources(controllerConfig, controllerProps)
+ && configControllerSinks(controllerConfig, controllerProps)
+ && configControllerCustom(controllerConfig, controllerProps);
+
+ if (!success) {
+ return false;
+ }
+
+ PolicyController controller;
+ try {
+ controller =
+ PolicyControllerConstants.getFactory().build(
+ controllerConfig.getControllerName(), controllerProps);
+ } catch (RuntimeException e) {
+ logger.warn("failed deploy (cannot create controller) for policy: {}", policy);
+ return false;
+ }
+
+ return controller != null;
+ }
+
+ @Override
+ public boolean undeploy(ToscaPolicy policy) {
+ try {
+ ControllerPolicy nativePolicy = fsm.getDomainMaker().convertTo(policy, ControllerPolicy.class);
+ PolicyControllerConstants.getFactory()
+ .destroy(nativePolicy.getProperties().getControllerName());
+ return true;
+ } catch (RuntimeException | CoderException e) {
+ logger.warn("failed undeploy of policy: {}", policy);
+ return false;
+ }
+ }
+
+ private ControllerPolicy toDomainPolicy(ToscaPolicy policy) {
+ ControllerPolicy nativePolicy = null;
+ try {
+ nativePolicy = fsm.getDomainMaker().convertTo(policy, ControllerPolicy.class);
+ ControllerProperties config = nativePolicy.getProperties();
+
+ /* check for duplicates */
+
+ if (isDups(sourceTopics(config.getSourceTopics()))
+ || isDups(sinkTopics(config.getSinkTopics()))) {
+ logger.warn("there are duplicated topics in policy {}", policy);
+ return null;
+ }
+
+ /* check for non-existance of the controller - throws IAE if there's not */
+
+ PolicyControllerConstants.getFactory().get(nativePolicy.getProperties().getControllerName());
+
+ } catch (CoderException e) {
+ logger.warn("failed deploy of policy (invalid): {}", policy);
+ return null;
+ } catch (IllegalArgumentException e) {
+ // this is OK
+ logger.trace("proceeding with the deploy of native controller policy: {}", policy);
+ }
+
+ return nativePolicy;
+ }
+
+ private boolean configControllerName(ControllerProperties controllerConfig, Properties controllerProps) {
+ controllerProps
+ .setProperty(DroolsPropertyConstants.PROPERTY_CONTROLLER_NAME, controllerConfig.getControllerName());
+ return true;
+ }
+
+ private boolean configControllerSources(ControllerProperties controllerConfig, Properties controllerProps) {
+ for (ControllerSourceTopic configSourceTopic : controllerConfig.getSourceTopics()) {
+ List<TopicSource> sources =
+ TopicEndpointManager.getManager().getTopicSources(List.of(configSourceTopic.getTopicName()));
+ if (sources.size() != 1) {
+ logger.warn("Topic {} is not present or ambigous {}", configSourceTopic.getTopicName(), sources);
+ return false;
+ }
+
+ configSourceTopic(sources.get(0), configSourceTopic, controllerProps);
+ }
+ return true;
+ }
+
+ private void configSourceTopic(TopicSource topic, ControllerSourceTopic configTopic, Properties controllerProps) {
+ String configCommPrefix = topic.getTopicCommInfrastructure().name().toLowerCase() + ".source";
+ configTopic(configCommPrefix, topic.getTopic(), configTopic.getEvents(), controllerProps);
+ }
+
+ private boolean configControllerSinks(ControllerProperties controllerConfig, Properties controllerProps) {
+ for (ControllerSinkTopic configSinkTopic : controllerConfig.getSinkTopics()) {
+ List<TopicSink> sinks =
+ TopicEndpointManager.getManager().getTopicSinks(List.of(configSinkTopic.getTopicName()));
+ if (sinks.size() != 1) {
+ logger.warn("Topic {} is not present or ambigous {}", configSinkTopic.getTopicName(), sinks);
+ return false;
+ }
+
+ configSinkTopic(sinks.get(0), configSinkTopic, controllerProps);
+ }
+ return true;
+ }
+
+ private void configSinkTopic(TopicSink topic, ControllerSinkTopic configTopic, Properties controllerProps) {
+ String configCommPrefix = topic.getTopicCommInfrastructure().name().toLowerCase() + ".sink";
+ configTopic(configCommPrefix, topic.getTopic(), configTopic.getEvents(), controllerProps);
+ }
+
+ private void configTopic(
+ String configCommPrefix, String topicName, List<ControllerEvent> events, Properties controllerProps) {
+ String configTopicPrefix = configCommPrefix + "." + topicName;
+ configTopics(configCommPrefix, topicName, controllerProps);
+ for (ControllerEvent configEvent : events) {
+ configEvent(configTopicPrefix, configEvent, controllerProps);
+ }
+ }
+
+ private void configTopics(String propPrefix, String topicName, Properties controllerProps) {
+ String topicsPropKey = propPrefix + ".topics";
+ configTopicItemList(topicsPropKey, topicName, controllerProps);
+ }
+
+ private void configEvent(String propPrefix, ControllerEvent configEvent, Properties controllerProps) {
+ String eventPropPrefix = propPrefix + ".events";
+ controllerProps.setProperty(eventPropPrefix, configEvent.getEventClass());
+ if (configEvent.getEventFilter() != null) {
+ controllerProps.setProperty(
+ eventPropPrefix + "." + configEvent.getEventClass() + ".filter", configEvent.getEventFilter());
+ }
+ if (configEvent.getCustomSerialization() != null) {
+ configSerialization(eventPropPrefix, configEvent.getCustomSerialization(), controllerProps);
+ }
+ configTopicItemList(eventPropPrefix, configEvent.getEventClass(), controllerProps);
+ }
+
+ private void configTopicItemList(String itemPrefix, String item, Properties controllerProps) {
+ if (controllerProps.getProperty(itemPrefix) == null) {
+ controllerProps.setProperty(itemPrefix, item);
+ } else {
+ controllerProps.setProperty(itemPrefix, "," + item);
+ }
+ }
+
+ private void configSerialization(
+ String propPrefix, ControllerCustomSerialization configCustom, Properties controllerProps) {
+ String customPropPrefix = propPrefix + ".custom.gson";
+ controllerProps.setProperty(
+ customPropPrefix, configCustom.getCustomSerializerClass() + "," + configCustom.getJsonParser());
+ }
+
+ private boolean configControllerCustom(ControllerProperties controllerConfig, Properties controllerProps) {
+ Map<String, String> configCustom = controllerConfig.getCustomConfig();
+ if (configCustom == null || configCustom.isEmpty()) {
+ return true;
+ }
+
+ controllerProps.putAll(configCustom);
+ return true;
+ }
+
+ private <T> boolean isDups(List<T> items) {
+ return items.size() != items.stream().distinct().count();
+ }
+
+ private List<String> sourceTopics(List<ControllerSourceTopic> sourceTopics) {
+ return sourceTopics.stream()
+ .map(ControllerSourceTopic::getTopicName)
+ .collect(Collectors.toList());
+ }
+
+ private List<String> sinkTopics(List<ControllerSinkTopic> sourceTopics) {
+ return sourceTopics.stream()
+ .map(ControllerSinkTopic::getTopicName)
+ .collect(Collectors.toList());
+ }
+
+}
+++ /dev/null
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.domain.models;
-
-import static org.junit.Assert.assertNotNull;
-
-import com.openpojo.reflection.PojoClass;
-import com.openpojo.reflection.filters.FilterChain;
-import com.openpojo.reflection.filters.FilterClassName;
-import com.openpojo.reflection.filters.FilterNonConcrete;
-import com.openpojo.reflection.impl.PojoClassFactory;
-import com.openpojo.validation.Validator;
-import com.openpojo.validation.ValidatorBuilder;
-import com.openpojo.validation.test.impl.GetterTester;
-import com.openpojo.validation.test.impl.SetterTester;
-import java.util.ArrayList;
-import java.util.List;
-import org.junit.Test;
-import org.onap.policy.drools.domain.models.controller.ControllerPolicy;
-import org.onap.policy.drools.domain.models.controller.ControllerProperties;
-import org.onap.policy.drools.domain.models.nativ.rules.NativeDroolsController;
-import org.onap.policy.drools.domain.models.nativ.rules.NativeDroolsPolicy;
-import org.onap.policy.drools.domain.models.nativ.rules.NativeDroolsProperties;
-import org.onap.policy.drools.domain.models.nativ.rules.NativeDroolsRulesArtifact;
-
-public class DroolsPolicyModelsTest {
-
- @Test
- public void testPackage() {
- /* validate model pojos */
- List<PojoClass> pojoClasses =
- PojoClassFactory
- .getPojoClassesRecursively("org.onap.policy.drools.domain.models",
- new FilterChain(new FilterNonConcrete(),
- new FilterClassName(DroolsPolicy.class.getName())));
-
- Validator validator = ValidatorBuilder.create()
- .with(new SetterTester(), new GetterTester()).build();
- validator.validate(pojoClasses);
- }
-
- @Test
- public void testBuildDomainPolicyNativeDrools() {
- /* manually create a native drools policy */
- assertNotNull(NativeDroolsPolicy.builder().metadata(Metadata.builder().policyId("policy-id").build())
- .name("example")
- .type("onap.policies.native.Drools")
- .typeVersion("1.0.0")
- .version("1.0.0")
- .properties(
- NativeDroolsProperties.builder().controller(
- NativeDroolsController.builder().name("example").version("1.0.0").build())
- .rulesArtifact(
- NativeDroolsRulesArtifact.builder().groupId("org.onap.policy.controlloop")
- .artifactId("example").version("example").build()).build())
- .build());
- }
-
- @Test
- public void testBuildDomainPolicyController() {
- /* manually create a controller policy */
- assertNotNull(ControllerPolicy.builder().metadata(Metadata.builder().policyId("policy-id").build())
- .name("example")
- .version("1.0.0")
- .type("onap.policies.drools.Controller")
- .typeVersion("1.0.0")
- .properties(ControllerProperties.builder().controllerName("example").sourceTopics(
- new ArrayList<>()).sinkTopics(new ArrayList<>()).build())
- .build());
- }
-
-}
\ No newline at end of file
((PolicyTypeDroolsController) fsm.getController(
new ToscaPolicyTypeIdentifier(
ControllerSupport.POLICY_TYPE, ControllerSupport.POLICY_TYPE_VERSION)))
- .getController());
+ .controllers().get(0));
fsm.stop(controllerSupport.getController());
assertNull(fsm.getController(new ToscaPolicyTypeIdentifier(ControllerSupport.POLICY_TYPE,
--- /dev/null
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * =============LICENSE_END========================================================
+ */
+
+package org.onap.policy.drools.lifecycle;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.resources.ResourceUtils;
+import org.onap.policy.drools.domain.models.operational.OperationalPolicy;
+import org.onap.policy.drools.system.PolicyControllerConstants;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+
+/**
+ * Drools Controller Policy Test.
+ */
+public class PolicyTypeDroolsControllerTest extends LifecycleStateRunningTest {
+
+ // Operational vCPE Policies
+ private static final String OP_POLICY_NAME_VCPE = "operational.restart";
+ private static final String VCPE_OPERATIONAL_DROOLS_POLICY_JSON =
+ "policies/vCPE.policy.operational.input.tosca.json";
+
+ private ToscaPolicy policy;
+ private OperationalPolicy operationalPolicy;
+ private PolicyTypeDroolsController controller;
+
+ /**
+ * Test initialization.
+ */
+ @Before
+ public void init() throws CoderException {
+ fsm = makeFsmWithPseudoTime();
+ policy = getExamplesPolicy(VCPE_OPERATIONAL_DROOLS_POLICY_JSON, OP_POLICY_NAME_VCPE);
+ operationalPolicy = fsm.getDomainMaker().convertTo(policy, OperationalPolicy.class);
+ controller = new PolicyTypeDroolsController(
+ fsm, PolicyTypeDroolsController.compliantType, controllerSupport.getController());
+
+ assertTrue(controllerSupport.getController().getDrools().isBrained());
+ assertFalse(controllerSupport.getController().isAlive());
+ assertFalse(controllerSupport.getController().getDrools().isAlive());
+ assertSame(controllerSupport.getController(), PolicyControllerConstants.getFactory().get("lifecycle"));
+
+ /* start controller */
+ assertTrue(controllerSupport.getController().start());
+
+ assertTrue(controllerSupport.getController().isAlive());
+ assertTrue(controllerSupport.getController().getDrools().isAlive());
+ assertTrue(controllerSupport.getController().getDrools().isBrained());
+ assertSame(controllerSupport.getController(), PolicyControllerConstants.getFactory().get("lifecycle"));
+ }
+
+ @Test
+ public void testDeployUndeploy() {
+ /* non-existing controller */
+ assertFalse(controller.undeploy(policy));
+ assertFalse(controller.deploy(policy));
+
+ policy.getProperties().remove("controllerName");
+ assertTrue(controller.deploy(policy));
+ assertTrue(controller.undeploy(policy));
+ assertFalse(controller.undeploy(policy));
+
+ /* existing controller */
+ policy.getProperties().put("controllerName", "lifecycle");
+ assertTrue(controller.deploy(policy));
+ assertTrue(controller.undeploy(policy));
+ assertFalse(controller.undeploy(policy));
+ }
+
+ private ToscaPolicy getExamplesPolicy(String resourcePath, String policyName) throws CoderException {
+ String policyJson = ResourceUtils.getResourceAsString(resourcePath);
+ ToscaServiceTemplate serviceTemplate = new StandardCoder().decode(policyJson, ToscaServiceTemplate.class);
+ return serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyName);
+ }
+
+}
\ No newline at end of file
import org.onap.policy.drools.controller.DroolsControllerConstants;
import org.onap.policy.drools.controller.internal.MavenDroolsController;
import org.onap.policy.drools.controller.internal.NullDroolsController;
-import org.onap.policy.drools.domain.models.nativ.rules.NativeDroolsPolicy;
+import org.onap.policy.drools.domain.models.artifact.NativeArtifactPolicy;
import org.onap.policy.drools.system.PolicyControllerConstants;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
/**
* Rules Controller Test.
*/
-public class PolicyTypeRulesControllerTest extends LifecycleStateRunningTest {
+public class PolicyTypeNativeArtifactControllerTest extends LifecycleStateRunningTest {
// Native Drools Policy
private static final String EXAMPLE_NATIVE_DROOLS_POLICY_NAME = "example";
private static final String EXAMPLE_NATIVE_DROOLS_POLICY_JSON =
- "src/test/resources/example.policy.native.drools.tosca.json";
+ "src/test/resources/tosca-policy-native-artifact-example.json";
private ToscaPolicy policy;
- private NativeDroolsPolicy nativePolicy;
- private PolicyTypeRulesController controller;
+ private NativeArtifactPolicy nativePolicy;
+ private PolicyTypeNativeArtifactController controller;
/**
* Test Set initialization.
public void init() throws IOException, CoderException {
fsm = makeFsmWithPseudoTime();
policy = getPolicyFromFile(EXAMPLE_NATIVE_DROOLS_POLICY_JSON, EXAMPLE_NATIVE_DROOLS_POLICY_NAME);
- nativePolicy = fsm.getDomainMaker().convertTo(policy, NativeDroolsPolicy.class);
+ nativePolicy = fsm.getDomainMaker().convertTo(policy, NativeArtifactPolicy.class);
controller =
- new PolicyTypeRulesController(fsm,
- new ToscaPolicyTypeIdentifier("onap.policies.native.Drools", "1.0.0"));
+ new PolicyTypeNativeArtifactController(fsm,
+ new ToscaPolicyTypeIdentifier("onap.policies.native.drools.Artifact", "1.0.0"));
assertTrue(controllerSupport.getController().getDrools().isBrained());
assertFalse(controllerSupport.getController().isAlive());
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020 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.assertTrue;
import java.io.IOException;
+import java.util.Properties;
import org.junit.Before;
import org.junit.Test;
+import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
+import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.drools.domain.models.controller.ControllerPolicy;
import org.onap.policy.drools.system.PolicyControllerConstants;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
/**
* Native Controller Policy Test.
*/
-public class PolicyTypeNativeControllerTest extends LifecycleStateRunningTest {
+public class PolicyTypeNativeDroolsControllerTest extends LifecycleStateRunningTest {
// Native Drools Policy
private static final String EXAMPLE_NATIVE_DROOLS_POLICY_NAME = "example";
private static final String EXAMPLE_NATIVE_DROOLS_POLICY_JSON =
- "src/test/resources/example.policy.drools.controller.tosca.json";
+ "src/test/resources/tosca-policy-native-controller-example.json";
private ToscaPolicy policy;
private ControllerPolicy controllerPolicy;
- private PolicyTypeNativeController controller;
+ private PolicyTypeNativeDroolsController controller;
/**
* Test initialization.
fsm = makeFsmWithPseudoTime();
policy = getPolicyFromFile(EXAMPLE_NATIVE_DROOLS_POLICY_JSON, EXAMPLE_NATIVE_DROOLS_POLICY_NAME);
controllerPolicy = fsm.getDomainMaker().convertTo(policy, ControllerPolicy.class);
- controller =
- new PolicyTypeNativeController(fsm,
- new ToscaPolicyTypeIdentifier("onap.policies.drools.Controller", "1.0.0"));
+ controller = new PolicyTypeNativeDroolsController(fsm, policy.getTypeIdentifier());
assertTrue(controllerSupport.getController().getDrools().isBrained());
assertFalse(controllerSupport.getController().isAlive());
}
@Test
- public void testUndeploy() {
+ public void testUndeployDeploy() {
assertTrue(controller.undeploy(policy));
assertThatIllegalArgumentException().isThrownBy(
() -> PolicyControllerConstants.getFactory().get(controllerPolicy.getName()));
+
+ assertFalse(controller.deploy(policy));
+
+ Properties noopTopicProperties = new Properties();
+ noopTopicProperties.put(PolicyEndPointProperties.PROPERTY_NOOP_SOURCE_TOPICS, "DCAE_TOPIC");
+ noopTopicProperties.put(PolicyEndPointProperties.PROPERTY_NOOP_SINK_TOPICS, "APPC-CL");
+ TopicEndpointManager.getManager().addTopics(noopTopicProperties);
+
+ controller.deploy(policy);
+
+ return;
}
}
\ No newline at end of file
"policies": [
{
"example": {
- "type": "onap.policies.native.Drools",
+ "type": "onap.policies.native.drools.Artifact",
"type_version": "1.0.0",
"version": "1.0.0",
"name": "example",
"policies": [
{
"example": {
- "type": "onap.policies.drools.Controller",
+ "type": "onap.policies.native.drools.Controller",
"type_version": "1.0.0",
"version": "1.0.0",
"name": "example",
"sourceTopics": [
{
"topicName": "DCAE_TOPIC",
- "serialization": [
+ "events": [
{
"eventClass": "org.onap.policy.controlloop.CanonicalOnset",
"eventFilter": "[?($.closedLoopEventStatus == 'ONSET')]",
- "customSerializer": {
+ "customSerialization": {
"customSerializerClass": "org.onap.policy.controlloop.util.Serialization",
"jsonParser": "gson"
}
+ },
+ {
+ "eventClass": "org.onap.policy.controlloop.CanonicalAbated",
+ "eventFilter": "[?($.closedLoopEventStatus == 'ABATED')]"
}
]
}
"sinkTopics": [
{
"topicName": "APPC-CL",
- "serialization": [
+ "events": [
{
"eventClass": "org.onap.policy.appc.Response",
"eventFilter": "[?($.CommonHeader && $.Status)]",
- "customSerializer": {
+ "customSerialization": {
"customSerializerClass": "org.onap.policy.appc.util.Serialization",
"jsonParser": "gsonPretty"
}
# ============LICENSE_START=======================================================
# ONAP
# ================================================================================
-# Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2019-2020 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=========================================================
+source ${POLICY_HOME}/etc/profile.d/env.sh
+
if [[ ${DEBUG} == y ]]; then
set -x
fi
#!/bin/bash
-###
# ============LICENSE_START=======================================================
-# Base Package
+# ONAP
# ================================================================================
-# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============LICENSE_END=========================================================
-###
+
+source ${POLICY_HOME}/etc/profile.d/env.sh
function usage() {
echo -n "syntax: $(basename $0) "
#!/bin/bash
-###
# ============LICENSE_START=======================================================
-# Base Package
+# ONAP
# ================================================================================
-# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============LICENSE_END=========================================================
-###
+
+source ${POLICY_HOME}/etc/profile.d/env.sh
function usage() {
echo -n "syntax: $(basename $0) "
--- /dev/null
+config.stopBubbling = true
+lombok.addLombokGeneratedAnnotation = true
+lombok.nonNull.exceptionType = IllegalArgumentException
--- /dev/null
+<!--
+ ============LICENSE_START=======================================================
+ ONAP
+ ================================================================================
+ Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ ================================================================================
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ ============LICENSE_END=========================================================
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onap.policy.drools-pdp</groupId>
+ <artifactId>drools-pdp</artifactId>
+ <version>1.6.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>policy-domains</artifactId>
+
+ <name>policy-domains</name>
+ <description>domain policies</description>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito2</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.openpojo</groupId>
+ <artifactId>openpojo</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.onap.policy.common</groupId>
+ <artifactId>utils</artifactId>
+ <version>1.6.2-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.onap.policy.drools-pdp</groupId>
+ <artifactId>policy-utils</artifactId>
+ <version>1.6.0-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+</project>
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.drools.domain.models.nativ.rules;
+package org.onap.policy.drools.domain.models.artifact;
-import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
import lombok.Builder;
import lombok.Data;
@Data
@Builder
-public class NativeDroolsController implements Serializable {
+public class NativeArtifactController implements Serializable {
private static final long serialVersionUID = -2070515139072136869L;
- @SerializedName("name")
- protected String name;
-
- @SerializedName("version")
- protected String version;
+ private String name;
}
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.drools.domain.models.nativ.rules;
+package org.onap.policy.drools.domain.models.artifact;
-import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
import lombok.Data;
import lombok.experimental.SuperBuilder;
@Data
@SuperBuilder
-public class NativeDroolsPolicy extends DroolsPolicy implements Serializable {
+public class NativeArtifactPolicy extends DroolsPolicy implements Serializable {
private static final long serialVersionUID = -8171337852833516581L;
- @SerializedName("properties")
- protected NativeDroolsProperties properties;
+ private NativeArtifactProperties properties;
}
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.drools.domain.models.nativ.rules;
+package org.onap.policy.drools.domain.models.artifact;
-import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
import lombok.Builder;
import lombok.Data;
@Data
@Builder
-public class NativeDroolsProperties implements Serializable {
+public class NativeArtifactProperties implements Serializable {
private static final long serialVersionUID = 2360030332628276427L;
- @SerializedName("rulesArtifact")
- protected NativeDroolsRulesArtifact rulesArtifact;
-
- @SerializedName("controller")
- protected NativeDroolsController controller;
+ private NativeArtifactRulesArtifact rulesArtifact;
+ private NativeArtifactController controller;
}
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.drools.domain.models.nativ.rules;
+package org.onap.policy.drools.domain.models.artifact;
-import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
import lombok.Builder;
import lombok.Data;
@Data
@Builder
-public class NativeDroolsRulesArtifact implements Serializable {
+public class NativeArtifactRulesArtifact implements Serializable {
private static final long serialVersionUID = -3519759514319217518L;
- @SerializedName("groupId")
- protected String groupId;
-
- @SerializedName("artifactId")
- protected String artifactId;
-
- @SerializedName("version")
- protected String version;
+ private String groupId;
+ private String artifactId;
+ private String version;
}
package org.onap.policy.drools.domain.models.controller;
-import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
import lombok.Builder;
import lombok.Data;
@Data
@Builder
-public class ControllerCustomSerializer implements Serializable {
+public class ControllerCustomSerialization implements Serializable {
private static final long serialVersionUID = 1505345574249332514L;
- @SerializedName("customSerializerClass")
- protected String customSerializerClass;
-
- @SerializedName("jsonParser")
- protected String jsonParser;
+ private String customSerializerClass;
+ private String jsonParser;
}
package org.onap.policy.drools.domain.models.controller;
-import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
-import java.util.List;
import lombok.Builder;
import lombok.Data;
-/**
- * Sink Topic.
- */
-
@Data
@Builder
-public class ControllerSinkTopic implements Serializable {
+public class ControllerEvent implements Serializable {
private static final long serialVersionUID = 8770353732981476267L;
- @SerializedName("topicName")
- protected String topicName;
-
- @SerializedName("serialization")
- protected List<ControllerSerialization> serialization;
-
+ private String eventClass;
+ private String eventFilter;
+ private ControllerCustomSerialization customSerialization;
}
package org.onap.policy.drools.domain.models.controller;
-import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
import lombok.Data;
import lombok.experimental.SuperBuilder;
private static final long serialVersionUID = -8171337852833516581L;
- @SerializedName("properties")
- protected ControllerProperties properties;
+ private ControllerProperties properties;
}
package org.onap.policy.drools.domain.models.controller;
-import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
public class ControllerProperties implements Serializable {
private static final long serialVersionUID = 1259434187110418986L;
- @SerializedName("controllerName")
- protected String controllerName;
-
- @SerializedName("sourceTopics")
- protected List<ControllerSourceTopic> sourceTopics;
-
- @SerializedName("sinkTopics")
- protected List<ControllerSinkTopic> sinkTopics;
-
- @SerializedName("customConfig")
- protected Map<String, String> customConfig;
-
+ private String controllerName;
+ private List<ControllerSourceTopic> sourceTopics;
+ private List<ControllerSinkTopic> sinkTopics;
+ private Map<String, String> customConfig;
}
--- /dev/null
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.drools.domain.models.controller;
+
+import java.io.Serializable;
+import lombok.Data;
+import lombok.experimental.SuperBuilder;
+
+
+/**
+ * Sink Topic.
+ */
+
+@Data
+@SuperBuilder
+public class ControllerSinkTopic extends ControllerTopic implements Serializable {
+ private static final long serialVersionUID = 8770353732981476267L;
+}
package org.onap.policy.drools.domain.models.controller;
import java.io.Serializable;
-import java.util.List;
-import lombok.Builder;
import lombok.Data;
+import lombok.experimental.SuperBuilder;
/**
*/
@Data
-@Builder
-public class ControllerSourceTopic implements Serializable {
+@SuperBuilder
+public class ControllerSourceTopic extends ControllerTopic implements Serializable {
private static final long serialVersionUID = -1732598566914643612L;
-
- protected String topicName;
- protected List<ControllerSerialization> serialization;
}
--- /dev/null
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.drools.domain.models.controller;
+
+import java.util.List;
+import lombok.Data;
+import lombok.experimental.SuperBuilder;
+
+
+/**
+ * Source Topics.
+ */
+
+@Data
+@SuperBuilder
+public abstract class ControllerTopic {
+ protected String topicName;
+ protected List<ControllerEvent> events;
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.drools.domain.models.legacy;
+
+import java.io.Serializable;
+import lombok.Data;
+import lombok.experimental.SuperBuilder;
+import org.onap.policy.drools.domain.models.DroolsPolicy;
+
+
+/**
+ * Operational Domain Policy.
+ */
+
+@Data
+@SuperBuilder
+public class LegacyPolicy extends DroolsPolicy implements Serializable {
+ private static final long serialVersionUID = 4100092564657497713L;
+
+ private LegacyProperties properties;
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.drools.domain.models.legacy;
+
+import java.io.Serializable;
+import lombok.Builder;
+import lombok.Data;
+
+
+/**
+ * Legacy Operational Policy Properties.
+ */
+
+@Data
+@Builder
+public class LegacyProperties implements Serializable {
+ private static final long serialVersionUID = 2455300363502597721L;
+
+ /**
+ * Content (Operational Policy URL encoded yaml).
+ */
+ private String content;
+
+ /**
+ * Controller Name (optional) to select an specific controller among many that
+ * support a policy type.
+ */
+ private String controllerName;
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.drools.domain.models.operational;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import lombok.Builder;
+import lombok.Data;
+
+
+/**
+ * Actor Operation.
+ */
+
+@Data
+@Builder
+public class ActorOperation implements Serializable {
+ private static final long serialVersionUID = -534488831693359530L;
+
+ /**
+ * Actor.
+ */
+ private String actor;
+
+ /**
+ * Operation Name.
+ */
+ private String operation;
+
+ /**
+ * Target.
+ */
+ private OperationalTarget target;
+
+ /**
+ * Payload.
+ */
+ @Builder.Default
+ private Map<String, String> payload = new HashMap<>();
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.drools.domain.models.operational;
+
+import com.google.gson.annotations.SerializedName;
+import java.io.Serializable;
+import lombok.Builder;
+import lombok.Data;
+
+/**
+ * Policy Operation.
+ */
+
+@Data
+@Builder
+public class Operation implements Serializable {
+ private static final long serialVersionUID = 6175229119078195110L;
+
+ /**
+ * Operation Identifier.
+ */
+ private String id;
+
+ /**
+ * Description.
+ */
+ private String description;
+
+ /**
+ * Actor Operation.
+ */
+ @SerializedName("operation")
+ private ActorOperation actorOperation;
+
+ /**
+ * Operation Timeout in seconds.
+ */
+ @Builder.Default
+ private int timeout = 10;
+
+ /**
+ * Number of Retries.
+ */
+ @Builder.Default
+ private int retries = 0;
+
+ /**
+ * Success Treatment.
+ */
+ @Builder.Default
+ private String success = "final_success";
+
+ /**
+ * Failure Treatment.
+ */
+ @Builder.Default
+ private String failure = "final_failure";
+
+ /**
+ * Failure Timeout Treatment.
+ */
+ @SerializedName("failure_timeout")
+ @Builder.Default
+ private String failureTimeout = "final_failure_timeout";
+
+ /**
+ * Failure Retry Treatment.
+ */
+ @SerializedName("failure_retries")
+ @Builder.Default
+ private String failureRetries = "final_failure_retries";
+
+ /**
+ * Failure Exception Treatment.
+ */
+ @SerializedName("failure_exception")
+ @Builder.Default
+ private String failureException = "final_failure_exception";
+
+ /**
+ * Failure Guard Treatment.
+ */
+ @SerializedName("failure_guard")
+ @Builder.Default
+ private String failureGuard = "final_failure_guard";
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.drools.domain.models.operational;
+
+import java.io.Serializable;
+import lombok.Data;
+import lombok.experimental.SuperBuilder;
+import org.onap.policy.drools.domain.models.DroolsPolicy;
+
+
+/**
+ * Operational Domain Policy.
+ */
+
+@Data
+@SuperBuilder
+public class OperationalPolicy extends DroolsPolicy implements Serializable {
+ private static final long serialVersionUID = 4100092564657497713L;
+
+ private OperationalProperties properties;
+
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.drools.domain.models.operational;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+import lombok.Builder;
+import lombok.Data;
+
+
+/**
+ * Operational Policy Properties.
+ */
+
+@Data
+@Builder
+public class OperationalProperties implements Serializable {
+ private static final long serialVersionUID = 2455300363502597721L;
+
+ /**
+ * Control Loop Name.
+ */
+ private String id;
+
+ /**
+ * Timeout in seconds.
+ */
+ private int timeout = 30;
+
+ /**
+ * Abatement.
+ */
+ private boolean abatement = false;
+
+ /**
+ * Trigger Operation.
+ */
+ private String trigger;
+
+ /**
+ * Operations.
+ */
+ @Builder.Default
+ private List<Operation> operations = new ArrayList<>();
+
+ /**
+ * Controller Name.
+ */
+ private String controllerName;
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.drools.domain.models.operational;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import lombok.Builder;
+import lombok.Data;
+
+
+/**
+ * Operational Target.
+ */
+
+@Data
+@Builder
+public class OperationalTarget implements Serializable {
+ private static final long serialVersionUID = -3557887855401250181L;
+
+ /**
+ * Target Type.
+ */
+ private String targetType;
+
+ /**
+ * Payload.
+ */
+ @Builder.Default
+ private Map<String, String> entityIds = new HashMap<>();
+}
"controlLoop%3A%0A%20%20version%3A%202.0.0%0A%20%20controlLoopName%3A%20ControlLoop-vCPEv2-48f0c2c3-a172-4192-9ae3-052274181b6e%0A%20%20trigger_policy%3A%20unique-policy-id-1-restart%0A%20%20timeout%3A%203600%0A%20%20abatement%3A%20true%0A%20%0Apolicies%3A%0A%20%20-%20id%3A%20unique-policy-id-1-restart%0A%20%20%20%20name%3A%20Restart%20the%20VM%0A%20%20%20%20description%3A%0A%20%20%20%20actor%3A%20APPC%0A%20%20%20%20recipe%3A%20Restart%0A%20%20%20%20target%3A%0A%20%20%20%20%20%20type%3A%20VM%0A%20%20%20%20retry%3A%203%0A%20%20%20%20timeout%3A%201200%0A%20%20%20%20success%3A%20final_success%0A%20%20%20%20failure%3A%20final_failure%0A%20%20%20%20failure_timeout%3A%20final_failure_timeout%0A%20%20%20%20failure_retries%3A%20final_failure_retries%0A%20%20%20%20failure_exception%3A%20final_failure_exception%0A%20%20%20%20failure_guard%3A%20final_failure_guard"
],
"pattern": "^(.+)$"
+ },
+ "controllerName": {
+ "$id": "#/properties/properties/properties/controllerName",
+ "type": "string",
+ "title": "Controller Name",
+ "examples": [
+ "usecases"
+ ],
+ "pattern": "^(.+)$"
}
}
}
"timeout",
"abatement",
"trigger",
- "operations",
- "controllerName"
+ "operations"
],
"properties": {
"id": {
{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
- "$id": "http://www.onap.org/policy/models/schemas/onap.policies.controlloop.native.Drools.schema.json",
+ "$id": "http://www.onap.org/policy/models/schemas/onap.policies.native.drools.Artifact.schema.json",
"type": "object",
- "title": "Domain onap.policies.controlloop.native.Drools Policy root schema",
+ "title": "Domain onap.policies.native.drools.Artifact Policy root schema",
"required": [
"type",
"type_version",
"$id": "#/properties/type",
"type": "string",
"title": "Policy Type",
- "default": "onap.policies.native.Drools",
+ "default": "onap.policies.native.drools.Artifact",
"examples": [
- "onap.policies.native.Drools"
+ "onap.policies.native.drools.Artifact"
],
"pattern": "^(.+)$"
},
{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
- "$id": "http://www.onap.org/policy/models/schemas/onap.policies.drools.Controller.schema.json",
+ "$id": "http://www.onap.org/policy/models/schemas/onap.policies.native.drools.Controller.schema.json",
"type": "object",
- "title": "Domain onap.policies.drools.Controller Policy root schema",
+ "title": "Domain onap.policies.native.drools.Controller Policy root schema",
"required": [
"type",
"type_version",
"$id": "#/properties/type",
"type": "string",
"title": "Policy Type",
- "default": "onap.policies.native.Drools",
+ "default": "onap.policies.native.drools.Controller",
"examples": [
- "onap.policies.native.Drools"
+ "onap.policies.native.drools.Controller"
],
"pattern": "^(.+)$"
},
"items": {
"$id": "#/properties/properties/properties/sourceTopics/items",
"type": "object",
- "title": "Topic Data",
+ "title": "Topic Sources",
"required": [
"topicName",
- "serialization"
+ "events"
],
"properties": {
"topicName": {
],
"pattern": "^(.+)$"
},
- "serialization": {
- "$id": "#/properties/properties/properties/sourceTopics/items/properties/serialization",
+ "events": {
+ "$id": "#/properties/properties/properties/sourceTopics/items/properties/events",
"type": "array",
- "title": "Serialization",
+ "title": "Source Events",
"items": {
- "$id": "#/properties/properties/properties/sourceTopics/items/properties/serialization/items",
+ "$id": "#/properties/properties/properties/sourceTopics/items/properties/events/items",
"type": "object",
- "title": "Serialization Data",
+ "title": "Event Information",
"required": [
- "eventClass",
- "eventFilter",
- "customSerializer"
+ "eventClass"
],
"properties": {
"eventClass": {
- "$id": "#/properties/properties/properties/sourceTopics/items/properties/serialization/items/properties/eventClass",
+ "$id": "#/properties/properties/properties/sourceTopics/items/properties/events/items/properties/eventClass",
"type": "string",
"title": "Event Class",
"examples": [
"pattern": "^(.+)$"
},
"eventFilter": {
- "$id": "#/properties/properties/properties/sourceTopics/items/properties/serialization/items/properties/eventFilter",
+ "$id": "#/properties/properties/properties/sourceTopics/items/properties/events/items/properties/eventFilter",
"type": "string",
"title": "Event Filter",
"examples": [
],
"pattern": "^(.+)$"
},
- "customSerializer": {
- "$id": "#/properties/properties/properties/sourceTopics/items/properties/serialization/items/properties/customSerializer",
+ "customSerialization": {
+ "$id": "#/properties/properties/properties/sourceTopics/items/properties/events/items/properties/customSerialization",
"type": "object",
- "title": "Custom Serializer",
+ "title": "Custom Serialization",
"required": [
"customSerializerClass",
"jsonParser"
],
"properties": {
"customSerializerClass": {
- "$id": "#/properties/properties/properties/sourceTopics/items/properties/serialization/items/properties/customSerializer/properties/customSerializerClass",
+ "$id": "#/properties/properties/properties/sourceTopics/items/properties/events/items/properties/customSerialization/properties/customSerializerClass",
"type": "string",
- "title": "Custom Serializer Class",
+ "title": "Custom Serializer Class for customized JSON parsing",
"examples": [
"org.onap.policy.controlloop.util.Serialization"
],
- "pattern": "^(.*)$"
+ "pattern": "^(.+)$"
},
"jsonParser": {
- "$id": "#/properties/properties/properties/sourceTopics/items/properties/serialization/items/properties/customSerializer/properties/jsonParser",
+ "$id": "#/properties/properties/properties/sourceTopics/items/properties/events/items/properties/customSerialization/properties/jsonParser",
"type": "string",
- "title": "JSON Parser reference",
+ "title": "JSON Parser Static Field (currently only GSON is supported)",
"examples": [
"gson"
],
"title": "Sink Topic Data",
"required": [
"topicName",
- "serialization"
+ "events"
],
"properties": {
"topicName": {
],
"pattern": "^(.+)$"
},
- "serialization": {
- "$id": "#/properties/properties/properties/sinkTopics/items/properties/serialization",
+ "events": {
+ "$id": "#/properties/properties/properties/sinkTopics/items/properties/events",
"type": "array",
- "title": "The Serialization Schema",
+ "title": "Source Events",
"items": {
- "$id": "#/properties/properties/properties/sinkTopics/items/properties/serialization/items",
+ "$id": "#/properties/properties/properties/sinkTopics/items/properties/events/items",
"type": "object",
- "title": "Serialization Data",
+ "title": "Event Information",
"required": [
- "eventClass",
- "eventFilter"
+ "eventClass"
],
"properties": {
"eventClass": {
- "$id": "#/properties/properties/properties/sinkTopics/items/properties/serialization/items/properties/eventClass",
+ "$id": "#/properties/properties/properties/sinkTopics/items/properties/events/items/properties/eventClass",
"type": "string",
"title": "Event Class",
"examples": [
"pattern": "^(.+)$"
},
"eventFilter": {
- "$id": "#/properties/properties/properties/sinkTopics/items/properties/serialization/items/properties/eventFilter",
+ "$id": "#/properties/properties/properties/sinkTopics/items/properties/events/items/properties/eventFilter",
"type": "string",
- "title": "The Eventfilter Schema",
+ "title": "Event Filter",
"examples": [
"[?($.CommonHeader && $.Status)]"
],
"pattern": "^(.+)$"
},
- "customSerializer": {
- "$id": "#/properties/properties/properties/sinkTopics/items/properties/serialization/items/properties/customSerializer",
+ "customSerialization": {
+ "$id": "#/properties/properties/properties/sinkTopics/items/properties/events/items/properties/customSerialization",
"type": "object",
- "title": "The Customserializer Schema",
+ "title": "Custom Serialization",
"required": [
"customSerializerClass",
"jsonParser"
],
"properties": {
"customSerializerClass": {
- "$id": "#/properties/properties/properties/sinkTopics/items/properties/serialization/items/properties/customSerializer/properties/customSerializerClass",
+ "$id": "#/properties/properties/properties/sinkTopics/items/properties/events/items/properties/customSerialization/properties/customSerializerClass",
"type": "string",
- "title": "The Customserializerclass Schema",
+ "title": "Custom Serializer Class for customized JSON parsing",
"examples": [
- "org.onap.policy.appc.util.Serialization"
+ "org.onap.policy.controlloop.util.Serialization"
],
"pattern": "^(.+)$"
},
"jsonParser": {
- "$id": "#/properties/properties/properties/sinkTopics/items/properties/serialization/items/properties/customSerializer/properties/jsonParser",
+ "$id": "#/properties/properties/properties/sinkTopics/items/properties/events/items/properties/customSerialization/properties/jsonParser",
"type": "string",
- "title": "The Jsonparser Schema",
+ "title": "JSON Parser Static Field (currently only GSON is supported)",
"examples": [
- "gsonPretty"
+ "gson"
],
"pattern": "^(.+)$"
}
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
+import org.onap.policy.drools.domain.models.artifact.NativeArtifactController;
+import org.onap.policy.drools.domain.models.artifact.NativeArtifactPolicy;
+import org.onap.policy.drools.domain.models.artifact.NativeArtifactProperties;
+import org.onap.policy.drools.domain.models.artifact.NativeArtifactRulesArtifact;
import org.onap.policy.drools.domain.models.controller.ControllerPolicy;
-import org.onap.policy.drools.domain.models.nativ.rules.NativeDroolsController;
-import org.onap.policy.drools.domain.models.nativ.rules.NativeDroolsPolicy;
-import org.onap.policy.drools.domain.models.nativ.rules.NativeDroolsProperties;
-import org.onap.policy.drools.domain.models.nativ.rules.NativeDroolsRulesArtifact;
import org.onap.policy.drools.policies.DomainMaker;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
// Policy Types
private static final String OPERATIONAL_DROOLS_POLICY_TYPE = "onap.policies.controlloop.operational.common.Drools";
- private static final String NATIVE_DROOLS_POLICY_TYPE = "onap.policies.native.Drools";
+ private static final String NATIVE_DROOLS_POLICY_TYPE = "onap.policies.native.drools.Artifact";
// Operational vCPE Policy
private static final String OP_POLICY_NAME_VCPE = "operational.restart";
// Native Drools Policy
private static final String EXAMPLE_NATIVE_DROOLS_POLICY_NAME = "example";
private static final String EXAMPLE_NATIVE_DROOLS_POLICY_JSON =
- "src/test/resources/example.policy.native.drools.tosca.json";
+ "src/test/resources/tosca-policy-native-artifact-example.json";
// Controller Drools Policy
private static final String EXAMPLE_CONTROLLER_DROOLS_POLICY_NAME = "example";
private static final String EXAMPLE_CONTROLLER_DROOLS_POLICY_JSON =
- "src/test/resources/example.policy.drools.controller.tosca.json";
+ "src/test/resources/tosca-policy-native-controller-example.json";
private DomainMaker domainMaker;
private StandardCoder nonValCoder;
domainMaker.isConformant(policyTypeId, rawNativeDroolsPolicy);
assertTrue(domainMaker.isConformant(toscaPolicy));
- NativeDroolsPolicy domainDroolsPolicy = domainMaker.convertTo(toscaPolicy, NativeDroolsPolicy.class);
+ NativeArtifactPolicy domainDroolsPolicy = domainMaker.convertTo(toscaPolicy, NativeArtifactPolicy.class);
assertEquals("org.onap.policy.drools.test", domainDroolsPolicy.getProperties().getRulesArtifact().getGroupId());
assertEquals("lifecycle", domainDroolsPolicy.getProperties().getRulesArtifact().getArtifactId());
assertEquals("1.0.0", domainDroolsPolicy.getProperties().getRulesArtifact().getVersion());
String policyId = toscaPolicy.getMetadata().remove("policy-id");
- assertThatThrownBy(() -> domainMaker.convertTo(toscaPolicy, NativeDroolsPolicy.class))
+ assertThatThrownBy(() -> domainMaker.convertTo(toscaPolicy, NativeArtifactPolicy.class))
.isInstanceOf(CoderException.class).hasCauseInstanceOf(ValidationFailedException.class);
toscaPolicy.getMetadata().put("policy-id", policyId);
.isInstanceOf(ValidationFailedException.class)
.hasMessageContaining("Pattern ^(.+)$ is not contained in text");
- NativeDroolsPolicy domainDroolsPolicy2 =
- NativeDroolsPolicy.builder().metadata(Metadata.builder().policyId("policy-id").build()).name("example")
+ // @formatter:off
+ NativeArtifactPolicy domainDroolsPolicy2 =
+ NativeArtifactPolicy.builder().metadata(Metadata.builder().policyId("policy-id").build())
+ .name("example")
.version("1.0.0").properties(
- NativeDroolsProperties.builder().controller(
- NativeDroolsController.builder().name("example").version("1.0.0").build())
+ NativeArtifactProperties.builder().controller(
+ NativeArtifactController.builder().name("example").build())
.rulesArtifact(
- NativeDroolsRulesArtifact.builder().groupId("org.onap.policy.controlloop")
+ NativeArtifactRulesArtifact.builder().groupId("org.onap.policy.controlloop")
.artifactId("example").version("example").build()).build())
- .type("onap.policies.native.Drools")
+ .type("onap.policies.native.drools.Artifact")
.typeVersion("1.0.0").build();
+ // @formatter:on
+
assertTrue(domainMaker
.isDomainConformant(
new ToscaPolicyTypeIdentifier(domainDroolsPolicy2.getType(), domainDroolsPolicy2.getTypeVersion()),
assertEquals("example", controllerPolicy.getName());
assertEquals("1.0.0", controllerPolicy.getVersion());
- assertEquals("onap.policies.drools.Controller", controllerPolicy.getType());
+ assertEquals("onap.policies.native.drools.Controller", controllerPolicy.getType());
assertEquals("1.0.0", controllerPolicy.getTypeVersion());
assertEquals("example", controllerPolicy.getMetadata().getPolicyId());
assertEquals("lifecycle", controllerPolicy.getProperties().getControllerName());
assertEquals("DCAE_TOPIC", controllerPolicy.getProperties().getSourceTopics().get(0).getTopicName());
assertEquals("org.onap.policy.controlloop.CanonicalOnset",
- controllerPolicy.getProperties().getSourceTopics().get(0).getSerialization().get(0).getEventClass());
+ controllerPolicy.getProperties().getSourceTopics().get(0).getEvents().get(0).getEventClass());
assertEquals("[?($.closedLoopEventStatus == 'ONSET')]",
- controllerPolicy.getProperties().getSourceTopics().get(0).getSerialization().get(0).getEventFilter());
+ controllerPolicy.getProperties().getSourceTopics().get(0).getEvents().get(0).getEventFilter());
assertEquals("org.onap.policy.controlloop.util.Serialization",
- controllerPolicy.getProperties().getSourceTopics().get(0).getSerialization().get(0)
- .getCustomSerializer().getCustomSerializerClass());
+ controllerPolicy.getProperties().getSourceTopics().get(0).getEvents().get(0)
+ .getCustomSerialization().getCustomSerializerClass());
assertEquals("gson",
- controllerPolicy.getProperties().getSourceTopics().get(0).getSerialization().get(0)
- .getCustomSerializer().getJsonParser());
+ controllerPolicy.getProperties().getSourceTopics().get(0).getEvents().get(0)
+ .getCustomSerialization().getJsonParser());
assertEquals("APPC-CL", controllerPolicy.getProperties().getSinkTopics().get(0).getTopicName());
assertEquals("org.onap.policy.appc.Response",
- controllerPolicy.getProperties().getSinkTopics().get(0).getSerialization().get(0).getEventClass());
+ controllerPolicy.getProperties().getSinkTopics().get(0).getEvents().get(0).getEventClass());
assertEquals("[?($.CommonHeader && $.Status)]",
- controllerPolicy.getProperties().getSinkTopics().get(0).getSerialization().get(0).getEventFilter());
+ controllerPolicy.getProperties().getSinkTopics().get(0).getEvents().get(0).getEventFilter());
assertEquals("org.onap.policy.appc.util.Serialization",
- controllerPolicy.getProperties().getSinkTopics().get(0).getSerialization().get(0)
- .getCustomSerializer().getCustomSerializerClass());
+ controllerPolicy.getProperties().getSinkTopics().get(0).getEvents().get(0)
+ .getCustomSerialization().getCustomSerializerClass());
assertEquals("gsonPretty",
- controllerPolicy.getProperties().getSinkTopics().get(0).getSerialization().get(0)
- .getCustomSerializer().getJsonParser());
+ controllerPolicy.getProperties().getSinkTopics().get(0).getEvents().get(0)
+ .getCustomSerialization().getJsonParser());
assertEquals("value1", controllerPolicy.getProperties().getCustomConfig().get("field1"));
}
private String getJsonFromFile(String filePath) throws IOException {
- return new String(Files.readAllBytes(Paths.get(filePath)));
+ return Files.readString(Paths.get(filePath));
}
private String getJsonFromResource(String resourcePath) {
package org.onap.policy.drools.domain.models;
+import com.openpojo.reflection.PojoClass;
+import com.openpojo.reflection.filters.FilterChain;
+import com.openpojo.reflection.filters.FilterClassName;
+import com.openpojo.reflection.filters.FilterNonConcrete;
import com.openpojo.reflection.impl.PojoClassFactory;
import com.openpojo.validation.Validator;
import com.openpojo.validation.ValidatorBuilder;
import com.openpojo.validation.test.impl.GetterTester;
import com.openpojo.validation.test.impl.SetterTester;
import java.io.Serializable;
+import java.util.List;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
}
@Test
- public void testPackage() {
+ public void testDerivedClass() {
/* validate model pojos */
Validator validator = ValidatorBuilder.create()
.with(new SetterTester(), new GetterTester()).build();
validator.validate(PojoClassFactory.getPojoClass(DerivedDomainPolicy.class));
}
+ @Test
+ public void testPackage() {
+ /* validate model pojos */
+ List<PojoClass> pojoClasses =
+ PojoClassFactory
+ .getPojoClassesRecursively("org.onap.policy.drools.domain.models",
+ new FilterChain(new FilterNonConcrete(),
+ new FilterClassName(DroolsPolicy.class.getName())));
+
+ Validator validator = ValidatorBuilder.create()
+ .with(new SetterTester(), new GetterTester()).build();
+ validator.validate(pojoClasses);
+ }
}
\ No newline at end of file
--- /dev/null
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.drools.domain.models.artifact;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+import org.onap.policy.drools.domain.models.Metadata;
+
+public class ArtifactPolicyTest {
+
+ @Test
+ public void testBuildDomainPolicyNativeArtifact() {
+ /* manually create a native drools policy */
+
+ // @formatter:off
+ assertNotNull(NativeArtifactPolicy.builder()
+ .metadata(Metadata.builder().policyId("policy-id").build())
+ .name("example")
+ .type("onap.policies.native.drools.Artifact")
+ .typeVersion("1.0.0")
+ .version("1.0.0")
+ .properties(
+ NativeArtifactProperties.builder().controller(
+ NativeArtifactController.builder().name("example").build())
+ .rulesArtifact(
+ NativeArtifactRulesArtifact.builder().groupId("org.onap.policy.controlloop")
+ .artifactId("example").version("example").build()).build())
+ .build());
+ // @formatter:on
+ }
+
+}
\ No newline at end of file
package org.onap.policy.drools.domain.models.controller;
-import com.google.gson.annotations.SerializedName;
-import java.io.Serializable;
-import lombok.Builder;
-import lombok.Data;
-
-
-@Data
-@Builder
-public class ControllerSerialization implements Serializable {
-
- @SerializedName("eventClass")
- public String eventClass;
-
- @SerializedName("eventFilter")
- public String eventFilter;
-
- @SerializedName("customSerializer")
- public ControllerCustomSerializer customSerializer;
-
-}
+import static org.junit.Assert.assertNotNull;
+
+import java.util.ArrayList;
+import org.junit.Test;
+import org.onap.policy.drools.domain.models.Metadata;
+
+public class ControllerPolicyTest {
+
+ @Test
+ public void testBuildDomainPolicyController() {
+ /* manually create a controller policy */
+
+ // @formatter:off
+ assertNotNull(ControllerPolicy.builder()
+ .metadata(Metadata.builder().policyId("policy-id").build())
+ .name("example")
+ .version("1.0.0")
+ .type("onap.policies.drools.Controller")
+ .typeVersion("1.0.0")
+ .properties(ControllerProperties.builder().controllerName("example").sourceTopics(
+ new ArrayList<>()).sinkTopics(new ArrayList<>()).build())
+ .build());
+ // @formatter:on
+ }
+
+}
\ No newline at end of file
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.drools.domain.models.legacy;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import org.junit.Test;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.drools.policies.DomainMaker;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
+
+public class LegacyPolicyTest {
+ // Policy Types
+ private static final String OPERATIONAL_LEGACY_POLICY_TYPE = "onap.policies.controlloop.Operational";
+
+ // Operational vCPE Legacy Policy
+ private static final String OP_POLICY_NAME_VCPE = "operational.restart";
+ public static final String VCPE_OPERATIONAL_LEGACY_POLICY_JSON = "src/test/resources/tosca-legacy-vcpe.json";
+
+ @Test
+ public void testToscaLegacyOperationalPolicyType() throws IOException, CoderException {
+ String rawVcpeToscaPolicy = getJsonFromFile(VCPE_OPERATIONAL_LEGACY_POLICY_JSON);
+
+ ToscaPolicyTypeIdentifier legacyType =
+ new ToscaPolicyTypeIdentifier(OPERATIONAL_LEGACY_POLICY_TYPE, "1.0.0");
+
+ DomainMaker domainMaker = new DomainMaker();
+ assertTrue(domainMaker .isConformant(legacyType, rawVcpeToscaPolicy));
+ LegacyPolicy legacyPolicy = domainMaker.convertTo(legacyType, rawVcpeToscaPolicy, LegacyPolicy.class);
+
+ ToscaPolicy policy = new StandardCoder().decode(rawVcpeToscaPolicy, ToscaPolicy.class);
+ assertEquals(policy.getProperties().get("content").toString(), legacyPolicy.getProperties().getContent());
+ assertEquals(policy.getProperties().get("controllerName").toString(),
+ legacyPolicy.getProperties().getControllerName());
+ }
+
+ private String getJsonFromFile(String filePath) throws IOException {
+ return Files.readString(Paths.get(filePath));
+ }
+}
\ No newline at end of file
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.drools.domain.models.operational;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.resources.ResourceUtils;
+import org.onap.policy.drools.domain.models.Metadata;
+import org.onap.policy.drools.policies.DomainMaker;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+
+public class OperationalPolicyTest {
+ // Policy Types
+ private static final String OPERATIONAL_DROOLS_POLICY_TYPE = "onap.policies.controlloop.operational.common.Drools";
+
+ // Operational vCPE Policies
+ private static final String OP_POLICY_NAME_VCPE = "operational.restart";
+ private static final String VCPE_OPERATIONAL_DROOLS_POLICY_JSON =
+ "policies/vCPE.policy.operational.input.tosca.json";
+
+ private DomainMaker domainMaker;
+ private StandardCoder nonValCoder;
+
+ @Before
+ public void setUp() {
+ domainMaker = new DomainMaker();
+ nonValCoder = new StandardCoder();
+ }
+
+ @Test
+ public void testToscaCompliantOperationalPolicyType() throws CoderException {
+ String rawVcpeToscaPolicy = getExamplesPolicyString(VCPE_OPERATIONAL_DROOLS_POLICY_JSON, OP_POLICY_NAME_VCPE);
+
+ // valid "known" policy type with implicit schema
+ ToscaPolicyTypeIdentifier operationalCompliantType =
+ new ToscaPolicyTypeIdentifier(OPERATIONAL_DROOLS_POLICY_TYPE, "1.0.0");
+ assertTrue(domainMaker.isConformant(operationalCompliantType, rawVcpeToscaPolicy));
+ assertNotNull(domainMaker.convertTo(operationalCompliantType, rawVcpeToscaPolicy, OperationalPolicy.class));
+ }
+
+ @Test
+ public void testOperationalCompliantModel() {
+ // @formatter:off
+ OperationalPolicy policy =
+ OperationalPolicy.builder()
+ .metadata(Metadata.builder().policyId(OP_POLICY_NAME_VCPE).build())
+ .name(OP_POLICY_NAME_VCPE)
+ .type(OPERATIONAL_DROOLS_POLICY_TYPE)
+ .typeVersion("1.0.0")
+ .version("1.0.0")
+ .properties(
+ OperationalProperties.builder()
+ .id("ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e")
+ .abatement(true)
+ .trigger("unique-policy-id-1-restart")
+ .operations(
+ List.of(Operation.builder()
+ .id("unique-policy-id-1-restart")
+ .description("Restart the VM")
+ .timeout(60)
+ .retries(3)
+ .actorOperation(ActorOperation.builder()
+ .operation("Restart")
+ .actor("APPC")
+ .target(OperationalTarget.builder().targetType("VNF").build())
+ .build())
+ .build()))
+ .controllerName("usecases")
+ .build())
+ .build();
+ // @formatter:on
+
+ assertNotNull(policy);
+ }
+
+ private String getJsonFromFile(String filePath) throws IOException {
+ return Files.readString(Paths.get(filePath));
+ }
+
+ private String getJsonFromResource(String resourcePath) {
+ return ResourceUtils.getResourceAsString(resourcePath);
+ }
+
+ private ToscaPolicy getExamplesPolicy(String resourcePath, String policyName) throws CoderException {
+ String policyJson = getJsonFromResource(resourcePath);
+ ToscaServiceTemplate serviceTemplate = new StandardCoder().decode(policyJson, ToscaServiceTemplate.class);
+ return serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyName);
+ }
+
+ private String getExamplesPolicyString(String resourcePath, String policyName) throws CoderException {
+ return nonValCoder.encode(getExamplesPolicy(resourcePath, policyName));
+ }
+}
\ No newline at end of file
--- /dev/null
+{
+ "type": "onap.policies.controlloop.Operational",
+ "type_version": "1.0.0",
+ "properties": {
+ "content": "controlLoop%3A%0A%20%20version%3A%202.0.0%0A%20%20controlLoopName%3A%20ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e%0A%20%20trigger_policy%3A%20unique-policy-id-1-restart%0A%20%20timeout%3A%203600%0A%20%20abatement%3A%20true%0A%20%0Apolicies%3A%0A%20%20-%20id%3A%20unique-policy-id-1-restart%0A%20%20%20%20name%3A%20Restart%20the%20VM%0A%20%20%20%20description%3A%0A%20%20%20%20actor%3A%20APPC%0A%20%20%20%20recipe%3A%20Restart%0A%20%20%20%20target%3A%0A%20%20%20%20%20%20type%3A%20VM%0A%20%20%20%20retry%3A%203%0A%20%20%20%20timeout%3A%201200%0A%20%20%20%20success%3A%20final_success%0A%20%20%20%20failure%3A%20final_failure%0A%20%20%20%20failure_timeout%3A%20final_failure_timeout%0A%20%20%20%20failure_retries%3A%20final_failure_retries%0A%20%20%20%20failure_exception%3A%20final_failure_exception%0A%20%20%20%20failure_guard%3A%20final_failure_guard",
+ "controllerName": "usecases"
+ },
+ "name": "operational.restart",
+ "version": "1.0.0"
+}
--- /dev/null
+{
+ "tosca_definitions_version": "tosca_simple_yaml_1_0_0",
+ "topology_template": {
+ "policies": [
+ {
+ "example": {
+ "type": "onap.policies.native.drools.Artifact",
+ "type_version": "1.0.0",
+ "version": "1.0.0",
+ "name": "example",
+ "metadata": {
+ "policy-id": "example"
+ },
+ "properties": {
+ "rulesArtifact": {
+ "groupId": "org.onap.policy.drools.test",
+ "artifactId": "lifecycle",
+ "version": "1.0.0"
+ },
+ "controller": {
+ "name": "lifecycle",
+ "version": "1.0.0"
+ }
+ }
+ }
+ }
+ ]
+ }
+}
\ No newline at end of file
--- /dev/null
+{
+ "tosca_definitions_version": "tosca_simple_yaml_1_0_0",
+ "topology_template": {
+ "policies": [
+ {
+ "example": {
+ "type": "onap.policies.native.drools.Controller",
+ "type_version": "1.0.0",
+ "version": "1.0.0",
+ "name": "example",
+ "metadata": {
+ "policy-id": "example"
+ },
+ "properties": {
+ "controllerName": "lifecycle",
+ "sourceTopics": [
+ {
+ "topicName": "DCAE_TOPIC",
+ "events": [
+ {
+ "eventClass": "org.onap.policy.controlloop.CanonicalOnset",
+ "eventFilter": "[?($.closedLoopEventStatus == 'ONSET')]",
+ "customSerialization": {
+ "customSerializerClass": "org.onap.policy.controlloop.util.Serialization",
+ "jsonParser": "gson"
+ }
+ },
+ {
+ "eventClass": "org.onap.policy.controlloop.CanonicalAbated",
+ "eventFilter": "[?($.closedLoopEventStatus == 'ABATED')]"
+ }
+ ]
+ }
+ ],
+ "sinkTopics": [
+ {
+ "topicName": "APPC-CL",
+ "events": [
+ {
+ "eventClass": "org.onap.policy.appc.Response",
+ "eventFilter": "[?($.CommonHeader && $.Status)]",
+ "customSerialization": {
+ "customSerializerClass": "org.onap.policy.appc.util.Serialization",
+ "jsonParser": "gsonPretty"
+ }
+ }
+ ]
+ }
+ ],
+ "customConfig": {
+ "field1" : "value1"
+ }
+ }
+ }
+ }
+ ]
+ }
+}
\ No newline at end of file
--- /dev/null
+{
+ "type": "onap.policies.controlloop.Operational",
+ "type_version": "1.0.0",
+ "properties": {
+ "content": "controlLoop%3A%0A%20%20version%3A%202.0.0%0A%20%20controlLoopName%3A%20ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e%0A%20%20trigger_policy%3A%20unique-policy-id-1-restart%0A%20%20timeout%3A%203600%0A%20%20abatement%3A%20true%0A%20%0Apolicies%3A%0A%20%20-%20id%3A%20unique-policy-id-1-restart%0A%20%20%20%20name%3A%20Restart%20the%20VM%0A%20%20%20%20description%3A%0A%20%20%20%20actor%3A%20APPC%0A%20%20%20%20recipe%3A%20Restart%0A%20%20%20%20target%3A%0A%20%20%20%20%20%20type%3A%20VM%0A%20%20%20%20retry%3A%203%0A%20%20%20%20timeout%3A%201200%0A%20%20%20%20success%3A%20final_success%0A%20%20%20%20failure%3A%20final_failure%0A%20%20%20%20failure_timeout%3A%20final_failure_timeout%0A%20%20%20%20failure_retries%3A%20final_failure_retries%0A%20%20%20%20failure_exception%3A%20final_failure_exception%0A%20%20%20%20failure_guard%3A%20final_failure_guard"
+ },
+ "name": "operational.restart",
+ "version": "1.0.0"
+}
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.onap.policy.drools-pdp</groupId>
+ <artifactId>policy-domains</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
<dependency>
<groupId>org.onap.policy.common</groupId>
<artifactId>policy-endpoints</artifactId>
/*
* ============LICENSE_START=======================================================
- * policy-management
+ * ONAP
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2020 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.onap.policy.drools.properties.DroolsPropertyConstants;
import org.onap.policy.drools.protocol.configuration.DroolsConfiguration;
import org.onap.policy.drools.system.PolicyController;
+import org.onap.policy.drools.utils.PropertyUtil;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/* persist new properties */
getPersistenceManager().storeController(name, properties);
- this.properties = properties;
+ this.properties = PropertyUtil.getInterpolatedProperties(properties);
this.policyTypes = getPolicyTypesFromProperties();
}
#!/bin/bash
-#
+
# ============LICENSE_START=======================================================
# ONAP
# ================================================================================
-# Copyright (C) 2017, 2019 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2017-2020 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.
#
# #####################################################################
+source ${POLICY_HOME}/etc/profile.d/env.sh
+
METADATA_DB=migration
METADATA_TABLE="${METADATA_DB}".metadata_versions
MIGRATION_DIR="${POLICY_HOME}"/etc/db/migration
#!/usr/bin/env bash
-#
# ============LICENSE_START=======================================================
# ONAP
# ================================================================================
-# Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved.
# Modifications Copyright (C) 2020 Bell Canada.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# See the License for the specific language governing permissions and
# limitations under the License.
# ============LICENSE_END=========================================================
-###
+
+source ${POLICY_HOME}/etc/profile.d/env.sh
##############################################################################
# Usage: usage
#! /bin/bash
-###
# ============LICENSE_START=======================================================
-# policy-management
+# ONAP
# ================================================================================
-# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2017-2020 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.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============LICENSE_END=========================================================
-###
+
+source ${POLICY_HOME}/etc/profile.d/env.sh
function usage() {
echo -n "Usage: $(basename $0) "
#!/bin/bash
-###
# ============LICENSE_START=======================================================
# ONAP POLICY
# ================================================================================
-# Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2017-2020 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.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============LICENSE_END=========================================================
-##
+
+source ${POLICY_HOME}/etc/profile.d/env.sh
SNAME="Policy Management"
PNAME=policy-management
#! /bin/bash
-###
# ============LICENSE_START=======================================================
-# policy-management
+# ONAP
# ================================================================================
-# Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2017-2020 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.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============LICENSE_END=========================================================
-###
source $POLICY_HOME/etc/profile.d/env.sh
#! /bin/bash
-###
# ============LICENSE_START=======================================================
-# policy-management
+# ONAP
# ================================================================================
-# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============LICENSE_END=========================================================
-###
source $POLICY_HOME/etc/profile.d/env.sh
if [[ -n $1 ]]; then
- if [[ -n ${TELEMETRY_PASSWORD} ]]; then
- curl -k --silent --user ${TELEMETRY_USER}:${TELEMETRY_PASSWORD} -X DELETE --header "Content-Type: application/json" \
- https://localhost:${TELEMETRY_PORT}/policy/pdp/engine/controllers/${1}
- else
- curl -k --silent -X DELETE --header "Content-Type: application/json" \
- https://localhost:${TELEMETRY_PORT}/policy/pdp/engine/controllers/${1}
- fi
- echo
- exit
+ if [[ -n ${TELEMETRY_PASSWORD} ]]; then
+ curl -k --silent --user ${TELEMETRY_USER}:${TELEMETRY_PASSWORD} -X DELETE --header "Content-Type: application/json" \
+ https://localhost:${TELEMETRY_PORT}/policy/pdp/engine/controllers/${1}
+ else
+ curl -k --silent -X DELETE --header "Content-Type: application/json" \
+ https://localhost:${TELEMETRY_PORT}/policy/pdp/engine/controllers/${1}
+ fi
+ echo
+ exit
fi
-
-
cat <<-'EOF'
Usage: rest-delete-controller.sh closed-loop-sample|reporter|sepc|vsegw|.. (or any other controller idenfied by name)
#! /bin/bash
-###
# ============LICENSE_START=======================================================
-# ONAP POLICY
+# ONAP
# ================================================================================
-# Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============LICENSE_END=========================================================
-##
+
+source ${POLICY_HOME}/etc/profile.d/env.sh
REST_TOOL="http-prompt"
TELEMETRY_SPEC="${POLICY_HOME}/config/telemetry-spec.json"
-if ! type -p "${REST_TOOL}" > /dev/null 2>&1; then
- echo "error: prerequisite software not found: http-prompt"
- exit 1
+if ! type -p "${REST_TOOL}" >/dev/null 2>&1; then
+ echo "error: prerequisite software not found: http-prompt"
+ exit 1
fi
-if ! "${POLICY_HOME}"/bin/policy-management-controller status > /dev/null 2>&1; then
- echo "error: pdp-d is not running"
- exit 2
+if ! "${POLICY_HOME}"/bin/policy-management-controller status >/dev/null 2>&1; then
+ echo "error: pdp-d is not running"
+ exit 2
fi
if [[ ! -r ${TELEMETRY_SPEC} ]]; then
- echo "generating new spec .."
- if ! http --verify=no -a "${TELEMETRY_USER}:${TELEMETRY_PASSWORD}" https://localhost:9696/swagger.json > ${TELEMETRY_SPEC} 2> /dev/null; then
- echo "error: cannot generate telemetry spec"
- exit 3
- fi
+ echo "generating new spec .."
+ if ! http --verify=no -a "${TELEMETRY_USER}:${TELEMETRY_PASSWORD}" https://localhost:9696/swagger.json >${TELEMETRY_SPEC} 2>/dev/null; then
+ echo "error: cannot generate telemetry spec"
+ rm -f ${TELEMETRY_SPEC} 2>/dev/null
+ exit 3
+ fi
fi
exec http-prompt https://localhost:9696/policy/pdp/engine --verify=no --auth "${TELEMETRY_USER}:${TELEMETRY_PASSWORD}" --spec ${TELEMETRY_SPEC}
<modules>
<module>policy-utils</module>
<module>policy-core</module>
+ <module>policy-domains</module>
<module>policy-management</module>
<module>feature-healthcheck</module>
<module>feature-eelf</module>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <encoding>${project.encoding}</encoding>
- <source>${project.source.version}</source>
- <target>${project.target.version}</target>
- </configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
- <configuration>
- <encoding>${project.encoding}</encoding>
- </configuration>
</plugin>
<plugin>