diff options
author | Ram Krishna Verma <ram_krishna.verma@bell.ca> | 2020-03-02 15:27:21 -0500 |
---|---|---|
committer | Ram Krishna Verma <ram_krishna.verma@bell.ca> | 2020-03-03 09:42:51 -0500 |
commit | ccc3e28512988345e640097381d2ae0be46fe986 (patch) | |
tree | e80d52e8d27c1492df9807e94296d79ce567fa1c /plugins/forwarding-plugins/src/main | |
parent | 7b63879e6837a0242ca0d68540830031c55b4ed6 (diff) |
Remove policy/engine & apex dependency from distribution
Issue-ID: POLICY-2404
Change-Id: Ia3084c55ea65a3119354079d9afd3ee35689b7d4
Signed-off-by: Ram Krishna Verma <ram_krishna.verma@bell.ca>
Diffstat (limited to 'plugins/forwarding-plugins/src/main')
7 files changed, 0 insertions, 524 deletions
diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarder.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarder.java deleted file mode 100644 index 996b887d..00000000 --- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarder.java +++ /dev/null @@ -1,120 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. All rights reserved. - * Copyright (C) 2019 Intel Corp. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * 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.distribution.forwarding.apex.pdp; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Collection; - -import org.apache.commons.io.IOUtils; -import org.onap.policy.apex.core.deployment.EngineServiceFacade; -import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.common.parameters.ParameterService; -import org.onap.policy.distribution.forwarding.PolicyForwarder; -import org.onap.policy.distribution.forwarding.PolicyForwardingException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * This class provides an implementation of {@link PolicyForwarder} interface for forwarding the given policies to - * apex-pdp. - * - * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) - */ -public class ApexPdpPolicyForwarder implements PolicyForwarder { - - private static final Logger LOGGER = LoggerFactory.getLogger(ApexPdpPolicyForwarder.class); - private static final String POLICY_TYPE = "APEX"; - - private ApexPdpPolicyForwarderParameterGroup apexForwarderParameters; - private EngineServiceFacade engineServiceFacade; - - /** - * {@inheritDoc}. - */ - @Override - public void configure(final String parameterGroupName) { - apexForwarderParameters = ParameterService.get(parameterGroupName); - engineServiceFacade = - new EngineServiceFacade(apexForwarderParameters.getHostname(), apexForwarderParameters.getPort()); - - } - - /** - * {@inheritDoc}. - */ - @Override - public void forward(final Collection<ToscaEntity> policies) throws PolicyForwardingException { - if (policies.isEmpty()) { - final String message = "No apex policy to be forwarded to an apex engine"; - LOGGER.debug(message); - throw new PolicyForwardingException(message); - } else if (policies.size() > 1) { - final String message = "More than one apex policy cannot be forwarded to an apex engine"; - LOGGER.debug(message); - throw new PolicyForwardingException(message); - } else { - final ToscaEntity policy = (ToscaEntity) policies.toArray()[0]; - if (policy instanceof ToscaPolicy) { - final ToscaPolicy toscaPolicy = (ToscaPolicy) policy; - if (POLICY_TYPE.equalsIgnoreCase(toscaPolicy.getType())) { - forwardPolicy(toscaPolicy); - } else { - final String message = "Ignoring the policy as it is not an apex-pdp policy"; - LOGGER.debug(message); - throw new PolicyForwardingException(message); - } - } else { - final String message = "Ignoring the policy as it is not of type ToscaPolicy"; - LOGGER.debug(message); - throw new PolicyForwardingException(message); - } - } - } - - /** - * Method to forward a given policy to apex-pdp. - * - * @param apexPolicy the apex policy - * @throws PolicyForwardingException if any exception occurs while forwarding policy - */ - private void forwardPolicy(final ToscaPolicy apexPolicy) throws PolicyForwardingException { - try { - engineServiceFacade.init(); - final InputStream policyInputStream = IOUtils.toInputStream(apexPolicy.toString(), "UTF-8"); - engineServiceFacade.deployModel(apexPolicy.getName(), policyInputStream, - apexForwarderParameters.isIgnoreConflicts(), apexForwarderParameters.isForceUpdate()); - - LOGGER.debug("Sucessfully forwarded the policy to apex-pdp egine at {}:{}", - apexForwarderParameters.getHostname(), apexForwarderParameters.getPort()); - - } catch (final ApexException | IOException exp) { - final String message = "Error sending policy to apex-pdp engine at" + apexForwarderParameters.getHostname() - + ":" + apexForwarderParameters.getPort(); - LOGGER.error(message, exp); - throw new PolicyForwardingException(message, exp); - } - } -} - diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderParameterGroup.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderParameterGroup.java deleted file mode 100644 index 77c98a2d..00000000 --- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/apex/pdp/ApexPdpPolicyForwarderParameterGroup.java +++ /dev/null @@ -1,50 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 AT&T Intellectual Property. - * Modifications Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * 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.distribution.forwarding.apex.pdp; - -import lombok.Getter; - -import org.onap.policy.common.parameters.annotations.Min; -import org.onap.policy.common.parameters.annotations.NotBlank; -import org.onap.policy.common.parameters.annotations.NotNull; -import org.onap.policy.distribution.main.parameters.PolicyForwarderConfigurationParameterGroup; - -/** - * Holds the parameters for the{@link ApexPdpPolicyForwarder}. - */ -@Getter -@NotNull -@NotBlank -public class ApexPdpPolicyForwarderParameterGroup extends PolicyForwarderConfigurationParameterGroup { - public static final String POLICY_FORWARDER_PLUGIN_CLASS = ApexPdpPolicyForwarder.class.getName(); - - private String hostname; - @Min(value = 1) - private int port; - private boolean ignoreConflicts; - private boolean forceUpdate; - - public ApexPdpPolicyForwarderParameterGroup() { - super(ApexPdpPolicyForwarderParameterGroup.class.getSimpleName()); - } -} diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyAdapter.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyAdapter.java deleted file mode 100644 index 613a406f..00000000 --- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyAdapter.java +++ /dev/null @@ -1,53 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.forwarding.xacml.pdp; - -import org.onap.policy.api.PolicyParameters; -import org.onap.policy.api.PushPolicyParameters; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; - -/** - * Adapts {@link ToscaPolicy} objects to objects compatible with the XACML PDP API. - */ -public interface XacmlPdpPolicyAdapter<T extends ToscaPolicy> { - - /** - * Get the policy. - * - * @return the policy - */ - T getPolicy(); - - /** - * Get as a {@link PolicyParameters} object. - * - * @returna {@link PolicyParameters} object - */ - PolicyParameters getAsPolicyParameters(); - - /** - * Get as a {@link PushPolicyParameters} object. - * - * @returna {@link PushPolicyParameters} object - */ - PushPolicyParameters getAsPushPolicyParameters(final String pdpGroups); - -} diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyForwarder.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyForwarder.java deleted file mode 100644 index 8eeeda7e..00000000 --- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyForwarder.java +++ /dev/null @@ -1,146 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. All rights reserved. - * Copyright (C) 2019 Intel Corp. All rights reserved. - * Modifications Copyright (C) 2019 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.distribution.forwarding.xacml.pdp; - -import java.util.Collection; -import java.util.Collections; - -import javax.ws.rs.client.Entity; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import org.onap.policy.api.PolicyParameters; -import org.onap.policy.api.PushPolicyParameters; -import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams; -import org.onap.policy.common.endpoints.http.client.HttpClient; -import org.onap.policy.common.endpoints.http.client.HttpClientConfigException; -import org.onap.policy.common.endpoints.http.client.HttpClientFactory; -import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance; -import org.onap.policy.common.parameters.ParameterService; -import org.onap.policy.distribution.forwarding.PolicyForwarder; -import org.onap.policy.distribution.forwarding.xacml.pdp.adapters.XacmlPdpOptimizationPolicyAdapter; -import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.http.HttpStatus; - -/** - * Forwards policies to the XACML PDP. - */ -public class XacmlPdpPolicyForwarder implements PolicyForwarder { - - private static final Logger LOGGER = LoggerFactory.getLogger(XacmlPdpPolicyForwarder.class); - private static final String BASE_PATH = "pdp/api/"; - - private XacmlPdpPolicyForwarderParameterGroup configurationParameters = null; - - - @Override - public void forward(final Collection<ToscaEntity> policies) { - for (final ToscaEntity policy : policies) { - forward(policy); - } - } - - private void forward(final ToscaEntity policy) { - final XacmlPdpPolicyAdapter<?> policyAdapter = getXacmlPdpPolicyAdapter(policy); - - if (policyAdapter == null) { - LOGGER.error("Cannot forward policy {}. Unsupported policy type {}", policy, - policy.getClass().getSimpleName()); - return; - } - - final boolean policyCreated = createPolicy(policyAdapter); - if (policyCreated) { - pushPolicy(policyAdapter); - } - } - - private XacmlPdpPolicyAdapter<?> getXacmlPdpPolicyAdapter(final ToscaEntity policy) { - if (policy instanceof ToscaPolicy) { - return new XacmlPdpOptimizationPolicyAdapter((ToscaPolicy) policy); - } - return null; - } - - private boolean createPolicy(final XacmlPdpPolicyAdapter<?> policyAdapter) { - final PolicyParameters policyParameters = policyAdapter.getAsPolicyParameters(); - final Entity<PolicyParameters> entity = Entity.entity(policyParameters, MediaType.APPLICATION_JSON); - - return invokeHttpClient(entity, "createPolicy", policyAdapter.getPolicy().getName()); - } - - private boolean pushPolicy(final XacmlPdpPolicyAdapter<?> policyAdapter) { - final PushPolicyParameters pushPolicyParameters = - policyAdapter.getAsPushPolicyParameters(configurationParameters.getPdpGroup()); - final Entity<PushPolicyParameters> entity = Entity.entity(pushPolicyParameters, MediaType.APPLICATION_JSON); - - return invokeHttpClient(entity, "pushPolicy", policyAdapter.getPolicy().getName()); - } - - private boolean invokeHttpClient(final Entity<?> entity, final String method, final String policyName) { - - try { - final Response response = getHttpClient().put(method, entity, - Collections.singletonMap("ClientAuth", configurationParameters.getClientAuth())); - - if (response.getStatus() != HttpStatus.OK.value()) { - LOGGER.error( - "Invocation of method {} failed for policy {}. Response status: {}, Response status info: {}", - method, policyName, response.getStatus(), response.getStatusInfo()); - return false; - } - } catch (final HttpClientConfigException exception) { - LOGGER.error("Invocation of method " + method + " failed for policy " + policyName - + " due to error opening Http client", exception); - return false; - } - return true; - } - - private HttpClient getHttpClient() throws HttpClientConfigException { - final boolean useHttps = configurationParameters.isUseHttps(); - final String hostname = configurationParameters.getHostname(); - final int port = configurationParameters.getPort(); - final String userName = configurationParameters.getUserName(); - final String password = configurationParameters.getPassword(); - final boolean managed = configurationParameters.isManaged(); - final BusTopicParams params = - BusTopicParams.builder().clientName("SDC Dist").useHttps(useHttps).hostname(hostname).port(port) - .userName(userName).password(password).basePath(BASE_PATH).managed(managed).build(); - return getHttpClientFactory().build(params); - } - - @Override - public void configure(final String parameterGroupName) { - configurationParameters = ParameterService.get(parameterGroupName); - } - - // these may be overridden by junit tests - - protected HttpClientFactory getHttpClientFactory() { - return HttpClientFactoryInstance.getClientFactory(); - } -} diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyForwarderParameterGroup.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyForwarderParameterGroup.java deleted file mode 100644 index 4ce35f20..00000000 --- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyForwarderParameterGroup.java +++ /dev/null @@ -1,54 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 AT&T Intellectual Property. - * Modifications Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * 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.distribution.forwarding.xacml.pdp; - -import lombok.Getter; - -import org.onap.policy.common.parameters.annotations.Min; -import org.onap.policy.common.parameters.annotations.NotBlank; -import org.onap.policy.common.parameters.annotations.NotNull; -import org.onap.policy.distribution.main.parameters.PolicyForwarderConfigurationParameterGroup; - -/** - * Holds the parameters for the{@link XacmlPdpPolicyForwarder}. - */ -@Getter -@NotNull -@NotBlank -public class XacmlPdpPolicyForwarderParameterGroup extends PolicyForwarderConfigurationParameterGroup { - public static final String POLICY_FORWARDER_PLUGIN_CLASS = XacmlPdpPolicyForwarder.class.getName(); - - private boolean useHttps; - private String hostname; - @Min(value = 1) - private int port; - private String userName; - private String password; - private String clientAuth; - private boolean isManaged; - private String pdpGroup; - - public XacmlPdpPolicyForwarderParameterGroup() { - super(XacmlPdpPolicyForwarderParameterGroup.class.getSimpleName()); - } -} diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/adapters/AbstractXacmlPdpPolicyAdapter.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/adapters/AbstractXacmlPdpPolicyAdapter.java deleted file mode 100644 index f978d3a9..00000000 --- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/adapters/AbstractXacmlPdpPolicyAdapter.java +++ /dev/null @@ -1,54 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.forwarding.xacml.pdp.adapters; - -import org.onap.policy.api.PushPolicyParameters; -import org.onap.policy.distribution.forwarding.xacml.pdp.XacmlPdpPolicyAdapter; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; - -/** - * Base class for {@link XacmlPdpPolicyAdapter} implementations. - * - * @param <T> the type of policy the adapter handles - */ -public abstract class AbstractXacmlPdpPolicyAdapter<T extends ToscaPolicy> implements XacmlPdpPolicyAdapter<T> { - - private T policy; - - protected AbstractXacmlPdpPolicyAdapter(final T policy) { - this.policy = policy; - } - - @Override - public T getPolicy() { - return policy; - } - - @Override - public PushPolicyParameters getAsPushPolicyParameters(final String pdpGroups) { - final PushPolicyParameters pushPolicyParameters = new PushPolicyParameters(); - pushPolicyParameters.setPolicyName(policy.getName()); - pushPolicyParameters.setPolicyType(policy.getType()); - pushPolicyParameters.setPdpGroup(pdpGroups); - return pushPolicyParameters; - } - -} diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/adapters/XacmlPdpOptimizationPolicyAdapter.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/adapters/XacmlPdpOptimizationPolicyAdapter.java deleted file mode 100644 index c9633b15..00000000 --- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/adapters/XacmlPdpOptimizationPolicyAdapter.java +++ /dev/null @@ -1,47 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.distribution.forwarding.xacml.pdp.adapters; - -import org.onap.policy.api.PolicyParameters; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; - -/** - * Adapts {@link ToscaPolicy} objects to objects compatible with the XACML PDP API. - */ -public class XacmlPdpOptimizationPolicyAdapter extends AbstractXacmlPdpPolicyAdapter<ToscaPolicy> { - - /** - * Create an instance to adapt the given {@link ToscaPolicy}. - * - * @param optimizationPolicy the {@link ToscaPolicy} to be adapted - */ - public XacmlPdpOptimizationPolicyAdapter(final ToscaPolicy optimizationPolicy) { - super(optimizationPolicy); - } - - @Override - public PolicyParameters getAsPolicyParameters() { - final PolicyParameters policyParameters = new PolicyParameters(); - policyParameters.setPolicyName(getPolicy().getName()); - return policyParameters; - } - -} |