diff options
author | Jim Hahn <jrh3@att.com> | 2021-07-26 11:11:09 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2021-07-27 17:05:44 -0400 |
commit | 70770572844f95a11206ae008dd62e42aedfe04d (patch) | |
tree | e7759ec1aaee2ab92443f2fd9febc440a2cc70bd /models-interactions/model-actors/actor.xacml/src/main | |
parent | 9a3996ce25be50c01c644efcac075a056de37451 (diff) |
Add "configure" operation to xacml
Added "configure" operation to xacml simulator and actor.xacml.
Issue-ID: POLICY-3502
Change-Id: Ia206303c65ce4e54187d818da9253dabfe864d62
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-actors/actor.xacml/src/main')
2 files changed, 84 insertions, 0 deletions
diff --git a/models-interactions/model-actors/actor.xacml/src/main/java/org/onap/policy/controlloop/actor/xacml/ConfigureOperation.java b/models-interactions/model-actors/actor.xacml/src/main/java/org/onap/policy/controlloop/actor/xacml/ConfigureOperation.java new file mode 100644 index 000000000..ed8e6778b --- /dev/null +++ b/models-interactions/model-actors/actor.xacml/src/main/java/org/onap/policy/controlloop/actor/xacml/ConfigureOperation.java @@ -0,0 +1,83 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.controlloop.actor.xacml; + +import java.util.Collections; +import java.util.Map; +import java.util.concurrent.CompletableFuture; +import javax.ws.rs.core.Response; +import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; +import org.onap.policy.controlloop.actorserviceprovider.OperationResult; +import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; +import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig; +import org.onap.policy.models.decisions.concepts.DecisionRequest; +import org.onap.policy.models.decisions.concepts.DecisionResponse; + +public class ConfigureOperation extends DecisionOperation { + + // operation name + public static final String NAME = "Configure"; + + /** + * Constructs the object. + * + * @param params operation parameters + * @param config configuration for this operation + */ + public ConfigureOperation(ControlLoopOperationParams params, HttpConfig config) { + super(params, config, Collections.emptyList()); + } + + @Override + protected DecisionRequest makeRequest() { + if (params.getPayload() == null) { + throw new IllegalArgumentException("missing payload"); + } + + DecisionRequest req = config.makeRequest(); + req.setRequestId(getSubRequestId()); + req.setResource(params.getPayload()); + + return req; + } + + @Override + protected CompletableFuture<OperationOutcome> postProcessResponse(OperationOutcome outcome, String url, + Response rawResponse, DecisionResponse response) { + + outcome.setResponse(response); + + // check for policies + Map<String, Object> policies = response.getPolicies(); + if (policies == null || policies.isEmpty()) { + outcome.setResult(OperationResult.FAILURE); + outcome.setMessage("response contains no policies"); + return CompletableFuture.completedFuture(outcome); + } + + outcome.setResult(OperationResult.SUCCESS); + + // set the message + outcome.setMessage(response.getMessage()); + + return CompletableFuture.completedFuture(outcome); + } +} diff --git a/models-interactions/model-actors/actor.xacml/src/main/java/org/onap/policy/controlloop/actor/xacml/XacmlActor.java b/models-interactions/model-actors/actor.xacml/src/main/java/org/onap/policy/controlloop/actor/xacml/XacmlActor.java index ab7452266..664aae1ec 100644 --- a/models-interactions/model-actors/actor.xacml/src/main/java/org/onap/policy/controlloop/actor/xacml/XacmlActor.java +++ b/models-interactions/model-actors/actor.xacml/src/main/java/org/onap/policy/controlloop/actor/xacml/XacmlActor.java @@ -35,5 +35,6 @@ public class XacmlActor extends HttpActor<XacmlActorParams> { super(NAME, XacmlActorParams.class); addOperator(new DecisionOperator(NAME, GuardOperation.NAME, GuardOperation::new)); + addOperator(new DecisionOperator(NAME, ConfigureOperation.NAME, ConfigureOperation::new)); } } |