From 161df8a94bb3b0c34ed16fd4fdba078bd1eeef9a Mon Sep 17 00:00:00 2001 From: Patrick Brady Date: Wed, 13 Dec 2017 11:14:21 -0800 Subject: Second part of onap rename This is the second commit of the rename. The folder structure is renamed for appc-adapters and appc-config in this commit. Change-Id: Iaa2b8c937ff1ca1b5d1178128961fb115ee65d9b Signed-off-by: Patrick Brady Issue-ID: APPC-13 --- .../restHealthcheck/RestHealthcheckActivator.java | 116 ++++++++ .../restHealthcheck/RestHealthcheckAdapter.java | 51 ++++ .../restHealthcheck/impl/RequestContext.java | 249 +++++++++++++++++ .../impl/RequestFailedException.java | 244 ++++++++++++++++ .../impl/RestHealthcheckAdapterImpl.java | 311 +++++++++++++++++++++ .../restHealthcheck/RestHealthcheckActivator.java | 116 -------- .../restHealthcheck/RestHealthcheckAdapter.java | 51 ---- .../restHealthcheck/impl/RequestContext.java | 249 ----------------- .../impl/RequestFailedException.java | 244 ---------------- .../impl/RestHealthcheckAdapterImpl.java | 311 --------------------- .../resources/org/onap/appc/default.properties | 79 ++++++ .../org/openecomp/appc/default.properties | 79 ------ 12 files changed, 1050 insertions(+), 1050 deletions(-) create mode 100644 appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/onap/appc/adapter/restHealthcheck/RestHealthcheckActivator.java create mode 100644 appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/onap/appc/adapter/restHealthcheck/RestHealthcheckAdapter.java create mode 100644 appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/onap/appc/adapter/restHealthcheck/impl/RequestContext.java create mode 100644 appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/onap/appc/adapter/restHealthcheck/impl/RequestFailedException.java create mode 100644 appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/onap/appc/adapter/restHealthcheck/impl/RestHealthcheckAdapterImpl.java delete mode 100644 appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/openecomp/appc/adapter/restHealthcheck/RestHealthcheckActivator.java delete mode 100644 appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/openecomp/appc/adapter/restHealthcheck/RestHealthcheckAdapter.java delete mode 100644 appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/openecomp/appc/adapter/restHealthcheck/impl/RequestContext.java delete mode 100644 appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/openecomp/appc/adapter/restHealthcheck/impl/RequestFailedException.java delete mode 100644 appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/openecomp/appc/adapter/restHealthcheck/impl/RestHealthcheckAdapterImpl.java create mode 100644 appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/resources/org/onap/appc/default.properties delete mode 100644 appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/resources/org/openecomp/appc/default.properties (limited to 'appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main') diff --git a/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/onap/appc/adapter/restHealthcheck/RestHealthcheckActivator.java b/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/onap/appc/adapter/restHealthcheck/RestHealthcheckActivator.java new file mode 100644 index 000000000..acd9d013b --- /dev/null +++ b/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/onap/appc/adapter/restHealthcheck/RestHealthcheckActivator.java @@ -0,0 +1,116 @@ + +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ +package org.onap.appc.adapter.restHealthcheck; + +import org.onap.appc.Constants; +import org.onap.appc.adapter.restHealthcheck.impl.RestHealthcheckAdapterImpl; +import org.onap.appc.configuration.Configuration; +import org.onap.appc.configuration.ConfigurationFactory; +import org.onap.appc.i18n.Msg; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; + +public class RestHealthcheckActivator implements BundleActivator { + + /** + * The bundle registration + */ + private ServiceRegistration registration = null; + + /** + * The reference to the actual implementation object that implements the services + */ + private RestHealthcheckAdapter adapter; + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(RestHealthcheckActivator.class); + + /** + * The configuration object used to configure this bundle + */ + private Configuration configuration; + + /** + * Called when this bundle is started so the Framework can perform the bundle-specific activities necessary to start + * this bundle. This method can be used to register services or to allocate any resources that this bundle needs. + *

+ * This method must complete and return to its caller in a timely manner. + *

+ * + * @param context + * The execution context of the bundle being started. + * @throws java.lang.Exception + * If this method throws an exception, this bundle is marked as stopped and the Framework will remove + * this bundle's listeners, unregister all services registered by this bundle, and release all services + * used by this bundle. + * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) + */ + @Override + public void start(BundleContext context) throws Exception { + logger.info("Starting bundle " + getName()); + + adapter = new RestHealthcheckAdapterImpl(); + if (registration == null) { + registration = context.registerService(RestHealthcheckAdapter.class, adapter, null); + } + + } + + /** + * Called when this bundle is stopped so the Framework can perform the bundle-specific activities necessary to stop + * the bundle. In general, this method should undo the work that the BundleActivator.start method started. There + * should be no active threads that were started by this bundle when this bundle returns. A stopped bundle must not + * call any Framework objects. + *

+ * This method must complete and return to its caller in a timely manner. + *

+ * + * @param context + * The execution context of the bundle being stopped. + * @throws java.lang.Exception + * If this method throws an exception, the bundle is still marked as stopped, and the Framework will + * remove the bundle's listeners, unregister all services registered by the bundle, and release all + * services used by the bundle. * + * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) + */ + @Override + public void stop(BundleContext context) throws Exception { + logger.info("Stopping bundle " + getName()); + + if (registration != null) { + + registration.unregister(); + registration = null; + + } + } + + public String getName() { + return "APPC Rest Healthcheck adapter"; + } + +} diff --git a/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/onap/appc/adapter/restHealthcheck/RestHealthcheckAdapter.java b/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/onap/appc/adapter/restHealthcheck/RestHealthcheckAdapter.java new file mode 100644 index 000000000..6413ec415 --- /dev/null +++ b/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/onap/appc/adapter/restHealthcheck/RestHealthcheckAdapter.java @@ -0,0 +1,51 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ +package org.onap.appc.adapter.restHealthcheck; + +import java.util.Map; + +import org.onap.appc.exceptions.APPCException; +import com.att.cdp.zones.model.Server; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; + + +public interface RestHealthcheckAdapter extends SvcLogicJavaPlugin { + + + static final String PROPERTY_PROVIDER_TYPE = "org.onap.appc.provider.type"; + + + static final String PROPERTY_PROVIDER_NAME = "org.onap.appc.provider.name"; + + static final String PROPERTY_INSTANCE_URL = "org.onap.appc.instance.url"; + + + static final String PROPERTY_IDENTITY_URL = "org.onap.appc.identity.url"; + + String getAdapterName(); + + void checkHealth(Map params, SvcLogicContext ctx) ; + +} diff --git a/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/onap/appc/adapter/restHealthcheck/impl/RequestContext.java b/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/onap/appc/adapter/restHealthcheck/impl/RequestContext.java new file mode 100644 index 000000000..7114f5524 --- /dev/null +++ b/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/onap/appc/adapter/restHealthcheck/impl/RequestContext.java @@ -0,0 +1,249 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + + + +package org.onap.appc.adapter.restHealthcheck.impl; + +import org.onap.appc.Constants; +import org.onap.appc.configuration.Configuration; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; + +public class RequestContext { + /** + * The number of seconds of wait time between successive attempts to connect to the provider. This is used to + * recover from provider outages or failures. It is not used to recover from logical errors, such as an invalid + * request, server not found, etc. + */ + private Integer retryDelay; + + /** + * The number of times we will attempt to connect to the provider. This is used to recover from provider outages or + * failures. It is not used to recover from logical errors, such as an invalid request, server not found, etc. + */ + private Integer retryLimit; + + /** + * The total time, in milliseconds, that the provider can have to process this request. If the accumulated time + * exceeds the time to live, then the request is failed with a timeout exception, regardless of the state of the + * provider. Note that the caller may supply this as a value in seconds, in which case it must be converted to + * milliseconds for the request context. + */ + private Long timeToLive; + + /** + * The accumulated time, in milliseconds, that has been used so far to process the request. This is compared to the + * time to live each time it is updated. If the accumulated time exceeds the time to live, then the request is + * failed with a timeout exception, regardless of the state of the provider. + */ + private long accumulatedTime; + + /** + * The total number of retries attempted so far + */ + private int attempt; + + /** + * The time when the stopwatch was started + */ + private long startTime = -1; + + /** + * The service logic (DG) context from the SLI + */ + private SvcLogicContext svcLogicContext; + + /** + * The configuration + */ + + + /** + * Set to true whenever the retry limit has been exceeded, reset to false when reset() is called. + */ + private boolean retryFailed; + + /** + * Creates the request context + * + * @param context + * The service logic (SLI) context associated with the current DG + */ + public RequestContext(SvcLogicContext context) { + setSvcLogicContext(context); + } + + /** + * @return The retry delay, in seconds. If zero, then no retry is to be performed + */ + public int getRetryDelay() { + if (retryDelay == null) { + int value = 10; + retryDelay = Integer.valueOf(value); + } + + return retryDelay.intValue(); + } + + /** + * This method is a helper that allows the caller to delay for the retry interval time and not have to handle the + * thread interruption, timer handling, etc. + */ + public void delay() { + long time = getRetryDelay() * 1000L; + long future = System.currentTimeMillis() + time; + if (time != 0) { + while (System.currentTimeMillis() < future && time > 0) { + try { + Thread.sleep(time); + } catch (InterruptedException e) { + /* + * This is rare, but it can happen if another thread interrupts us while we are sleeping. In that + * case, the thread is resumed before the delay time has actually expired, so re-calculate the + * amount of delay time needed and reenter the sleep until we get to the future time. + */ + time = future - System.currentTimeMillis(); + } + } + } + } + + /** + * @return The number of retries that are allowed per connection + */ + public int getRetryLimit() { + if (retryLimit == null) { + int value = 10; + retryLimit = Integer.valueOf(value); + } + + return retryLimit.intValue(); + } + + /** + * Check and count the connection attempt. + * + * @return True if the connection should be attempted. False indicates that the number of retries has been exhausted + * and it should NOT be attempted. + */ + public boolean attempt() { + if (retryFailed || attempt >= getRetryLimit()) { + retryFailed = true; + return false; + } + attempt++; + + return true; + } + + /** + * @return The number of retry attempts so far + */ + public int getAttempts() { + return attempt; + } + + /** + * @return True if the retry limit has been exceeded, false otherwise + */ + public boolean isFailed() { + return retryFailed; + } + + /** + * This method both checks the time to live to see if it has been exceeded and accumulates the total time used so + * far. + *

+ * Each time this method is called it accumulates the total duration since the last time it was called to the total + * time accumulator. It then checks the total time to the time to live and if greater, it returns false. As long as + * the total time used is less than or equal to the time to live limit, the method returns true. It is important to + * call this method at the very beginning of the process so that all parts of the process are tracked. + *

+ * + * @return True if the total time to live has not been exceeded. False indicates that the total time to live has + * been exceeded and no further processing should be performed. + */ + public boolean isAlive() { + long now = System.currentTimeMillis(); + if (startTime == -1) { + startTime = now; + return true; + } + accumulatedTime += (now - startTime); + startTime = now; + if (accumulatedTime > timeToLive) { + return false; + } + return true; + } + + /** + * @return The total amount of time used, in milliseconds. + */ + public long getTotalDuration() { + return accumulatedTime; + } + + /** + * This method is called to reset the retry counters. It has no effect on the time to live accumulator. + */ + public void reset() { + attempt = 0; + } + + /** + * Sets the time to live to the value, expressed in seconds + * + * @param time + * The time to live, in seconds + */ + public void setTimeToLiveSeconds(int time) { + setTimeToLiveMS(time * 1000L); + } + + /** + * Sets the time to live to the value, expressed in milliseconds + * + * @param time + * The time to live, in milliseconds + */ + public void setTimeToLiveMS(long time) { + this.timeToLive = time; + } + + /** + * @return The service logic context associated with this request + */ + public SvcLogicContext getSvcLogicContext() { + return svcLogicContext; + } + + /** + * @param svcLogicContext + * The service logic context to be associated with this request + */ + public void setSvcLogicContext(SvcLogicContext svcLogicContext) { + this.svcLogicContext = svcLogicContext; + } +} diff --git a/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/onap/appc/adapter/restHealthcheck/impl/RequestFailedException.java b/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/onap/appc/adapter/restHealthcheck/impl/RequestFailedException.java new file mode 100644 index 000000000..07ed295ef --- /dev/null +++ b/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/onap/appc/adapter/restHealthcheck/impl/RequestFailedException.java @@ -0,0 +1,244 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + + + +package org.onap.appc.adapter.restHealthcheck.impl; + +import org.glassfish.grizzly.http.util.HttpStatus; + +import com.att.cdp.zones.model.Server; + + +public class RequestFailedException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * The operation that was being requested or performed at the time of the failure. + */ + private String operation; + + /** + * A message that details the reason for the failure + */ + private String reason; + + /** + * The server that was being operated upon + */ + private Server server; + + /** + * The id of the server being operated upon if the server object is not available (such as the server was not found) + */ + private String serverId; + + /** + * The most appropriate Http Status code that reflects the error + */ + private HttpStatus status; + + /** + * + */ + public RequestFailedException() { + // intentionally empty + } + + /** + * @param message + * The error message + */ + public RequestFailedException(String message) { + super(message); + } + + /** + * Construct the request failed exception with the operation being performed, reason for the failure, http status + * code that is most appropriate, and the server we were processing. + * + * @param operation + * The operation being performed + * @param reason + * The reason that the operation was failed + * @param status + * The http status code that is most appropriate + * @param server + * The server that we were processing + */ + @SuppressWarnings("nls") + public RequestFailedException(String operation, String reason, HttpStatus status, Server server) { + super(operation + ":" + reason); + this.operation = operation; + this.reason = reason; + this.status = status; + this.server = server; + if (server != null) { + this.serverId = server.getId(); + } + } + + /** + * Construct the request failed exception with the operation being performed, reason for the failure, http status + * code that is most appropriate, and the server we were processing. + * + * @param ex + * The exception that we are wrapping + * @param operation + * The operation being performed + * @param reason + * The reason that the operation was failed + * @param status + * The http status code that is most appropriate + * @param server + * The server that we were processing + */ + @SuppressWarnings("nls") + public RequestFailedException(Throwable ex, String operation, String reason, HttpStatus status, Server server) { + super(operation + ":" + reason, ex); + this.operation = operation; + this.reason = reason; + this.status = status; + this.server = server; + if (server != null) { + this.serverId = server.getId(); + } + } + + /** + * @param message + * The error message + * @param cause + * A nested exception + */ + public RequestFailedException(String message, Throwable cause) { + super(message, cause); + } + + /** + * @param message + * The error message + * @param cause + * A nested exception + * @param enableSuppression + * whether or not suppression is enabled or disabled + * @param writableStackTrace + * whether or not the stack trace should be writable + */ + public RequestFailedException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } + + /** + * @param cause + * the cause (which is saved for later retrieval by the {@link #getCause()} method). (A null value is + * permitted, and indicates that the cause is nonexistent or unknown.) + */ + public RequestFailedException(Throwable cause) { + super(cause); + } + + /** + * @return The operation being performed + */ + public String getOperation() { + return operation; + } + + /** + * @return The reason for the failure + */ + public String getReason() { + return reason; + } + + /** + * @return The server being operated upon + */ + public Server getServer() { + return server; + } + + /** + * @return The id of the server being operated upon + */ + public String getServerId() { + return serverId; + } + + /** + * @return The status code from the operation + */ + public HttpStatus getStatus() { + return status; + } + + /** + * @param operation + * The operation being performed + */ + public void setOperation(String operation) { + this.operation = operation; + } + + /** + * @param reason + * The reason for the failure + */ + public void setReason(String reason) { + this.reason = reason; + } + + /** + * @param server + * The server being operated upon + */ + public void setServer(Server server) { + this.server = server; + if (server != null) { + setServerId(server.getId()); + } + } + + /** + * @param serverId + * The id of the server being operated upon + */ + public void setServerId(String serverId) { + this.serverId = serverId; + } + + /** + * @param status + * The status of the request + */ + public void setStatus(HttpStatus status) { + this.status = status; + } + +} diff --git a/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/onap/appc/adapter/restHealthcheck/impl/RestHealthcheckAdapterImpl.java b/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/onap/appc/adapter/restHealthcheck/impl/RestHealthcheckAdapterImpl.java new file mode 100644 index 000000000..37820a63d --- /dev/null +++ b/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/onap/appc/adapter/restHealthcheck/impl/RestHealthcheckAdapterImpl.java @@ -0,0 +1,311 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.adapter.restHealthcheck.impl; + +import java.util.Map; +import java.util.Properties; +import org.apache.http.impl.client.CloseableHttpClient; + +import org.onap.appc.Constants; +import org.onap.appc.adapter.restHealthcheck.RestHealthcheckAdapter; +import org.onap.appc.configuration.Configuration; +import org.onap.appc.pool.PoolExtensionException; +import org.onap.appc.util.StructuredPropertyHelper; + + +import com.att.cdp.zones.ImageService; +import com.att.cdp.zones.Provider; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.att.eelf.i18n.EELFResourceManager; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; + +import org.glassfish.grizzly.http.util.HttpStatus; + +import static com.att.eelf.configuration.Configuration.*; + +import org.apache.http.*; +import org.apache.http.client.*; +import org.apache.http.client.methods.*; +import org.apache.http.impl.client.*; +import org.apache.http.util.EntityUtils; +import java.io.IOException; +import java.net.InetAddress; + +public class RestHealthcheckAdapterImpl implements RestHealthcheckAdapter { + + /** + * The constant used to define the adapter name in the mapped diagnostic + * context + */ + + + @SuppressWarnings("nls") + public static final String MDC_ADAPTER = "adapter"; + + /** + * The constant used to define the service name in the mapped diagnostic + * context + */ + @SuppressWarnings("nls") + public static final String MDC_SERVICE = "service"; + + /** + * The constant for the status code for a failed outcome + */ + @SuppressWarnings("nls") + public static final String OUTCOME_FAILURE = "failure"; + + /** + * The constant for the status code for a successful outcome + */ + @SuppressWarnings("nls") + public static final String OUTCOME_SUCCESS = "success"; + + /** + * A constant for the property token "provider" used in the structured + * property specifications + */ + @SuppressWarnings("nls") + public static final String PROPERTY_PROVIDER = "provider"; + + /** + * A constant for the property token "identity" used in the structured + * property specifications + */ + @SuppressWarnings("nls") + public static final String PROPERTY_PROVIDER_IDENTITY = "identity"; + + /** + * A constant for the property token "name" used in the structured property + * specifications + */ + @SuppressWarnings("nls") + public static final String PROPERTY_PROVIDER_NAME = "name"; + + /** + * A constant for the property token "tenant" used in the structured + * property specifications + */ + @SuppressWarnings("nls") + public static final String PROPERTY_PROVIDER_TENANT = "tenant"; + + /** + * A constant for the property token "tenant name" used in the structured + * property specifications + */ + @SuppressWarnings("nls") + public static final String PROPERTY_PROVIDER_TENANT_NAME = "name"; + + /** + * A constant for the property token "password" used in the structured + * property specifications + */ + @SuppressWarnings("nls") + public static final String PROPERTY_PROVIDER_TENANT_PASSWORD = "password"; // NOSONAR + + /** + * A constant for the property token "userid" used in the structured + * property specifications + */ + @SuppressWarnings("nls") + public static final String PROPERTY_PROVIDER_TENANT_USERID = "userid"; + + /** + * A constant for the property token "type" used in the structured property + * specifications + */ + @SuppressWarnings("nls") + public static final String PROPERTY_PROVIDER_TYPE = "type"; + + + @SuppressWarnings("nls") + public static final String PING_SERVICE = "pingServer"; + + /** + * The logger to be used + */ + private static final EELFLogger logger = EELFManager.getInstance().getLogger(RestHealthcheckAdapterImpl.class); + + /** + * The constant for a left parenthesis + */ + private static final char LPAREN = '('; + + /** + * The constant for a new line control code + */ + private static final char NL = '\n'; + + /** + * The constant for a single quote + */ + private static final char QUOTE = '\''; + + /** + * The constant for a right parenthesis + */ + private static final char RPAREN = ')'; + + /** + * The constant for a space + */ + private static final char SPACE = ' '; + + /** + * A reference to the adapter configuration object. + */ + private Configuration configuration; + + /** + * A cache of providers that are predefined. + */ + // private Map providerCache; + + /** + * This default constructor is used as a work around because the activator + * wasnt getting called + */ + /** + * A cache of providers that are predefined. + */ + // private Map providerCache; + + /** + * This default constructor is used as a work around because the activator + * wasnt getting called + */ + public RestHealthcheckAdapterImpl() { + initialize(); + + } + + + public RestHealthcheckAdapterImpl(boolean initialize) { + + if (initialize) { + initialize(); + + } + } + + + public RestHealthcheckAdapterImpl(Properties props) { + initialize(); + + } + + + @Override + public String getAdapterName() { + return configuration.getProperty(Constants.PROPERTY_ADAPTER_NAME); + } + + public void checkHealth(Map params, SvcLogicContext ctx) { + logger.info("VNF rest health check"); + String uri=params.get("VNF.URI"); + String endPoint=params.get("VNF.endpoint"); + String tUrl=uri+"/"+endPoint; + RequestContext rc = new RequestContext(ctx); + rc.isAlive(); + + try(CloseableHttpClient httpClient = HttpClients.createDefault()) { + HttpGet httpGet = new HttpGet(tUrl); + HttpResponse response = null; + response = httpClient.execute(httpGet); + int responseCode=response.getStatusLine().getStatusCode(); + HttpEntity entity = response.getEntity(); + String responseOutput=EntityUtils.toString(entity); + if(responseCode==200) + { + doSuccess(rc,responseCode,responseOutput); + } + else + { + doHealthCheckFailure(rc,responseCode,responseOutput); + } + } catch (Exception ex) { + doFailure(rc, HttpStatus.INTERNAL_SERVER_ERROR_500, ex.toString()); + } + } + + + + + @SuppressWarnings("static-method") + private void doFailure(RequestContext rc, HttpStatus code, String message) { + SvcLogicContext svcLogic = rc.getSvcLogicContext(); + String msg = (message == null) ? code.getReasonPhrase() : message; + if (msg.contains("\n")) { + msg = msg.substring(msg.indexOf("\n")); + } + + String status; + try { + status = Integer.toString(code.getStatusCode()); + } catch (Exception e) { + status = "500"; + } + svcLogic.setStatus(OUTCOME_FAILURE); + svcLogic.setAttribute("healthcheck.result.code", "200"); + svcLogic.setAttribute("healthcheck.result.message", status+" "+msg); + } + + + /** + * @param rc + * The request context that manages the state and recovery of the + * request for the life of its processing. + */ + @SuppressWarnings("static-method") + private void doHealthCheckFailure(RequestContext rc, int code, String message) { + SvcLogicContext svcLogic = rc.getSvcLogicContext(); + String msg = Integer.toString(code)+" "+message; + svcLogic.setAttribute("healthcheck.result.code", "200"); + svcLogic.setAttribute("healthcheck.result.message", msg); + + } + + + @SuppressWarnings("static-method") + private void doSuccess(RequestContext rc, int code, String message) { + SvcLogicContext svcLogic = rc.getSvcLogicContext(); + String msg = Integer.toString(code)+" "+message; + svcLogic.setAttribute("healthcheck.result.code", "400"); + svcLogic.setAttribute("healthcheck.result.message", msg); + + } + + + /** + * initialize the provider adapter by building the context cache + */ + private void initialize() { + + + logger.info("init rest health check adapter!!!!!"); + } + +} diff --git a/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/openecomp/appc/adapter/restHealthcheck/RestHealthcheckActivator.java b/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/openecomp/appc/adapter/restHealthcheck/RestHealthcheckActivator.java deleted file mode 100644 index acd9d013b..000000000 --- a/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/openecomp/appc/adapter/restHealthcheck/RestHealthcheckActivator.java +++ /dev/null @@ -1,116 +0,0 @@ - -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ -package org.onap.appc.adapter.restHealthcheck; - -import org.onap.appc.Constants; -import org.onap.appc.adapter.restHealthcheck.impl.RestHealthcheckAdapterImpl; -import org.onap.appc.configuration.Configuration; -import org.onap.appc.configuration.ConfigurationFactory; -import org.onap.appc.i18n.Msg; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; - -public class RestHealthcheckActivator implements BundleActivator { - - /** - * The bundle registration - */ - private ServiceRegistration registration = null; - - /** - * The reference to the actual implementation object that implements the services - */ - private RestHealthcheckAdapter adapter; - - private static final EELFLogger logger = EELFManager.getInstance().getLogger(RestHealthcheckActivator.class); - - /** - * The configuration object used to configure this bundle - */ - private Configuration configuration; - - /** - * Called when this bundle is started so the Framework can perform the bundle-specific activities necessary to start - * this bundle. This method can be used to register services or to allocate any resources that this bundle needs. - *

- * This method must complete and return to its caller in a timely manner. - *

- * - * @param context - * The execution context of the bundle being started. - * @throws java.lang.Exception - * If this method throws an exception, this bundle is marked as stopped and the Framework will remove - * this bundle's listeners, unregister all services registered by this bundle, and release all services - * used by this bundle. - * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) - */ - @Override - public void start(BundleContext context) throws Exception { - logger.info("Starting bundle " + getName()); - - adapter = new RestHealthcheckAdapterImpl(); - if (registration == null) { - registration = context.registerService(RestHealthcheckAdapter.class, adapter, null); - } - - } - - /** - * Called when this bundle is stopped so the Framework can perform the bundle-specific activities necessary to stop - * the bundle. In general, this method should undo the work that the BundleActivator.start method started. There - * should be no active threads that were started by this bundle when this bundle returns. A stopped bundle must not - * call any Framework objects. - *

- * This method must complete and return to its caller in a timely manner. - *

- * - * @param context - * The execution context of the bundle being stopped. - * @throws java.lang.Exception - * If this method throws an exception, the bundle is still marked as stopped, and the Framework will - * remove the bundle's listeners, unregister all services registered by the bundle, and release all - * services used by the bundle. * - * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) - */ - @Override - public void stop(BundleContext context) throws Exception { - logger.info("Stopping bundle " + getName()); - - if (registration != null) { - - registration.unregister(); - registration = null; - - } - } - - public String getName() { - return "APPC Rest Healthcheck adapter"; - } - -} diff --git a/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/openecomp/appc/adapter/restHealthcheck/RestHealthcheckAdapter.java b/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/openecomp/appc/adapter/restHealthcheck/RestHealthcheckAdapter.java deleted file mode 100644 index 6413ec415..000000000 --- a/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/openecomp/appc/adapter/restHealthcheck/RestHealthcheckAdapter.java +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ -package org.onap.appc.adapter.restHealthcheck; - -import java.util.Map; - -import org.onap.appc.exceptions.APPCException; -import com.att.cdp.zones.model.Server; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; - - -public interface RestHealthcheckAdapter extends SvcLogicJavaPlugin { - - - static final String PROPERTY_PROVIDER_TYPE = "org.onap.appc.provider.type"; - - - static final String PROPERTY_PROVIDER_NAME = "org.onap.appc.provider.name"; - - static final String PROPERTY_INSTANCE_URL = "org.onap.appc.instance.url"; - - - static final String PROPERTY_IDENTITY_URL = "org.onap.appc.identity.url"; - - String getAdapterName(); - - void checkHealth(Map params, SvcLogicContext ctx) ; - -} diff --git a/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/openecomp/appc/adapter/restHealthcheck/impl/RequestContext.java b/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/openecomp/appc/adapter/restHealthcheck/impl/RequestContext.java deleted file mode 100644 index 7114f5524..000000000 --- a/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/openecomp/appc/adapter/restHealthcheck/impl/RequestContext.java +++ /dev/null @@ -1,249 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - - - -package org.onap.appc.adapter.restHealthcheck.impl; - -import org.onap.appc.Constants; -import org.onap.appc.configuration.Configuration; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; - -public class RequestContext { - /** - * The number of seconds of wait time between successive attempts to connect to the provider. This is used to - * recover from provider outages or failures. It is not used to recover from logical errors, such as an invalid - * request, server not found, etc. - */ - private Integer retryDelay; - - /** - * The number of times we will attempt to connect to the provider. This is used to recover from provider outages or - * failures. It is not used to recover from logical errors, such as an invalid request, server not found, etc. - */ - private Integer retryLimit; - - /** - * The total time, in milliseconds, that the provider can have to process this request. If the accumulated time - * exceeds the time to live, then the request is failed with a timeout exception, regardless of the state of the - * provider. Note that the caller may supply this as a value in seconds, in which case it must be converted to - * milliseconds for the request context. - */ - private Long timeToLive; - - /** - * The accumulated time, in milliseconds, that has been used so far to process the request. This is compared to the - * time to live each time it is updated. If the accumulated time exceeds the time to live, then the request is - * failed with a timeout exception, regardless of the state of the provider. - */ - private long accumulatedTime; - - /** - * The total number of retries attempted so far - */ - private int attempt; - - /** - * The time when the stopwatch was started - */ - private long startTime = -1; - - /** - * The service logic (DG) context from the SLI - */ - private SvcLogicContext svcLogicContext; - - /** - * The configuration - */ - - - /** - * Set to true whenever the retry limit has been exceeded, reset to false when reset() is called. - */ - private boolean retryFailed; - - /** - * Creates the request context - * - * @param context - * The service logic (SLI) context associated with the current DG - */ - public RequestContext(SvcLogicContext context) { - setSvcLogicContext(context); - } - - /** - * @return The retry delay, in seconds. If zero, then no retry is to be performed - */ - public int getRetryDelay() { - if (retryDelay == null) { - int value = 10; - retryDelay = Integer.valueOf(value); - } - - return retryDelay.intValue(); - } - - /** - * This method is a helper that allows the caller to delay for the retry interval time and not have to handle the - * thread interruption, timer handling, etc. - */ - public void delay() { - long time = getRetryDelay() * 1000L; - long future = System.currentTimeMillis() + time; - if (time != 0) { - while (System.currentTimeMillis() < future && time > 0) { - try { - Thread.sleep(time); - } catch (InterruptedException e) { - /* - * This is rare, but it can happen if another thread interrupts us while we are sleeping. In that - * case, the thread is resumed before the delay time has actually expired, so re-calculate the - * amount of delay time needed and reenter the sleep until we get to the future time. - */ - time = future - System.currentTimeMillis(); - } - } - } - } - - /** - * @return The number of retries that are allowed per connection - */ - public int getRetryLimit() { - if (retryLimit == null) { - int value = 10; - retryLimit = Integer.valueOf(value); - } - - return retryLimit.intValue(); - } - - /** - * Check and count the connection attempt. - * - * @return True if the connection should be attempted. False indicates that the number of retries has been exhausted - * and it should NOT be attempted. - */ - public boolean attempt() { - if (retryFailed || attempt >= getRetryLimit()) { - retryFailed = true; - return false; - } - attempt++; - - return true; - } - - /** - * @return The number of retry attempts so far - */ - public int getAttempts() { - return attempt; - } - - /** - * @return True if the retry limit has been exceeded, false otherwise - */ - public boolean isFailed() { - return retryFailed; - } - - /** - * This method both checks the time to live to see if it has been exceeded and accumulates the total time used so - * far. - *

- * Each time this method is called it accumulates the total duration since the last time it was called to the total - * time accumulator. It then checks the total time to the time to live and if greater, it returns false. As long as - * the total time used is less than or equal to the time to live limit, the method returns true. It is important to - * call this method at the very beginning of the process so that all parts of the process are tracked. - *

- * - * @return True if the total time to live has not been exceeded. False indicates that the total time to live has - * been exceeded and no further processing should be performed. - */ - public boolean isAlive() { - long now = System.currentTimeMillis(); - if (startTime == -1) { - startTime = now; - return true; - } - accumulatedTime += (now - startTime); - startTime = now; - if (accumulatedTime > timeToLive) { - return false; - } - return true; - } - - /** - * @return The total amount of time used, in milliseconds. - */ - public long getTotalDuration() { - return accumulatedTime; - } - - /** - * This method is called to reset the retry counters. It has no effect on the time to live accumulator. - */ - public void reset() { - attempt = 0; - } - - /** - * Sets the time to live to the value, expressed in seconds - * - * @param time - * The time to live, in seconds - */ - public void setTimeToLiveSeconds(int time) { - setTimeToLiveMS(time * 1000L); - } - - /** - * Sets the time to live to the value, expressed in milliseconds - * - * @param time - * The time to live, in milliseconds - */ - public void setTimeToLiveMS(long time) { - this.timeToLive = time; - } - - /** - * @return The service logic context associated with this request - */ - public SvcLogicContext getSvcLogicContext() { - return svcLogicContext; - } - - /** - * @param svcLogicContext - * The service logic context to be associated with this request - */ - public void setSvcLogicContext(SvcLogicContext svcLogicContext) { - this.svcLogicContext = svcLogicContext; - } -} diff --git a/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/openecomp/appc/adapter/restHealthcheck/impl/RequestFailedException.java b/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/openecomp/appc/adapter/restHealthcheck/impl/RequestFailedException.java deleted file mode 100644 index 07ed295ef..000000000 --- a/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/openecomp/appc/adapter/restHealthcheck/impl/RequestFailedException.java +++ /dev/null @@ -1,244 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - - - -package org.onap.appc.adapter.restHealthcheck.impl; - -import org.glassfish.grizzly.http.util.HttpStatus; - -import com.att.cdp.zones.model.Server; - - -public class RequestFailedException extends Exception { - - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * The operation that was being requested or performed at the time of the failure. - */ - private String operation; - - /** - * A message that details the reason for the failure - */ - private String reason; - - /** - * The server that was being operated upon - */ - private Server server; - - /** - * The id of the server being operated upon if the server object is not available (such as the server was not found) - */ - private String serverId; - - /** - * The most appropriate Http Status code that reflects the error - */ - private HttpStatus status; - - /** - * - */ - public RequestFailedException() { - // intentionally empty - } - - /** - * @param message - * The error message - */ - public RequestFailedException(String message) { - super(message); - } - - /** - * Construct the request failed exception with the operation being performed, reason for the failure, http status - * code that is most appropriate, and the server we were processing. - * - * @param operation - * The operation being performed - * @param reason - * The reason that the operation was failed - * @param status - * The http status code that is most appropriate - * @param server - * The server that we were processing - */ - @SuppressWarnings("nls") - public RequestFailedException(String operation, String reason, HttpStatus status, Server server) { - super(operation + ":" + reason); - this.operation = operation; - this.reason = reason; - this.status = status; - this.server = server; - if (server != null) { - this.serverId = server.getId(); - } - } - - /** - * Construct the request failed exception with the operation being performed, reason for the failure, http status - * code that is most appropriate, and the server we were processing. - * - * @param ex - * The exception that we are wrapping - * @param operation - * The operation being performed - * @param reason - * The reason that the operation was failed - * @param status - * The http status code that is most appropriate - * @param server - * The server that we were processing - */ - @SuppressWarnings("nls") - public RequestFailedException(Throwable ex, String operation, String reason, HttpStatus status, Server server) { - super(operation + ":" + reason, ex); - this.operation = operation; - this.reason = reason; - this.status = status; - this.server = server; - if (server != null) { - this.serverId = server.getId(); - } - } - - /** - * @param message - * The error message - * @param cause - * A nested exception - */ - public RequestFailedException(String message, Throwable cause) { - super(message, cause); - } - - /** - * @param message - * The error message - * @param cause - * A nested exception - * @param enableSuppression - * whether or not suppression is enabled or disabled - * @param writableStackTrace - * whether or not the stack trace should be writable - */ - public RequestFailedException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { - super(message, cause, enableSuppression, writableStackTrace); - } - - /** - * @param cause - * the cause (which is saved for later retrieval by the {@link #getCause()} method). (A null value is - * permitted, and indicates that the cause is nonexistent or unknown.) - */ - public RequestFailedException(Throwable cause) { - super(cause); - } - - /** - * @return The operation being performed - */ - public String getOperation() { - return operation; - } - - /** - * @return The reason for the failure - */ - public String getReason() { - return reason; - } - - /** - * @return The server being operated upon - */ - public Server getServer() { - return server; - } - - /** - * @return The id of the server being operated upon - */ - public String getServerId() { - return serverId; - } - - /** - * @return The status code from the operation - */ - public HttpStatus getStatus() { - return status; - } - - /** - * @param operation - * The operation being performed - */ - public void setOperation(String operation) { - this.operation = operation; - } - - /** - * @param reason - * The reason for the failure - */ - public void setReason(String reason) { - this.reason = reason; - } - - /** - * @param server - * The server being operated upon - */ - public void setServer(Server server) { - this.server = server; - if (server != null) { - setServerId(server.getId()); - } - } - - /** - * @param serverId - * The id of the server being operated upon - */ - public void setServerId(String serverId) { - this.serverId = serverId; - } - - /** - * @param status - * The status of the request - */ - public void setStatus(HttpStatus status) { - this.status = status; - } - -} diff --git a/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/openecomp/appc/adapter/restHealthcheck/impl/RestHealthcheckAdapterImpl.java b/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/openecomp/appc/adapter/restHealthcheck/impl/RestHealthcheckAdapterImpl.java deleted file mode 100644 index 37820a63d..000000000 --- a/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/openecomp/appc/adapter/restHealthcheck/impl/RestHealthcheckAdapterImpl.java +++ /dev/null @@ -1,311 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.adapter.restHealthcheck.impl; - -import java.util.Map; -import java.util.Properties; -import org.apache.http.impl.client.CloseableHttpClient; - -import org.onap.appc.Constants; -import org.onap.appc.adapter.restHealthcheck.RestHealthcheckAdapter; -import org.onap.appc.configuration.Configuration; -import org.onap.appc.pool.PoolExtensionException; -import org.onap.appc.util.StructuredPropertyHelper; - - -import com.att.cdp.zones.ImageService; -import com.att.cdp.zones.Provider; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.att.eelf.i18n.EELFResourceManager; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; - -import org.glassfish.grizzly.http.util.HttpStatus; - -import static com.att.eelf.configuration.Configuration.*; - -import org.apache.http.*; -import org.apache.http.client.*; -import org.apache.http.client.methods.*; -import org.apache.http.impl.client.*; -import org.apache.http.util.EntityUtils; -import java.io.IOException; -import java.net.InetAddress; - -public class RestHealthcheckAdapterImpl implements RestHealthcheckAdapter { - - /** - * The constant used to define the adapter name in the mapped diagnostic - * context - */ - - - @SuppressWarnings("nls") - public static final String MDC_ADAPTER = "adapter"; - - /** - * The constant used to define the service name in the mapped diagnostic - * context - */ - @SuppressWarnings("nls") - public static final String MDC_SERVICE = "service"; - - /** - * The constant for the status code for a failed outcome - */ - @SuppressWarnings("nls") - public static final String OUTCOME_FAILURE = "failure"; - - /** - * The constant for the status code for a successful outcome - */ - @SuppressWarnings("nls") - public static final String OUTCOME_SUCCESS = "success"; - - /** - * A constant for the property token "provider" used in the structured - * property specifications - */ - @SuppressWarnings("nls") - public static final String PROPERTY_PROVIDER = "provider"; - - /** - * A constant for the property token "identity" used in the structured - * property specifications - */ - @SuppressWarnings("nls") - public static final String PROPERTY_PROVIDER_IDENTITY = "identity"; - - /** - * A constant for the property token "name" used in the structured property - * specifications - */ - @SuppressWarnings("nls") - public static final String PROPERTY_PROVIDER_NAME = "name"; - - /** - * A constant for the property token "tenant" used in the structured - * property specifications - */ - @SuppressWarnings("nls") - public static final String PROPERTY_PROVIDER_TENANT = "tenant"; - - /** - * A constant for the property token "tenant name" used in the structured - * property specifications - */ - @SuppressWarnings("nls") - public static final String PROPERTY_PROVIDER_TENANT_NAME = "name"; - - /** - * A constant for the property token "password" used in the structured - * property specifications - */ - @SuppressWarnings("nls") - public static final String PROPERTY_PROVIDER_TENANT_PASSWORD = "password"; // NOSONAR - - /** - * A constant for the property token "userid" used in the structured - * property specifications - */ - @SuppressWarnings("nls") - public static final String PROPERTY_PROVIDER_TENANT_USERID = "userid"; - - /** - * A constant for the property token "type" used in the structured property - * specifications - */ - @SuppressWarnings("nls") - public static final String PROPERTY_PROVIDER_TYPE = "type"; - - - @SuppressWarnings("nls") - public static final String PING_SERVICE = "pingServer"; - - /** - * The logger to be used - */ - private static final EELFLogger logger = EELFManager.getInstance().getLogger(RestHealthcheckAdapterImpl.class); - - /** - * The constant for a left parenthesis - */ - private static final char LPAREN = '('; - - /** - * The constant for a new line control code - */ - private static final char NL = '\n'; - - /** - * The constant for a single quote - */ - private static final char QUOTE = '\''; - - /** - * The constant for a right parenthesis - */ - private static final char RPAREN = ')'; - - /** - * The constant for a space - */ - private static final char SPACE = ' '; - - /** - * A reference to the adapter configuration object. - */ - private Configuration configuration; - - /** - * A cache of providers that are predefined. - */ - // private Map providerCache; - - /** - * This default constructor is used as a work around because the activator - * wasnt getting called - */ - /** - * A cache of providers that are predefined. - */ - // private Map providerCache; - - /** - * This default constructor is used as a work around because the activator - * wasnt getting called - */ - public RestHealthcheckAdapterImpl() { - initialize(); - - } - - - public RestHealthcheckAdapterImpl(boolean initialize) { - - if (initialize) { - initialize(); - - } - } - - - public RestHealthcheckAdapterImpl(Properties props) { - initialize(); - - } - - - @Override - public String getAdapterName() { - return configuration.getProperty(Constants.PROPERTY_ADAPTER_NAME); - } - - public void checkHealth(Map params, SvcLogicContext ctx) { - logger.info("VNF rest health check"); - String uri=params.get("VNF.URI"); - String endPoint=params.get("VNF.endpoint"); - String tUrl=uri+"/"+endPoint; - RequestContext rc = new RequestContext(ctx); - rc.isAlive(); - - try(CloseableHttpClient httpClient = HttpClients.createDefault()) { - HttpGet httpGet = new HttpGet(tUrl); - HttpResponse response = null; - response = httpClient.execute(httpGet); - int responseCode=response.getStatusLine().getStatusCode(); - HttpEntity entity = response.getEntity(); - String responseOutput=EntityUtils.toString(entity); - if(responseCode==200) - { - doSuccess(rc,responseCode,responseOutput); - } - else - { - doHealthCheckFailure(rc,responseCode,responseOutput); - } - } catch (Exception ex) { - doFailure(rc, HttpStatus.INTERNAL_SERVER_ERROR_500, ex.toString()); - } - } - - - - - @SuppressWarnings("static-method") - private void doFailure(RequestContext rc, HttpStatus code, String message) { - SvcLogicContext svcLogic = rc.getSvcLogicContext(); - String msg = (message == null) ? code.getReasonPhrase() : message; - if (msg.contains("\n")) { - msg = msg.substring(msg.indexOf("\n")); - } - - String status; - try { - status = Integer.toString(code.getStatusCode()); - } catch (Exception e) { - status = "500"; - } - svcLogic.setStatus(OUTCOME_FAILURE); - svcLogic.setAttribute("healthcheck.result.code", "200"); - svcLogic.setAttribute("healthcheck.result.message", status+" "+msg); - } - - - /** - * @param rc - * The request context that manages the state and recovery of the - * request for the life of its processing. - */ - @SuppressWarnings("static-method") - private void doHealthCheckFailure(RequestContext rc, int code, String message) { - SvcLogicContext svcLogic = rc.getSvcLogicContext(); - String msg = Integer.toString(code)+" "+message; - svcLogic.setAttribute("healthcheck.result.code", "200"); - svcLogic.setAttribute("healthcheck.result.message", msg); - - } - - - @SuppressWarnings("static-method") - private void doSuccess(RequestContext rc, int code, String message) { - SvcLogicContext svcLogic = rc.getSvcLogicContext(); - String msg = Integer.toString(code)+" "+message; - svcLogic.setAttribute("healthcheck.result.code", "400"); - svcLogic.setAttribute("healthcheck.result.message", msg); - - } - - - /** - * initialize the provider adapter by building the context cache - */ - private void initialize() { - - - logger.info("init rest health check adapter!!!!!"); - } - -} diff --git a/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/resources/org/onap/appc/default.properties b/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/resources/org/onap/appc/default.properties new file mode 100644 index 000000000..248aabbd8 --- /dev/null +++ b/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/resources/org/onap/appc/default.properties @@ -0,0 +1,79 @@ +### +# ============LICENSE_START======================================================= +# ONAP : APPC +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Copyright (C) 2017 Amdocs +# ============================================================================= +# 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. +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +# ============LICENSE_END========================================================= +### + +# +# Default properties for the APP-C Provider Adapter +# +# ------------------------------------------------------------------------------------------------- +# +# Define the name and path of any user-provided configuration (bootstrap) file that can be loaded +# to supply configuration options +org.onap.appc.bootstrap.file=appc.properties +org.onap.appc.bootstrap.path=/opt/openecomp/appc/data/properties,${user.home},. + +appc.application.name=APPC + +# +# Define the message resource bundle name to be loaded +org.onap.appc.resources=org/onap/appc/i18n/MessageResources +# +# The name of the adapter. +org.onap.appc.provider.adaptor.name=org.onap.appc.appc_provider_adapter +# +# Set up the logging environment +# +org.onap.appc.logging.file=org/onap/appc/logback.xml +org.onap.appc.logging.path=${user.home};etc;../etc +org.onap.appc.logger=org.onap.appc +org.onap.appc.security.logger=org.onap.appc.security +# +# The minimum and maximum provider/tenant context pool sizes. Min=1 means that as soon +# as the provider/tenant is referenced a Context is opened and added to the pool. Max=0 +# means that the upper bound on the pool is unbounded. +org.onap.appc.provider.min.pool=1 +org.onap.appc.provider.max.pool=0 + +# +# The following properties are used to configure the retry logic for connection to the +# IaaS provider(s). The retry delay property is the amount of time, in seconds, the +# application waits between retry attempts. The retry limit is the number of retries +# that are allowed before the request is failed. +org.onap.appc.provider.retry.delay = 30 +org.onap.appc.provider.retry.limit = 10 + +# +# The trusted hosts list for SSL access when a certificate is not provided. +# +provider.trusted.hosts=* +# +# The amount of time, in seconds, to wait for a server state change (start->stop, stop->start, etc). +# If the server does not change state to a valid state within the alloted time, the operation +# fails. +org.onap.appc.server.state.change.timeout=300 +# +# The amount of time to wait, in seconds, between subsequent polls to the OpenStack provider +# to refresh the status of a resource we are waiting on. +# +org.onap.appc.openstack.poll.interval=20 +# diff --git a/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/resources/org/openecomp/appc/default.properties b/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/resources/org/openecomp/appc/default.properties deleted file mode 100644 index 248aabbd8..000000000 --- a/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/resources/org/openecomp/appc/default.properties +++ /dev/null @@ -1,79 +0,0 @@ -### -# ============LICENSE_START======================================================= -# ONAP : APPC -# ================================================================================ -# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. -# ================================================================================ -# Copyright (C) 2017 Amdocs -# ============================================================================= -# 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. -# -# ECOMP is a trademark and service mark of AT&T Intellectual Property. -# ============LICENSE_END========================================================= -### - -# -# Default properties for the APP-C Provider Adapter -# -# ------------------------------------------------------------------------------------------------- -# -# Define the name and path of any user-provided configuration (bootstrap) file that can be loaded -# to supply configuration options -org.onap.appc.bootstrap.file=appc.properties -org.onap.appc.bootstrap.path=/opt/openecomp/appc/data/properties,${user.home},. - -appc.application.name=APPC - -# -# Define the message resource bundle name to be loaded -org.onap.appc.resources=org/onap/appc/i18n/MessageResources -# -# The name of the adapter. -org.onap.appc.provider.adaptor.name=org.onap.appc.appc_provider_adapter -# -# Set up the logging environment -# -org.onap.appc.logging.file=org/onap/appc/logback.xml -org.onap.appc.logging.path=${user.home};etc;../etc -org.onap.appc.logger=org.onap.appc -org.onap.appc.security.logger=org.onap.appc.security -# -# The minimum and maximum provider/tenant context pool sizes. Min=1 means that as soon -# as the provider/tenant is referenced a Context is opened and added to the pool. Max=0 -# means that the upper bound on the pool is unbounded. -org.onap.appc.provider.min.pool=1 -org.onap.appc.provider.max.pool=0 - -# -# The following properties are used to configure the retry logic for connection to the -# IaaS provider(s). The retry delay property is the amount of time, in seconds, the -# application waits between retry attempts. The retry limit is the number of retries -# that are allowed before the request is failed. -org.onap.appc.provider.retry.delay = 30 -org.onap.appc.provider.retry.limit = 10 - -# -# The trusted hosts list for SSL access when a certificate is not provided. -# -provider.trusted.hosts=* -# -# The amount of time, in seconds, to wait for a server state change (start->stop, stop->start, etc). -# If the server does not change state to a valid state within the alloted time, the operation -# fails. -org.onap.appc.server.state.change.timeout=300 -# -# The amount of time to wait, in seconds, between subsequent polls to the OpenStack provider -# to refresh the status of a resource we are waiting on. -# -org.onap.appc.openstack.poll.interval=20 -# -- cgit 1.2.3-korg