2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.drools.lifecycle;
23 import com.fasterxml.jackson.annotation.JsonIgnore;
25 import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
26 import org.onap.policy.common.utils.coder.CoderException;
27 import org.onap.policy.drools.controller.DroolsControllerConstants;
28 import org.onap.policy.drools.domain.models.artifact.NativeArtifactPolicy;
29 import org.onap.policy.drools.protocol.configuration.DroolsConfiguration;
30 import org.onap.policy.drools.system.PolicyController;
31 import org.onap.policy.drools.system.PolicyControllerConstants;
32 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
33 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
37 public class PolicyTypeNativeArtifactController implements PolicyTypeController {
38 private static final Logger logger = LoggerFactory.getLogger(PolicyTypeNativeArtifactController.class);
41 protected final ToscaPolicyTypeIdentifier policyType;
45 protected final transient LifecycleFsm fsm;
47 public PolicyTypeNativeArtifactController(LifecycleFsm fsm, ToscaPolicyTypeIdentifier policyType) {
48 this.policyType = policyType;
53 public boolean deploy(ToscaPolicy policy) {
54 NativeArtifactPolicy nativePolicy;
55 PolicyController controller;
57 nativePolicy = fsm.getDomainMaker().convertTo(policy, NativeArtifactPolicy.class);
59 PolicyControllerConstants.getFactory().get(nativePolicy.getProperties().getController().getName());
60 } catch (CoderException e) {
61 logger.warn("Invalid Policy: {}", policy);
65 DroolsConfiguration newConfig =
66 new DroolsConfiguration(
67 nativePolicy.getProperties().getRulesArtifact().getArtifactId(),
68 nativePolicy.getProperties().getRulesArtifact().getGroupId(),
69 nativePolicy.getProperties().getRulesArtifact().getVersion());
71 PolicyControllerConstants.getFactory().patch(controller, newConfig);
76 public boolean undeploy(ToscaPolicy policy) {
77 PolicyController controller;
79 NativeArtifactPolicy nativePolicy = fsm.getDomainMaker().convertTo(policy, NativeArtifactPolicy.class);
81 PolicyControllerConstants.getFactory().get(nativePolicy.getProperties().getController().getName());
82 } catch (RuntimeException | CoderException e) {
83 logger.warn("Invalid Policy: {}", policy);
87 DroolsConfiguration noConfig =
88 new DroolsConfiguration(
89 DroolsControllerConstants.NO_ARTIFACT_ID,
90 DroolsControllerConstants.NO_GROUP_ID,
91 DroolsControllerConstants.NO_VERSION);
93 PolicyControllerConstants.getFactory().patch(controller, noConfig);