summaryrefslogtreecommitdiffstats
path: root/plugins/forwarding-plugins/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/forwarding-plugins/src/main')
-rw-r--r--plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiForwarderParameters.java7
-rw-r--r--plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiParameters.java48
-rw-r--r--plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarder.java40
3 files changed, 19 insertions, 76 deletions
diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiForwarderParameters.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiForwarderParameters.java
index c266a1ba..060be1ad 100644
--- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiForwarderParameters.java
+++ b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiForwarderParameters.java
@@ -22,6 +22,7 @@
package org.onap.policy.distribution.forwarding.lifecycle.api;
import lombok.Getter;
+import org.onap.policy.common.endpoints.parameters.RestClientParameters;
import org.onap.policy.common.parameters.annotations.NotBlank;
import org.onap.policy.common.parameters.annotations.NotNull;
import org.onap.policy.common.parameters.annotations.Valid;
@@ -38,10 +39,8 @@ import org.onap.policy.distribution.main.parameters.PolicyForwarderConfiguration
public class LifecycleApiForwarderParameters extends PolicyForwarderConfigurationParameterGroup {
public static final String POLICY_FORWARDER_PLUGIN_CLASS = LifecycleApiPolicyForwarder.class.getName();
- private @Valid LifecycleApiParameters apiParameters;
- private @Valid LifecycleApiParameters papParameters;
- private boolean isHttps;
- private boolean allowSelfSignedCerts;
+ private @Valid RestClientParameters apiParameters;
+ private @Valid RestClientParameters papParameters;
private boolean deployPolicies = true;
public LifecycleApiForwarderParameters() {
diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiParameters.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiParameters.java
deleted file mode 100644
index 46a7b082..00000000
--- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiParameters.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * 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.lifecycle.api;
-
-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 LifecycleApiPolicyForwarder}.
- *
- * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
- */
-@Getter
-@NotNull
-@NotBlank
-public class LifecycleApiParameters extends PolicyForwarderConfigurationParameterGroup {
-
- private String hostName;
- @Min(value = 1)
- private int port;
- private String userName;
- private String password;
-
- public LifecycleApiParameters() {
- super(LifecycleApiParameters.class.getSimpleName());
- }
-}
diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarder.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarder.java
index b6f41fbf..8640332d 100644
--- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarder.java
+++ b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarder.java
@@ -31,7 +31,6 @@ import javax.ws.rs.client.Entity;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-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.HttpClientFactoryInstance;
@@ -57,14 +56,20 @@ public class LifecycleApiPolicyForwarder implements PolicyForwarder {
private static final String DEPLOY_POLICY_URI = "/policy/pap/v1/pdps/policies";
private static final String CREATE_POLICY_TYPE_URI = "/policy/api/v1/policytypes/";
private static final Logger LOGGER = LoggerFactory.getLogger(LifecycleApiPolicyForwarder.class);
+
private LifecycleApiForwarderParameters forwarderParameters;
+ private HttpClient apiClient;
+ private HttpClient papClient;
/**
* {@inheritDoc}.
*/
@Override
- public void configure(final String parameterGroupName) {
+ public void configure(final String parameterGroupName) throws HttpClientConfigException {
forwarderParameters = ParameterService.get(parameterGroupName);
+
+ apiClient = HttpClientFactoryInstance.getClientFactory().build(forwarderParameters.getApiParameters());
+ papClient = HttpClientFactoryInstance.getClientFactory().build(forwarderParameters.getPapParameters());
}
/**
@@ -138,32 +143,19 @@ public class LifecycleApiPolicyForwarder implements PolicyForwarder {
private Response invokeHttpClient(final Entity<?> entity, final String path, final boolean wantApi)
throws PolicyForwardingException {
- Response response = null;
- try {
- response = getHttpClient(wantApi).post(path, entity, Map.of(HttpHeaders.ACCEPT,
- MediaType.APPLICATION_JSON, HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON));
- if (response.getStatus() / 100 != 2) {
- LOGGER.error(
- "Invocation of path {} failed for entity {}. Response status: {}, Response status info: {}",
- path, entity, response.getStatus(), response.getStatusInfo());
- throw new PolicyForwardingException("Failed creating the entity - " + entity);
- }
- } catch (final HttpClientConfigException exception) {
- throw new PolicyForwardingException("Invocation of path " + path + " failed for entity " + entity,
- exception);
+ Response response = getHttpClient(wantApi).post(path, entity, Map.of(HttpHeaders.ACCEPT,
+ MediaType.APPLICATION_JSON, HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON));
+ if (response.getStatus() / 100 != 2) {
+ LOGGER.error(
+ "Invocation of path {} failed for entity {}. Response status: {}, Response status info: {}",
+ path, entity, response.getStatus(), response.getStatusInfo());
+ throw new PolicyForwardingException("Failed creating the entity - " + entity);
}
return response;
}
- private HttpClient getHttpClient(final boolean wantApi) throws HttpClientConfigException {
- final boolean https = forwarderParameters.isHttps();
- final LifecycleApiParameters parameters =
- (wantApi ? forwarderParameters.getApiParameters() : forwarderParameters.getPapParameters());
- final BusTopicParams params = BusTopicParams.builder().clientName("Policy Distribution").useHttps(https)
- .hostname(parameters.getHostName()).port(parameters.getPort()).userName(parameters.getUserName())
- .password(parameters.getPassword()).allowSelfSignedCerts(forwarderParameters.isAllowSelfSignedCerts())
- .build();
- return HttpClientFactoryInstance.getClientFactory().build(params);
+ private HttpClient getHttpClient(final boolean wantApi) {
+ return (wantApi ? apiClient : papClient);
}
}