diff options
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src/main')
14 files changed, 552 insertions, 105 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Constants.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Constants.java index fe105a7637..d824696147 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Constants.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Constants.java @@ -49,4 +49,6 @@ public class Constants { public final static String VNF_REQUEST_SCOPE = "vnf"; public final static String SERVICE_INSTANCE_PATH = "/serviceInstances"; public final static String SERVICE_INSTANTIATION_PATH = "/serviceInstantiation"; + public final static String ORCHESTRATION_REQUESTS_PATH = "/orchestrationRequests"; + } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/GlobalHealthcheckHandler.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/GlobalHealthcheckHandler.java index 7a8035ac63..70603e5911 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/GlobalHealthcheckHandler.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/GlobalHealthcheckHandler.java @@ -20,6 +20,13 @@ package org.onap.so.apihandlerinfra; + +import java.net.URI; +import java.util.Collections; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; + +import javax.annotation.PostConstruct; import javax.transaction.Transactional; import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; @@ -29,42 +36,190 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.core.Context; import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriBuilder; +import java.util.UUID; import org.apache.http.HttpStatus; import org.onap.so.logger.MessageEnum; import org.onap.so.logger.MsoLogger; -import org.onap.so.utils.UUIDChecker; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.env.Environment; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; import org.springframework.stereotype.Component; - +import org.springframework.web.client.RestTemplate; +import org.springframework.http.HttpMethod; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; - @Component @Path("/globalhealthcheck") @Api(value="/globalhealthcheck",description="APIH Infra Global Health Check") public class GlobalHealthcheckHandler { + private static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.APIH, GlobalHealthcheckHandler.class); + private static final String CONTEXTPATH_PROPERTY = "management.context-path"; + private static final String PROPERTY_DOMAIN = "mso.health.endpoints"; + private static final String CATALOGDB_PROPERTY = PROPERTY_DOMAIN+".catalogdb"; + private static final String REQUESTDB_PROPERTY = PROPERTY_DOMAIN+".requestdb"; + private static final String SDNC_PROPERTY = PROPERTY_DOMAIN+".sdnc"; + private static final String OPENSTACK_PROPERTY = PROPERTY_DOMAIN+".openstack"; + private static final String BPMN_PROPERTY = PROPERTY_DOMAIN+".bpmn"; + private static final String ASDC_PROPERTY = PROPERTY_DOMAIN+".asdc"; + private static final String REQUESTDBATTSVC_PROPERTY = PROPERTY_DOMAIN+".requestdbattsvc"; + private static final String DEFAULT_PROPERTY_VALUE = ""; + + // e.g. /manage + private String actuatorContextPath; + private String endpointCatalogdb; + private String endpointRequestdb; + private String endpointSdnc; + private String endpointOpenstack; + private String endpointBpmn; + private String endpointAsdc; + private String endpointRequestdbAttsvc; + + @Autowired + private Environment env; - private static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.APIH,GlobalHealthcheckHandler.class); - private static final String CHECK_HTML = "<!DOCTYPE html><html><head><meta charset=\"ISO-8859-1\"><title>Health Check</title></head><body>Application ready</body></html>"; + @Autowired + private RestTemplate restTemplate; + private final String health = "/health"; - public static final Response HEALTH_CHECK_RESPONSE = Response.status (HttpStatus.SC_OK) - .entity (CHECK_HTML) - .build (); + + @PostConstruct + protected void init() { + actuatorContextPath = env.getProperty(CONTEXTPATH_PROPERTY, String.class, DEFAULT_PROPERTY_VALUE); + endpointCatalogdb = env.getProperty(CATALOGDB_PROPERTY, String.class, DEFAULT_PROPERTY_VALUE); + endpointRequestdb = env.getProperty(REQUESTDB_PROPERTY, String.class, DEFAULT_PROPERTY_VALUE); + endpointSdnc = env.getProperty(SDNC_PROPERTY, String.class, DEFAULT_PROPERTY_VALUE); + endpointOpenstack = env.getProperty(OPENSTACK_PROPERTY, String.class, DEFAULT_PROPERTY_VALUE); + endpointBpmn = env.getProperty(BPMN_PROPERTY, String.class, DEFAULT_PROPERTY_VALUE); + endpointAsdc = env.getProperty(ASDC_PROPERTY, String.class, DEFAULT_PROPERTY_VALUE); + endpointRequestdbAttsvc = env.getProperty(REQUESTDBATTSVC_PROPERTY, String.class, DEFAULT_PROPERTY_VALUE); + } @GET - @Produces("text/html") + @Produces("application/json") @ApiOperation(value="Performing global health check",response=Response.class) @Transactional public Response globalHealthcheck (@DefaultValue("true") @QueryParam("enableBpmn") boolean enableBpmn, @Context ContainerRequestContext requestContext) { - long startTime = System.currentTimeMillis (); - MsoLogger.setServiceName ("GlobalHealthcheck"); - // Generated RequestId - String requestId = requestContext.getProperty("requestId").toString(); - MsoLogger.setLogContext(requestId, null); - msoLogger.info(MessageEnum.APIH_GENERATED_REQUEST_ID, requestId, "", ""); + Response HEALTH_CHECK_RESPONSE = null; + // Build internal response object + HealthcheckResponse rsp = new HealthcheckResponse(); + + try{ + long startTime = System.currentTimeMillis (); + MsoLogger.setServiceName ("GlobalHealthcheck"); + // Generated RequestId + String requestId = requestContext.getProperty("requestId").toString(); + MsoLogger.setLogContext(requestId, null); + msoLogger.info(MessageEnum.APIH_GENERATED_REQUEST_ID, requestId, "", ""); + + // set APIH status, this is the main entry point + rsp.setApih(HealthcheckStatus.UP.toString()); + // set BPMN + rsp.setBpmn(querySubsystemHealth(MsoSubsystems.BPMN)); + // set SDNCAdapter + rsp.setSdncAdapter(querySubsystemHealth(MsoSubsystems.SDNC)); + // set ASDCController + rsp.setAsdcController(querySubsystemHealth(MsoSubsystems.ASDC)); + // set CatalogDbAdapter + rsp.setCatalogdbAdapter(querySubsystemHealth(MsoSubsystems.CATALOGDB)); + // set RequestDbAdapter + rsp.setRequestdbAdapter(querySubsystemHealth(MsoSubsystems.REQUESTDB)); + // set OpenStackAdapter + rsp.setOpenstackAdapter(querySubsystemHealth(MsoSubsystems.OPENSTACK)); + // set RequestDbAdapterAttSvc + rsp.setRequestdbAdapterAttsvc(querySubsystemHealth(MsoSubsystems.REQUESTDBATT)); + // set Message + rsp.setMessage(String.format("HttpStatus: %s", HttpStatus.SC_OK)); + msoLogger.info(rsp.toString(), "", ""); + + HEALTH_CHECK_RESPONSE = Response.status (HttpStatus.SC_OK) + .entity (rsp) + .build (); + + }catch (Exception ex){ + msoLogger.error(ex); + rsp.setMessage(ex.getMessage()); + HEALTH_CHECK_RESPONSE = Response.status (HttpStatus.SC_INTERNAL_SERVER_ERROR) + .entity (rsp) + .build (); + } + return HEALTH_CHECK_RESPONSE; - } + } + + protected HttpEntity<String> buildHttpEntityForRequest(){ + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + headers.set("Content-Type", "application/json"); + HttpEntity<String> entity = new HttpEntity<>("parameters", headers); + return entity; + } + + protected String querySubsystemHealth(MsoSubsystems subsystem){ + try{ + // get port number for the subsystem + String ept = getEndpointUrlForSubsystemEnum(subsystem); + + // build final endpoint url + UriBuilder builder = UriBuilder.fromPath(ept).path(actuatorContextPath).path(health); + URI uri = builder.build(); + msoLogger.info("Calculated URL: "+uri.toString(), "", ""); + + ResponseEntity<SubsystemHealthcheckResponse> result = + restTemplate.exchange(uri, HttpMethod.GET, buildHttpEntityForRequest(), SubsystemHealthcheckResponse.class); + + return processResponseFromSubsystem(result,subsystem); + + }catch(Exception ex){ + msoLogger.error(ex.getMessage()); + return HealthcheckStatus.DOWN.toString(); + } + } + protected String processResponseFromSubsystem(ResponseEntity<SubsystemHealthcheckResponse> result, MsoSubsystems subsystem){ + if(result == null || result.getStatusCodeValue() != HttpStatus.SC_OK){ + msoLogger.error(String.format("Globalhealthcheck: checking subsystem: %s failed ! result object is: %s", + subsystem, + result == null? "NULL": result)); + return HealthcheckStatus.DOWN.toString(); + } + + SubsystemHealthcheckResponse body = result.getBody(); + + String status = body.getStatus(); + if("UP".equalsIgnoreCase(status)){ + return HealthcheckStatus.UP.toString(); + }else{ + msoLogger.error(subsystem + ", query health endpoint did not return UP status!"); + return HealthcheckStatus.DOWN.toString(); + } + } + + + protected String getEndpointUrlForSubsystemEnum(MsoSubsystems subsystem){ + switch (subsystem){ + case SDNC: + return this.endpointSdnc; + case ASDC: + return this.endpointAsdc; + case BPMN: + return this.endpointBpmn; + case CATALOGDB: + return this.endpointCatalogdb; + case OPENSTACK: + return this.endpointOpenstack; + case REQUESTDB: + return this.endpointRequestdb; + case REQUESTDBATT: + return this.endpointRequestdbAttsvc; + default: + return ""; + } + } } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/HealthcheckResponse.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/HealthcheckResponse.java new file mode 100644 index 0000000000..8f0bbc4e1f --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/HealthcheckResponse.java @@ -0,0 +1,121 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.so.apihandlerinfra; + +import org.apache.commons.lang3.builder.ToStringBuilder; + +public class HealthcheckResponse { + private String apih; + private String bpmn; + private String sdncAdapter; + private String asdcController; + private String catalogdbAdapter; + private String requestdbAdapter; + private String openstackAdapter; + private String requestdbAdapterAttsvc; + private String message = ""; + + public String getApih() { + return apih; + } + + public void setApih(String apih) { + this.apih = apih; + } + + public String getBpmn() { + return bpmn; + } + + public void setBpmn(String bpmn) { + this.bpmn = bpmn; + } + + public String getSdncAdapter() { + return sdncAdapter; + } + + public void setSdncAdapter(String sdncAdapter) { + this.sdncAdapter = sdncAdapter; + } + + public String getAsdcController() { + return asdcController; + } + + public void setAsdcController(String asdcController) { + this.asdcController = asdcController; + } + + public String getCatalogdbAdapter() { + return catalogdbAdapter; + } + + public void setCatalogdbAdapter(String catalogdbAdapter) { + this.catalogdbAdapter = catalogdbAdapter; + } + + public String getRequestdbAdapter() { + return requestdbAdapter; + } + + public void setRequestdbAdapter(String requestdbAdapter) { + this.requestdbAdapter = requestdbAdapter; + } + + public String getOpenstackAdapter() { + return openstackAdapter; + } + + public void setOpenstackAdapter(String openstackAdapter) { + this.openstackAdapter = openstackAdapter; + } + + public String getRequestdbAdapterAttsvc() { + return requestdbAdapterAttsvc; + } + + public void setRequestdbAdapterAttsvc(String requestdbAdapterAttsvc) { + this.requestdbAdapterAttsvc = requestdbAdapterAttsvc; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + @Override + public String toString() { + return new ToStringBuilder(this). + append("apih", this.apih). + append("pbmn", this.bpmn). + append("sdncAdapter", this.sdncAdapter). + append("asdcController", this.asdcController). + append("catalogdbAdapter", this.catalogdbAdapter). + append("requestdbAdapter", this.requestdbAdapter). + append("openstackAdapter", this.openstackAdapter). + append("requestdbAdapterAttsvc", this.requestdbAdapterAttsvc). + append("message", this.message). + toString(); + } +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/HealthcheckStatus.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/HealthcheckStatus.java new file mode 100644 index 0000000000..89c4e0efda --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/HealthcheckStatus.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.so.apihandlerinfra; + +public enum HealthcheckStatus { + UP("UP"), DOWN("DOWN"); + + private String status; + private HealthcheckStatus(String status) { + this.status = status; + } + + @Override + public String toString(){ + return status; + } +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java index 753e712d71..c9f32d9705 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java @@ -23,12 +23,14 @@ package org.onap.so.apihandlerinfra; import java.io.IOException; import java.io.StringWriter; +import java.net.URL; import java.sql.Timestamp; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Optional; import java.util.StringTokenizer; import javax.ws.rs.core.MultivaluedMap; @@ -65,6 +67,7 @@ import org.onap.so.db.request.beans.InfraActiveRequests; import org.onap.so.db.request.client.RequestsDbClient; import org.onap.so.db.request.data.repository.InfraActiveRequestsRepository; import org.onap.so.exceptions.ValidationException; +import org.onap.so.logger.LogConstants; import org.onap.so.logger.MessageEnum; import org.onap.so.logger.MsoLogger; import org.onap.so.serviceinstancebeans.CloudConfiguration; @@ -80,6 +83,7 @@ import org.onap.so.serviceinstancebeans.RequestParameters; import org.onap.so.serviceinstancebeans.Service; import org.onap.so.serviceinstancebeans.ServiceException; import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; +import org.slf4j.MDC; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.w3c.dom.Document; @@ -266,6 +270,7 @@ public class MsoRequest { aq.setRequestId (requestId); aq.setRequestAction(action.toString()); aq.setAction(action.toString()); + aq.setRequestUrl(MDC.get(LogConstants.HTTP_URL)); Timestamp startTimeStamp = new Timestamp (System.currentTimeMillis()); @@ -386,6 +391,7 @@ public class MsoRequest { aq.setRequestId (requestId); aq.setRequestAction(action.name()); aq.setAction(action.name()); + aq.setRequestUrl(MDC.get(LogConstants.HTTP_URL)); Timestamp startTimeStamp = new Timestamp (System.currentTimeMillis()); @@ -429,6 +435,7 @@ public class MsoRequest { request.setRequestBody(requestJSON); Timestamp endTimeStamp = new Timestamp(System.currentTimeMillis()); request.setEndTime(endTimeStamp); + request.setRequestUrl(MDC.get(LogConstants.HTTP_URL)); requestsDbClient.save(request); } catch (Exception e) { msoLogger.error(MessageEnum.APIH_DB_UPDATE_EXC, e.getMessage(), "", "", MsoLogger.ErrorCode.DataError, "Exception when updating record in DB"); @@ -742,4 +749,23 @@ public class MsoRequest { return vnfType; } + + public Optional<URL> buildSelfLinkUrl(String url, String requestId) { + Optional<URL> selfLinkUrl = Optional.empty(); + String version = ""; + try { + URL aUrl = new URL(url); + String aPath = aUrl.getPath(); + if (aPath.indexOf("/v") == -1) { + version = aPath.substring(aPath.indexOf("/V"), aPath.indexOf("/V")+4); + } else { + version = aPath.substring(aPath.indexOf("/v"), aPath.indexOf("/v")+4); + } + String selfLinkPath = Constants.ORCHESTRATION_REQUESTS_PATH.concat(version).concat(requestId); + selfLinkUrl = Optional.of(new URL(aUrl.getProtocol(), aUrl.getHost(), aUrl.getPort(), selfLinkPath)); + } catch (Exception e) { + selfLinkUrl = Optional.empty(); // ignore + } + return selfLinkUrl; + } } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoSubsystems.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoSubsystems.java new file mode 100644 index 0000000000..cfdce473a4 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoSubsystems.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.so.apihandlerinfra; + +public enum MsoSubsystems { + APIH ("API Handler"), + ASDC ("ASDC Controller"), + BPMN ("BPMN Infra"), + CATALOGDB ("CatalogDb Adapter"), + OPENSTACK ("Openstack Adapter"), + REQUESTDB ("RequestDB Adapter"), + REQUESTDBATT ("RequestDB Adapter ATT Svc"), + SDNC ("SDNC Adapter"); + private String subsystem; + private MsoSubsystems(String subsystem){ + this.subsystem = subsystem; + } + + @Override + public String toString(){ + return subsystem; + } + +} + diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java index 50d2639b2d..0c0b70b6dd 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java @@ -270,6 +270,7 @@ public class OrchestrationRequests { request.setRequestId(iar.getRequestId()); request.setRequestScope(iar.getRequestScope()); request.setRequestType(iar.getRequestAction()); + String rollbackStatusMessage = iar.getRollbackStatusMessage(); InstanceReferences ir = new InstanceReferences(); if(iar.getNetworkId() != null) @@ -342,6 +343,10 @@ public class OrchestrationRequests { if(iar.getProgress() != null){ status.setPercentProgress(iar.getProgress().intValue()); } + + if(rollbackStatusMessage != null){ + status.setRollbackStatusMessage(rollbackStatusMessage); + } request.setRequestStatus(status); diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java index 8047893bb4..cb66209fc9 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java @@ -95,6 +95,7 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.io.IOException; +import java.net.URL; import java.sql.Timestamp; import java.util.ArrayList; import java.util.HashMap; @@ -873,6 +874,13 @@ public class ServiceInstances { try { ObjectMapper mapper = new ObjectMapper(); jsonResponse = mapper.readValue(camundaResp.getResponse(), ServiceInstancesResponse.class); + jsonResponse.getRequestReferences().setRequestId(requestId); + Optional<URL> selfLinkUrl = msoRequest.buildSelfLinkUrl(currentActiveReq.getRequestUrl(), requestId); + if(selfLinkUrl.isPresent()){ + jsonResponse.getRequestReferences().setRequestSelfLink(selfLinkUrl.get()); + } else { + jsonResponse.getRequestReferences().setRequestSelfLink(null); + } } catch (IOException e) { msoLogger.error(e); ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_RESPONSE_ERROR, MsoLogger.ErrorCode.SchemaError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/SubsystemHealthcheckResponse.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/SubsystemHealthcheckResponse.java new file mode 100644 index 0000000000..625df66d2a --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/SubsystemHealthcheckResponse.java @@ -0,0 +1,36 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.so.apihandlerinfra; + +import java.io.Serializable; + +public class SubsystemHealthcheckResponse implements Serializable { + private static final long serialVersionUID = 1L; + private String status; + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/configuration/CatalogDBConfig.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/configuration/CatalogDBConfig.java index f7d719048f..3aa54bdfb3 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/configuration/CatalogDBConfig.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/configuration/CatalogDBConfig.java @@ -25,7 +25,7 @@ import javax.persistence.EntityManagerFactory; import javax.sql.DataSource; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; +import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; import org.springframework.context.annotation.Bean; diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/configuration/RequestDBConfig.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/configuration/RequestDBConfig.java index 2298ccdb26..908b864536 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/configuration/RequestDBConfig.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/configuration/RequestDBConfig.java @@ -25,7 +25,7 @@ import javax.persistence.EntityManagerFactory; import javax.sql.DataSource; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; +import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; import org.springframework.context.annotation.Bean; diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/helpers/SDCClientHelper.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/helpers/SDCClientHelper.java index 804eb696cb..8a4d561fbd 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/helpers/SDCClientHelper.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/helpers/SDCClientHelper.java @@ -7,9 +7,9 @@ * 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. @@ -20,6 +20,9 @@ package org.onap.so.apihandlerinfra.tenantisolation.helpers; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; import java.util.UUID; import javax.ws.rs.core.Response; @@ -32,13 +35,11 @@ import org.onap.so.apihandler.common.ErrorNumbers; import org.onap.so.apihandlerinfra.exceptions.ApiException; import org.onap.so.apihandlerinfra.exceptions.ValidateException; import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo; +import org.onap.so.client.HttpClient; import org.onap.so.logger.MessageEnum; import org.onap.so.logger.MsoLogger; -import org.onap.so.rest.APIResponse; -import org.onap.so.rest.RESTClient; -import org.onap.so.rest.RESTConfig; -import org.onap.so.rest.RESTException; import org.onap.so.utils.CryptoUtils; +import org.onap.so.utils.TargetEntity; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -47,12 +48,12 @@ public class SDCClientHelper { private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.APIH, SDCClientHelper.class); private static final String SDC_CONTENT_TYPE = "application/json"; - private static final String SDC_ACCEPT_TYPE = "application/json"; + private static final String SDC_ACCEPT_TYPE = "application/json"; private static String PARTIAL_SDC_URI = "/sdc/v1/catalog/services/"; - + private static String MESSAGE_UNDEFINED_ERROR = "Undefined Error Message!"; - private static String MESSAGE_UNEXPECTED_FORMAT = "Unexpected response format from SDC."; - + private static String MESSAGE_UNEXPECTED_FORMAT = "Unexpected response format from SDC."; + @Value("${mso.sdc.endpoint}") private String sdcEndpoint; @Value("${mso.sdc.activate.userid}") @@ -63,23 +64,23 @@ public class SDCClientHelper { private String sdcClientAuth; @Value("${mso.msoKey}") private String msoKey; - + /** * Send POST request to SDC for operational activation * @param serviceModelVersionI - String * @param operationalEnvironmentId - String - * @param workloadContext - String + * @param workloadContext - String * @return sdcResponseJsonObj - JSONObject object - * @throws JSONException - */ + * @throws JSONException + */ public JSONObject postActivateOperationalEnvironment(String serviceModelVersionId, String operationalEnvironmentId, String workloadContext) throws ApiException { JSONObject sdcResponseJsonObj = new JSONObject(); - + try { - String url = this.buildUriBuilder(serviceModelVersionId, operationalEnvironmentId); + String urlString = this.buildUriBuilder(serviceModelVersionId, operationalEnvironmentId); String jsonPayload = this.buildJsonWorkloadContext(workloadContext); String basicAuthCred = getBasicAuth(); - + if ( basicAuthCred == null || "".equals(basicAuthCred) ) { ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, MsoLogger.ErrorCode.BusinessProcesssError).build(); ValidateException validateException = new ValidateException.Builder(" SDC credentials 'mso.sdc.client.auth' not setup in properties file!", @@ -87,148 +88,135 @@ public class SDCClientHelper { throw validateException; } - - RESTConfig config = new RESTConfig(url); - RESTClient client = setRestClient(config); - client.addAuthorizationHeader(basicAuthCred); - - APIResponse apiResponse = setHttpPostResponse(client, jsonPayload); - int statusCode = apiResponse.getStatusCode(); - - String responseData = apiResponse.getResponseBodyAsString(); + + URL url = new URL(urlString); + + HttpClient httpClient = new HttpClient(url, "application/json", TargetEntity.SDC); + httpClient.addBasicAuthHeader(sdcClientAuth, msoKey); + + Response apiResponse = setHttpPostResponse(httpClient, jsonPayload); + int statusCode = apiResponse.getStatus();; + + String responseData = apiResponse.readEntity(String.class); sdcResponseJsonObj = enhanceJsonResponse(new JSONObject(responseData), statusCode); - + } catch (Exception ex) { msoLogger.debug("calling SDC Exception message: " + ex.getMessage()); String errorMessage = " Encountered Error while calling SDC POST Activate. " + ex.getMessage(); msoLogger.debug(errorMessage); - sdcResponseJsonObj.put("statusCode", String.valueOf(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode())); - sdcResponseJsonObj.put("messageId", ""); + sdcResponseJsonObj.put("statusCode", String.valueOf(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode())); + sdcResponseJsonObj.put("messageId", ""); sdcResponseJsonObj.put("message", errorMessage); } return sdcResponseJsonObj; } - - /** - * set RESTClient - * @param config - RESTConfig object - * @return client - RestClient object - */ - public RESTClient setRestClient(RESTConfig config) throws Exception { - RESTClient client = new RESTClient(config).addHeader("X-ECOMP-InstanceID", sdcActivateInstanceId) - .addHeader("X-ECOMP-RequestID", UUID.randomUUID().toString()) - .addHeader("Content-Type", SDCClientHelper.SDC_CONTENT_TYPE) - .addHeader("Accept", SDCClientHelper.SDC_ACCEPT_TYPE) - .addHeader("USER_ID", sdcActivateUserId); - return client; - } - + /** - * set HttpPostResponse + * set HttpPostResponse * @param config - RESTConfig object * @param jsonPayload - String * @return client - RestClient object - */ - public APIResponse setHttpPostResponse(RESTClient client, String jsonPayload) throws ApiException { + */ + public Response setHttpPostResponse(HttpClient client, String jsonPayload) throws ApiException { try { - return client.httpPost(jsonPayload); - }catch(RESTException ex){ + return client.post(jsonPayload); + }catch(Exception ex){ ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, MsoLogger.ErrorCode.BusinessProcesssError).build(); ValidateException validateException = new ValidateException.Builder("Bad request could not post payload", HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(ex).errorInfo(errorLoggerInfo).build(); throw validateException; } - } - + } + /** - * enhance Response + * enhance Response * @param sdcResponseJsonObj - JSONObject object * @param statusCode - int * @return enhancedAsdcResponseJsonObj - JSONObject object - */ + */ public JSONObject enhanceJsonResponse(JSONObject sdcResponseJsonObj, int statusCode) throws JSONException { JSONObject enhancedAsdcResponseJsonObj = new JSONObject(); String message = ""; - String messageId = ""; - + String messageId = ""; + if (statusCode == Response.Status.ACCEPTED.getStatusCode()) { // Accepted - enhancedAsdcResponseJsonObj.put("distributionId", sdcResponseJsonObj.get("distributionId")); + enhancedAsdcResponseJsonObj.put("distributionId", sdcResponseJsonObj.get("distributionId")); enhancedAsdcResponseJsonObj.put("statusCode", Integer.toString(statusCode)); enhancedAsdcResponseJsonObj.put("messageId", ""); - enhancedAsdcResponseJsonObj.put("message", "Success"); - + enhancedAsdcResponseJsonObj.put("message", "Success"); + } else { // error if (sdcResponseJsonObj.has("requestError") ) { JSONObject requestErrorObj = sdcResponseJsonObj.getJSONObject("requestError"); if (sdcResponseJsonObj.getJSONObject("requestError").has("serviceException") ) { message = requestErrorObj.getJSONObject("serviceException").getString("text"); messageId = requestErrorObj.getJSONObject("serviceException").getString("messageId"); - } + } if (sdcResponseJsonObj.getJSONObject("requestError").has("policyException") ) { message = requestErrorObj.getJSONObject("policyException").getString("text"); messageId = requestErrorObj.getJSONObject("policyException").getString("messageId"); } - enhancedAsdcResponseJsonObj.put("statusCode", Integer.toString(statusCode)); + enhancedAsdcResponseJsonObj.put("statusCode", Integer.toString(statusCode)); enhancedAsdcResponseJsonObj.put("messageId", messageId); enhancedAsdcResponseJsonObj.put("message", message); - } else { + } else { // unexpected format - enhancedAsdcResponseJsonObj.put("statusCode", String.valueOf(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode())); + enhancedAsdcResponseJsonObj.put("statusCode", String.valueOf(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode())); enhancedAsdcResponseJsonObj.put("messageId", MESSAGE_UNDEFINED_ERROR); enhancedAsdcResponseJsonObj.put("message", MESSAGE_UNEXPECTED_FORMAT); } } return enhancedAsdcResponseJsonObj; - + } - + /** - * Build Uri + * Build Uri * @param serviceModelVersionId - String * @param operationalEnvironmentId - String * @return uriBuilder - String - */ + */ public String buildUriBuilder(String serviceModelVersionId, String operationalEnvironmentId) { String path = serviceModelVersionId + "/distribution/" + operationalEnvironmentId +"/activate"; UriBuilder uriBuilder = UriBuilder.fromPath(sdcEndpoint + SDCClientHelper.PARTIAL_SDC_URI) .path(path); return uriBuilder.build().toString(); } - + /** - * Build JSON context + * Build JSON context * @param workloadContext - String * @return String json - * @throws JSONException - */ + * @throws JSONException + */ public String buildJsonWorkloadContext(String workloadContext) throws JSONException { return new JSONObject().put("workloadContext", workloadContext).toString(); - + } - + /** - * decrypt value + * decrypt value * @param toDecrypt - String * @param msokey - String * @return result - String - */ + */ public synchronized String decrypt(String toDecrypt, String msokey){ String result = null; try { result = CryptoUtils.decrypt(toDecrypt, msokey); - + } catch (Exception e) { msoLogger.debug("Failed to decrypt credentials: " + toDecrypt, e); } return result; } - + private String getBasicAuth() { return decrypt(sdcClientAuth, msoKey); } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/resources/application-local.yaml b/mso-api-handlers/mso-api-handler-infra/src/main/resources/application-local.yaml index acc04061cf..cabee8e8f7 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/resources/application-local.yaml +++ b/mso-api-handlers/mso-api-handler-infra/src/main/resources/application-local.yaml @@ -17,6 +17,16 @@ camunda-nodehealthcheck-urn: /mso/nodehealthcheck mso: + health: + endpoints: + catalogdb: http://localhost:8800 + sdnc: http://localhost:8400 + openstack: http://localhost:8300 + requestdb: http://localhost:8700 + bpmn: http://localhost:8200 + asdc: http://localhost:8400 + requestdbattsvc: http://localhost:8600 + adapters: requestDb: auth: Basic YnBlbDptc28tZGItMTUwNyE= @@ -45,16 +55,16 @@ mso: homing: sdna: url: http://localhost:8089/ - password: 4112B789E942B161228F7D5AFC654C0F + password: 4E0BDC08EE8EDC0572ABBE9FD2D59B62DB725A00B8469E39393D6C86D64284C5D34A57D56F7B58C375316F camundaURL: http://localhost:8089/ - camundaAuth: F8E9452B55DDE4CCE77547B0E748105C54CF5EF1351B4E2CBAABF2981EFE776D + camundaAuth: E8E19DD16CC90D2E458E8FF9A884CC0452F8F3EB8E321F96038DE38D5C1B0B02DFAE00B88E2CF6E2A4101AB2C011FC161212EE async: core-pool-size: 50 max-pool-size: 50 queue-capacity: 500 sdc: client: - auth: F3473596C526938329DF877495B494DC374D1C4198ED3AD305EA3ADCBBDA1862 + auth: 97FF88AB352DA16E00DDD81E3876431DEF8744465DACA489EB3B3BE1F10F63EDA1715E626D0A4827A3E19CD88421BF activate: instanceid: test userid: cs0008 @@ -66,7 +76,7 @@ mso: count: 3 aai: endpoint: http://localhost:28090 - auth: 26AFB797A6A57960D5D718491925C50F77CDC22AC394B3DBA09950D8FD1C0764 + auth: 5E12ACACBD552A415E081E29F2C4772F9835792A51C766CCFDD7433DB5220B59969CB2798C grm: endpoint: http://localhost:28090 username: gmruser @@ -108,7 +118,7 @@ volume: # H2 spring: datasource: - url: jdbc:h2:mem:AZ;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE + jdbc-url: jdbc:h2:mem:AZ;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE username: sa password: sa driver-class-name: org.h2.Driver @@ -151,7 +161,7 @@ spring: role: ACTUATOR request: datasource: - url: jdbc:h2:mem:AZ;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE + jdbc-url: jdbc:h2:mem:AZ;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE username: sa password: sa driver-class-name: org.h2.Driver @@ -159,4 +169,11 @@ request: #Actuator management: - context-path: /manage
\ No newline at end of file + context-path: /manage + +org: + onap: + so: + adapters: + network: + encryptionKey: aa3871669d893c7fb8abbcda31b88b4f diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/resources/application.yaml b/mso-api-handlers/mso-api-handler-infra/src/main/resources/application.yaml index 52bf3ffb87..9387d08c84 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/resources/application.yaml +++ b/mso-api-handlers/mso-api-handler-infra/src/main/resources/application.yaml @@ -27,7 +27,7 @@ mso: spring: datasource: - url: jdbc:mariadb://${DB_HOST}:${DB_PORT}/catalogdb + jdbc-url: jdbc:mariadb://${DB_HOST}:${DB_PORT}/catalogdb username: ${DB_USERNAME} password: ${DB_PASSWORD} driver-class-name: org.mariadb.jdbc.Driver @@ -49,7 +49,7 @@ spring: request: datasource: - url: jdbc:mariadb://${DB_HOST}:${DB_PORT}/requestdb + jdbc-url: jdbc:mariadb://${DB_HOST}:${DB_PORT}/requestdb username: ${DB_USERNAME} password: ${DB_PASSWORD} driver-class-name: org.mariadb.jdbc.Driver @@ -60,11 +60,24 @@ request: test-on-borrow: true #Actuator -management: - context-path: /manage +management: + endpoints: + web: + base-path: /manage + server: + servlet: + context-path: /manage metrics: se-global-registry: false export: prometheus: enabled: true # Whether exporting of metrics to Prometheus is enabled. step: 1m # Step size (i.e. reporting frequency) to use. + + +org: + onap: + so: + adapters: + network: + encryptionKey: aa3871669d893c7fb8abbcda31b88b4f
\ No newline at end of file |