diff options
Diffstat (limited to 'adapters/mso-requests-db-adapter/src/main/java/org/onap')
11 files changed, 1073 insertions, 0 deletions
diff --git a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/ArchiveInfraRequestsScheduler.java b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/ArchiveInfraRequestsScheduler.java new file mode 100644 index 0000000000..9a7382f200 --- /dev/null +++ b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/ArchiveInfraRequestsScheduler.java @@ -0,0 +1,156 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 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.adapters.requestsdb; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; + +import org.onap.so.db.request.beans.ArchivedInfraRequests; +import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.db.request.data.repository.ArchivedInfraRequestsRepository; +import org.onap.so.db.request.data.repository.InfraActiveRequestsRepository; +import org.onap.so.logger.MessageEnum; +import org.onap.so.logger.MsoLogger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.domain.PageRequest; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import net.javacrumbs.shedlock.core.SchedulerLock; + +@Component +public class ArchiveInfraRequestsScheduler { + + private static MsoLogger logger = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA, ArchiveInfraRequestsScheduler.class); + + @Autowired + private InfraActiveRequestsRepository infraActiveRepo; + @Autowired + private ArchivedInfraRequestsRepository archivedInfraRepo; + + @Value("${mso.infra-requests.archived.period}") + private int archivedPeriod; + + /** + * Runs the scheduler nightly + * [Seconds] [Minutes] [Hours] [Day of month] [Month] [Day of week] [Year] + */ + @Scheduled(cron="0 0 1 * * ?") + @SchedulerLock(name = "archiveInfraRequestsScheduler") + public void infraRequestsScheduledTask() { + logger.debug("Start of archiveInfraRequestsScheduler"); + + Date currentDate= new Date(); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(currentDate); + calendar.add(Calendar.DATE, -archivedPeriod); + Date archivingDate = calendar.getTime(); + + logger.debug("Date before 6 months: "+ (calendar.get(Calendar.MONTH) + 1) + "-" + + calendar.get(Calendar.DATE) + "-" + calendar.get(Calendar.YEAR)); + + List<InfraActiveRequests> requestsByEndTime = new ArrayList<>(); + PageRequest pageRequest = new PageRequest(0, 100); + do { + requestsByEndTime = infraActiveRepo.findByEndTimeLessThan(archivingDate, pageRequest); + logger.debug(requestsByEndTime.size() + " requests to be archived based on End Time" ); + archiveInfraRequests(requestsByEndTime); + } while(requestsByEndTime.size() > 0); + + List<InfraActiveRequests> requestsByStartTime = new ArrayList<>(); + do { + requestsByStartTime = infraActiveRepo.findByStartTimeLessThanAndEndTime(archivingDate, null, pageRequest); + logger.debug(requestsByEndTime.size() + " requests to be archived based on Start Time" ); + archiveInfraRequests(requestsByStartTime); + } while(requestsByStartTime.size() > 0); + + logger.debug("End of archiveInfraRequestsScheduler"); + } + + protected void archiveInfraRequests(List<InfraActiveRequests> requests) { + List<ArchivedInfraRequests> newArchivedReqs = new ArrayList<>(); + List<InfraActiveRequests> oldInfraReqs = new ArrayList<>(); + + for(InfraActiveRequests iar: requests) { + ArchivedInfraRequests archivedInfra = new ArchivedInfraRequests(); + try { + archivedInfra.setAaiServiceId(iar.getAaiServiceId()); + archivedInfra.setAction(iar.getAction()); + archivedInfra.setAicCloudRegion(iar.getAicCloudRegion()); + archivedInfra.setAicNodeClli(iar.getAicNodeClli()); + archivedInfra.setCallBackUrl(iar.getCallBackUrl()); + archivedInfra.setClientRequestId(iar.getClientRequestId()); + archivedInfra.setConfigurationId(iar.getConfigurationId()); + archivedInfra.setConfigurationName(iar.getConfigurationName()); + archivedInfra.setCorrelator(iar.getCorrelator()); + archivedInfra.setEndTime(iar.getEndTime()); + archivedInfra.setLastModifiedBy(iar.getLastModifiedBy()); + archivedInfra.setNetworkId(iar.getNetworkId()); + archivedInfra.setNetworkName(iar.getNetworkName()); + archivedInfra.setNetworkType(iar.getNetworkType()); + archivedInfra.setOperationalEnvId(iar.getOperationalEnvId()); + archivedInfra.setOperationalEnvName(iar.getOperationalEnvName()); + archivedInfra.setProgress(iar.getProgress()); + archivedInfra.setProvStatus(iar.getProvStatus()); + archivedInfra.setRequestAction(iar.getRequestAction()); + archivedInfra.setRequestBody(iar.getRequestBody()); + archivedInfra.setRequestId(iar.getRequestId()); + archivedInfra.setRequestorId(iar.getRequestorId()); + archivedInfra.setRequestScope(iar.getRequestScope()); + archivedInfra.setRequestStatus(iar.getRequestStatus()); + archivedInfra.setRequestType(iar.getRequestType()); + archivedInfra.setResponseBody(iar.getResponseBody()); + archivedInfra.setServiceInstanceId(iar.getServiceInstanceId()); + archivedInfra.setServiceInstanceName(iar.getServiceInstanceName()); + archivedInfra.setServiceType(iar.getServiceType()); + archivedInfra.setSource(iar.getSource()); + archivedInfra.setStartTime(iar.getStartTime()); + archivedInfra.setStatusMessage(iar.getStatusMessage()); + archivedInfra.setTenantId(iar.getTenantId()); + archivedInfra.setVfModuleId(iar.getVfModuleId()); + archivedInfra.setVfModuleModelName(iar.getVfModuleModelName()); + archivedInfra.setVfModuleName(iar.getVfModuleName()); + archivedInfra.setVnfId(iar.getVnfId()); + archivedInfra.setVnfName(iar.getVnfName()); + archivedInfra.setVnfOutputs(iar.getVnfOutputs()); + archivedInfra.setVnfParams(iar.getVnfParams()); + archivedInfra.setVnfType(iar.getVnfType()); + archivedInfra.setVolumeGroupId(iar.getVolumeGroupId()); + archivedInfra.setVolumeGroupName(iar.getVolumeGroupName()); + + newArchivedReqs.add(archivedInfra); + oldInfraReqs.add(iar); + } catch(Exception e) { + logger.error(e); + logger.error(MessageEnum.RA_GENERAL_EXCEPTION, "", "", MsoLogger.ErrorCode.UnknownError, e.getMessage()); + } + } + + logger.info("Creating archivedInfraRequest records: " + newArchivedReqs.size()); + archivedInfraRepo.save(newArchivedReqs); + + logger.info("Deleting InfraActiveRequest records: "+ oldInfraReqs.size()); + infraActiveRepo.delete(oldInfraReqs); + } +} diff --git a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/MsoRequestsDbAdapter.java b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/MsoRequestsDbAdapter.java new file mode 100644 index 0000000000..e28bdb2f96 --- /dev/null +++ b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/MsoRequestsDbAdapter.java @@ -0,0 +1,102 @@ +/*- + * ============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.adapters.requestsdb; + +import javax.jws.WebMethod; +import javax.jws.WebParam; +import javax.jws.WebService; +import javax.xml.bind.annotation.XmlElement; + +import org.onap.so.adapters.requestsdb.exceptions.MsoRequestsDbException; +import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.db.request.beans.ResourceOperationStatus; + +/** + * MSO Request DB Adapter Web Service + */ +@WebService(name = "RequestsDbAdapter", targetNamespace = "http://org.onap.so/requestsdb") +public interface MsoRequestsDbAdapter { + + @WebMethod + public void updateInfraRequest(@WebParam(name = "requestId") @XmlElement(required = true) String requestId, + @WebParam(name = "lastModifiedBy") @XmlElement(required = true) String lastModifiedBy, + @WebParam(name = "statusMessage") @XmlElement(required = false) String statusMessage, + @WebParam(name = "responseBody") @XmlElement(required = false) String responseBody, + @WebParam(name = "requestStatus") @XmlElement(required = false) RequestStatusType requestStatus, + @WebParam(name = "progress") @XmlElement(required = false) String progress, + @WebParam(name = "vnfOutputs") @XmlElement(required = false) String vnfOutputs, + @WebParam(name = "serviceInstanceId") @XmlElement(required = false) String serviceInstanceId, + @WebParam(name = "networkId") @XmlElement(required = false) String networkId, + @WebParam(name = "vnfId") @XmlElement(required = false) String vnfId, + @WebParam(name = "vfModuleId") @XmlElement(required = false) String vfModuleId, + @WebParam(name = "volumeGroupId") @XmlElement(required = false) String volumeGroupId, + @WebParam(name = "serviceInstanceName") @XmlElement(required = false) String serviceInstanceName, + @WebParam(name = "configurationId") @XmlElement(required = false) String configurationId, + @WebParam(name = "configurationName") @XmlElement(required = false) String configurationName, + @WebParam(name = "vfModuleName") @XmlElement(required = false) String vfModuleName) + throws MsoRequestsDbException; + + @WebMethod + public InfraActiveRequests getInfraRequest( + @WebParam(name = "requestId") @XmlElement(required = true) String requestId) throws MsoRequestsDbException; + + @WebMethod + public boolean getSiteStatus(@WebParam(name = "siteName") @XmlElement(required = true) String siteName); + + @WebMethod + public void updateServiceOperationStatus( + @WebParam(name = "serviceId") @XmlElement(required = true) String serviceId, + @WebParam(name = "operationId") @XmlElement(required = false) String operationId, + @WebParam(name = "operationType") @XmlElement(required = false) String operationType, + @WebParam(name = "userId") @XmlElement(required = false) String userId, + @WebParam(name = "result") @XmlElement(required = false) String result, + @WebParam(name = "operationContent") @XmlElement(required = false) String operationContent, + @WebParam(name = "progress") @XmlElement(required = false) String progress, + @WebParam(name = "reason") @XmlElement(required = false) String reason) throws MsoRequestsDbException; + + @WebMethod + public void initResourceOperationStatus(@WebParam(name = "serviceId") @XmlElement(required = true) String serviceId, + @WebParam(name = "operationId") @XmlElement(required = true) String operationId, + @WebParam(name = "operationType") @XmlElement(required = true) String operationType, + @WebParam(name = "resourceTemplateUUIDs") @XmlElement(required = true) String resourceTemplateUUIDs) + throws MsoRequestsDbException; + + @WebMethod + public ResourceOperationStatus getResourceOperationStatus( + @WebParam(name = "serviceId") @XmlElement(required = true) String serviceId, + @WebParam(name = "operationId") @XmlElement(required = true) String operationId, + @WebParam(name = "resourceTemplateUUID") @XmlElement(required = true) String resourceTemplateUUID) + throws MsoRequestsDbException; + + @WebMethod + public void updateResourceOperationStatus( + @WebParam(name = "serviceId") @XmlElement(required = true) String serviceId, + @WebParam(name = "operationId") @XmlElement(required = true) String operationId, + @WebParam(name = "resourceTemplateUUID") @XmlElement(required = true) String resourceTemplateUUID, + @WebParam(name = "operType") @XmlElement(required = false) String operType, + @WebParam(name = "resourceInstanceID") @XmlElement(required = false) String resourceInstanceID, + @WebParam(name = "jobId") @XmlElement(required = false) String jobId, + @WebParam(name = "status") @XmlElement(required = false) String status, + @WebParam(name = "progress") @XmlElement(required = false) String progress, + @WebParam(name = "errorCode") @XmlElement(required = false) String errorCode, + @WebParam(name = "statusDescription") @XmlElement(required = false) String statusDescription) + throws MsoRequestsDbException; +}
\ No newline at end of file diff --git a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/MsoRequestsDbAdapterImpl.java b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/MsoRequestsDbAdapterImpl.java new file mode 100644 index 0000000000..2f6a5839b7 --- /dev/null +++ b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/MsoRequestsDbAdapterImpl.java @@ -0,0 +1,326 @@ +/*- + * ============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.adapters.requestsdb; + +import java.sql.Timestamp; + +import javax.jws.WebService; +import javax.transaction.Transactional; + +import org.onap.so.adapters.requestsdb.exceptions.MsoRequestsDbException; +import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.db.request.beans.OperationStatus; +import org.onap.so.db.request.beans.ResourceOperationStatus; +import org.onap.so.db.request.beans.ResourceOperationStatusId; +import org.onap.so.db.request.beans.SiteStatus; +import org.onap.so.db.request.data.repository.InfraActiveRequestsRepository; +import org.onap.so.db.request.data.repository.OperationStatusRepository; +import org.onap.so.db.request.data.repository.ResourceOperationStatusRepository; +import org.onap.so.db.request.data.repository.SiteStatusRepository; +import org.onap.so.logger.MessageEnum; +import org.onap.so.logger.MsoLogger; +import org.onap.so.requestsdb.RequestsDbConstant; +import org.onap.so.utils.UUIDChecker; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.stereotype.Component; + +@WebService(serviceName = "RequestsDbAdapter", endpointInterface = "org.onap.so.adapters.requestsdb.MsoRequestsDbAdapter", targetNamespace = "http://org.onap.so/requestsdb") +@Component +@Primary +public class MsoRequestsDbAdapterImpl implements MsoRequestsDbAdapter { + + private static final String SUCCESSFUL = "Successful"; + + private static final String GET_INFRA_REQUEST = "Get Infra request"; + + private static MsoLogger logger = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA, MsoRequestsDbAdapterImpl.class); + + @Autowired + private InfraActiveRequestsRepository infraActive; + + @Autowired + private SiteStatusRepository siteRepo; + + @Autowired + private OperationStatusRepository operationStatusRepository; + + @Autowired + private ResourceOperationStatusRepository resourceOperationStatusRepository; + + @Transactional + @Override + public void updateInfraRequest(String requestId, String lastModifiedBy, String statusMessage, String responseBody, + RequestStatusType requestStatus, String progress, String vnfOutputs, String serviceInstanceId, + String networkId, String vnfId, String vfModuleId, String volumeGroupId, String serviceInstanceName, + String configurationId, String configurationName, String vfModuleName) throws MsoRequestsDbException { + MsoLogger.setLogContext(requestId, serviceInstanceId); + long startTime = System.currentTimeMillis(); + try { + InfraActiveRequests request = infraActive.findOneByRequestIdOrClientRequestId(requestId, requestId); + if (request == null) { + String error = "Entity not found. Unable to retrieve MSO Infra Requests DB for Request ID " + requestId; + throw new MsoRequestsDbException(error); + } + if (statusMessage != null) { + request.setStatusMessage(statusMessage); + } + if (responseBody != null) { + request.setResponseBody(responseBody); + } + if (requestStatus != null) { + request.setRequestStatus(requestStatus.toString()); + } + if (progress != null) { + setProgress(progress, request); + } + if (vnfOutputs != null) { + request.setVnfOutputs(vnfOutputs); + } + if (serviceInstanceId != null) { + request.setServiceInstanceId(serviceInstanceId); + } + if (networkId != null) { + request.setNetworkId(networkId); + } + if (vnfId != null) { + request.setVnfId(vnfId); + } + if (vfModuleId != null) { + request.setVfModuleId(vfModuleId); + } + if (volumeGroupId != null) { + request.setVolumeGroupId(volumeGroupId); + } + if (serviceInstanceName != null) { + request.setServiceInstanceName(serviceInstanceName); + } + if (vfModuleName != null) { + request.setVfModuleName(vfModuleName); + } + if (configurationId != null) { + request.setConfigurationId(configurationId); + } + if (configurationName != null) { + request.setConfigurationName(configurationName); + } + if (requestStatus == RequestStatusType.COMPLETE || requestStatus == RequestStatusType.FAILED) { + Timestamp nowTimeStamp = new Timestamp(System.currentTimeMillis()); + request.setEndTime(nowTimeStamp); + } + request.setLastModifiedBy(lastModifiedBy); + infraActive.save(request); + + } catch (Exception e) { + String error = "Error retrieving MSO Infra Requests DB for Request ID " + requestId; + logger.error("Error " + MsoLogger.ErrorCode.BusinessProcesssError + " for " + GET_INFRA_REQUEST + " - " + MessageEnum.RA_DB_REQUEST_NOT_EXIST + " - " + error, e); + logger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError, error); + throw new MsoRequestsDbException(error, e); + } + logger.recordAuditEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, SUCCESSFUL); + + } + + private void setProgress(String progress, InfraActiveRequests request) { + try { + request.setProgress(Long.parseLong(progress)); + } catch (NumberFormatException e) { + logger.warnSimple("UpdateInfraRequest", "Invalid value sent for progress"); + } + } + + @Override + @Transactional + public InfraActiveRequests getInfraRequest(String requestId) throws MsoRequestsDbException { + long startTime = System.currentTimeMillis(); + MsoLogger.setLogContext(requestId, null); + + logger.debug("Call to MSO Infra RequestsDb adapter get method with request Id: " + requestId); + + InfraActiveRequests request = null; + try { + + request = infraActive.findOneByRequestIdOrClientRequestId(requestId, requestId); + if (request == null) { + String error = "Entity not found. Unable to retrieve MSO Infra Requests DB for Request ID " + requestId; + throw new MsoRequestsDbException(error); + } + } catch (Exception e) { + String error = "Error retrieving MSO Infra Requests DB for Request ID " + requestId; + logger.error("Error " + MsoLogger.ErrorCode.BusinessProcesssError + " for " + GET_INFRA_REQUEST + " - " + MessageEnum.RA_DB_REQUEST_NOT_EXIST + " - " + error, e); + logger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError, error); + throw new MsoRequestsDbException(error, e); + } + logger.recordAuditEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, SUCCESSFUL); + return request; + } + + /** + * Get SiteStatus by SiteName. + * + * @param siteName + * The unique name of the site + * @return Status of that site + */ + @Override + @Transactional + public boolean getSiteStatus(String siteName) { + UUIDChecker.generateUUID(logger); + long startTime = System.currentTimeMillis(); + SiteStatus siteStatus; + logger.debug("Request database - get Site Status with Site name:" + siteName); + + siteStatus = siteRepo.findOneBySiteName(siteName); + if (siteStatus == null) { + // if not exist in DB, it means the site is not disabled, thus + // return true + logger.recordAuditEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, SUCCESSFUL); + return true; + } else { + logger.recordAuditEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, SUCCESSFUL); + return siteStatus.getStatus(); + } + } + + /** + * update operation status <br> + * + * @param serviceId + * @param operationId + * @param operationType + * @param userId + * @param result + * @param operationContent + * @param progress + * @param reason + * @throws MsoRequestsDbException + * @since ONAP Amsterdam Release + */ + @Override + @Transactional + public void updateServiceOperationStatus(String serviceId, String operationId, String operationType, String userId, + String result, String operationContent, String progress, String reason) throws MsoRequestsDbException { + OperationStatus operStatus = operationStatusRepository.findOneByServiceIdAndOperationId(serviceId, operationId); + if (operStatus == null) { + String error = "Entity not found. Unable to retrieve OperationStatus Object ServiceId: " + serviceId + " operationId: " + + operationId; + MsoRequestsDbException e = new MsoRequestsDbException(error); + logger.error("Error "+ MsoLogger.ErrorCode.BusinessProcesssError + " - " + MessageEnum.RA_DB_REQUEST_NOT_EXIST + " - " + error, e); + throw e; + } + + operStatus.setUserId(userId); + operStatus.setOperation(operationType); + operStatus.setReason(reason); + operStatus.setProgress(progress); + operStatus.setResult(result); + operStatus.setOperationContent(operationContent); + operStatus.setResult(result); + operationStatusRepository.save(operStatus); + } + + /** + * init the operation status of all the resources <br> + * + * @param serviceId + * the service Id + * @param operationId + * the operation Id + * @param operationType + * the operationType + * @param resourceTemplateUUIDs + * the resources, the UUID is split by ":" + * @throws MsoRequestsDbException + * @since ONAP Amsterdam Release + */ + @Override + @Transactional + public void initResourceOperationStatus(String serviceId, String operationId, String operationType, + String resourceTemplateUUIDs) throws MsoRequestsDbException { + String[] resourceLst = resourceTemplateUUIDs.split(":"); + for (String resource : resourceLst) { + if ("".equals(resource)) { + continue; + } + ResourceOperationStatus resourceStatus = new ResourceOperationStatus(); + resourceStatus.setOperationId(operationId); + resourceStatus.setServiceId(serviceId); + resourceStatus.setResourceTemplateUUID(resource); + resourceStatus.setOperType(operationType); + resourceStatus.setStatus(RequestsDbConstant.Status.PROCESSING); + resourceStatus.setStatusDescription("Waiting for start"); + resourceOperationStatusRepository.save(resourceStatus); + + } + } + + /** + * get resource operation status <br> + * + * @param serviceId + * @param operationId + * @param resourceTemplateUUID + * @return + * @throws MsoRequestsDbException + * @since ONAP Amsterdam Release + */ + @Override + public ResourceOperationStatus getResourceOperationStatus(String serviceId, String operationId, + String resourceTemplateUUID) throws MsoRequestsDbException { + + return resourceOperationStatusRepository + .findOne(new ResourceOperationStatusId(serviceId, operationId, resourceTemplateUUID)); + } + + /** + * update resource operation status <br> + * + * @param serviceId + * @param operationId + * @param resourceTemplateUUID + * @param operationType + * @param resourceInstanceID + * @param jobId + * @param status + * @param progress + * @param errorCode + * @param statusDescription + * @throws MsoRequestsDbException + * @since ONAP Amsterdam Release + */ + @Override + public void updateResourceOperationStatus(String serviceId, String operationId, String resourceTemplateUUID, + String operationType, String resourceInstanceID, String jobId, String status, String progress, + String errorCode, String statusDescription) throws MsoRequestsDbException { + ResourceOperationStatus resStatus = new ResourceOperationStatus(); + resStatus.setServiceId(serviceId); + resStatus.setOperationId(operationId); + resStatus.setResourceTemplateUUID(resourceTemplateUUID); + resStatus.setOperType(operationType); + resStatus.setResourceInstanceID(resourceInstanceID); + resStatus.setJobId(jobId); + resStatus.setStatus(status); + resStatus.setProgress(progress); + resStatus.setErrorCode(errorCode); + resStatus.setStatusDescription(statusDescription); + resourceOperationStatusRepository.save(resStatus); + } +}
\ No newline at end of file diff --git a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/RequestStatusType.java b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/RequestStatusType.java new file mode 100644 index 0000000000..1d5b892ade --- /dev/null +++ b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/RequestStatusType.java @@ -0,0 +1,70 @@ +/*- + * ============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========================================================= + */ + +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4-2 +// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2015.07.24 at 11:49:17 AM EDT +// + + +package org.onap.so.adapters.requestsdb; + + + +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlType; + + +/** + * <p>Java class for request-status-type. + * + * <p>The following schema fragment specifies the expected content contained within this class. + * <p> + * <pre> + * <simpleType name="request-status-type"> + * <restriction base="{http://www.w3.org/2001/XMLSchema}string"> + * <enumeration value="COMPLETE"/> + * <enumeration value="FAILED"/> + * <enumeration value="IN_PROGRESS"/> + * </restriction> + * </simpleType> + * </pre> + * + */ +@XmlType(name = "request-status-type") +@XmlEnum +public enum RequestStatusType { + + COMPLETE, + FAILED, + IN_PROGRESS, + PENDING_MANUAL_TASK; + + public String value() { + return name(); + } + + public static RequestStatusType fromValue(String v) { + return valueOf(v); + } + +} diff --git a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/ResponseStatus.java b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/ResponseStatus.java new file mode 100644 index 0000000000..5ee7119f35 --- /dev/null +++ b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/ResponseStatus.java @@ -0,0 +1,28 @@ +/*- + * ============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.adapters.requestsdb; + +/* + * Enum for Status values returned by API Handler to Tail-F +*/ +public enum ResponseStatus { + SENDING_FINAL_NOTIFY, SUCCESS, FAILED, TIMEOUT +}
\ No newline at end of file diff --git a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/WebSecurityConfigImpl.java b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/WebSecurityConfigImpl.java new file mode 100644 index 0000000000..9f52160c8e --- /dev/null +++ b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/WebSecurityConfigImpl.java @@ -0,0 +1,51 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 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.adapters.requestsdb; + +import org.onap.so.security.MSOSpringFirewall; +import org.onap.so.security.WebSecurityConfig; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.builders.WebSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.web.firewall.StrictHttpFirewall; +import org.springframework.util.StringUtils; + +@EnableWebSecurity +public class WebSecurityConfigImpl extends WebSecurityConfig { + + @Override + protected void configure(HttpSecurity http) throws Exception { + http.csrf().disable() + .authorizeRequests() + .antMatchers("/manage/health","/manage/info").permitAll() + .antMatchers("/**").hasAnyRole(StringUtils.collectionToDelimitedString(getRoles(),",").toString()) + .and() + .httpBasic(); + } + + @Override + public void configure(WebSecurity web) throws Exception { + super.configure(web); + StrictHttpFirewall firewall = new MSOSpringFirewall(); + web.httpFirewall(firewall); + } + +} diff --git a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/application/CXFConfiguration.java b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/application/CXFConfiguration.java new file mode 100644 index 0000000000..a7e9cab6ba --- /dev/null +++ b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/application/CXFConfiguration.java @@ -0,0 +1,78 @@ +/*- + * ============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.adapters.requestsdb.application; + +import javax.xml.ws.Endpoint; + +import org.apache.cxf.Bus; +import org.apache.cxf.feature.LoggingFeature; +import org.apache.cxf.jaxrs.swagger.Swagger2Feature; +import org.apache.cxf.jaxws.EndpointImpl; +import org.apache.cxf.transport.servlet.CXFServlet; +import org.onap.so.adapters.requestsdb.MsoRequestsDbAdapter; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.web.servlet.ServletRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + + +@Configuration +public class CXFConfiguration { + + @Autowired + private Bus bus; + + @Autowired + private MsoRequestsDbAdapter requestDbAdapterImpl; + + + + @Bean + public ServletRegistrationBean cxfServlet() { + + return new ServletRegistrationBean(new CXFServlet(), "/services/*"); + } + + @Bean + public Endpoint requestEndpointk() { + EndpointImpl endpoint = new EndpointImpl(bus, requestDbAdapterImpl); + endpoint.publish("/RequestsDbAdapter"); + LoggingFeature logFeature = new LoggingFeature(); + logFeature.setPrettyLogging(true); + logFeature.initialize(bus); + endpoint.getFeatures().add(logFeature); + return endpoint; + } + + @Bean + public Swagger2Feature createSwaggerFeature() { + Swagger2Feature swagger2Feature = new Swagger2Feature(); + swagger2Feature.setPrettyPrint(true); + swagger2Feature.setTitle("SO Request Adapter"); + swagger2Feature.setContact("The ONAP SO team"); + swagger2Feature.setDescription("This project is the SO Orchestration Engine"); + swagger2Feature.setVersion("1.0.0"); + swagger2Feature.setResourcePackage("org.onap.so.adapters.requestdb"); + swagger2Feature.setScan(true); + return swagger2Feature; + } + +} diff --git a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/application/MSORequestDBApplication.java b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/application/MSORequestDBApplication.java new file mode 100644 index 0000000000..21582a1e5f --- /dev/null +++ b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/application/MSORequestDBApplication.java @@ -0,0 +1,70 @@ +/*- + * ============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.adapters.requestsdb.application; + +import java.time.Duration; + +import javax.sql.DataSource; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; + +import net.javacrumbs.shedlock.core.LockProvider; +import net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider; +import net.javacrumbs.shedlock.spring.ScheduledLockConfiguration; +import net.javacrumbs.shedlock.spring.ScheduledLockConfigurationBuilder; + +/** + * @since Version 1.0 + * + */ + +@SpringBootApplication(scanBasePackages = { "org.onap.so"}) +public class MSORequestDBApplication { + + private static final String LOGS_DIR = "logs_dir"; + + private static void setLogsDir() { + if (System.getProperty(LOGS_DIR) == null) { + System.getProperties().setProperty(LOGS_DIR, "./logs/reqdb/"); + } + } + + public static void main(String... args) { + SpringApplication.run(MSORequestDBApplication.class, args); + setLogsDir(); + } + + @Bean + public LockProvider lockProvider(DataSource dataSource) { + return new JdbcTemplateLockProvider(dataSource); + } + + @Bean + public ScheduledLockConfiguration taskScheduler(LockProvider lockProvider) { + return ScheduledLockConfigurationBuilder + .withLockProvider(lockProvider) + .withPoolSize(10) + .withDefaultLockAtMostFor(Duration.ofMinutes(10)) + .build(); + } +} diff --git a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/application/RequestDBConfig.java b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/application/RequestDBConfig.java new file mode 100644 index 0000000000..bc1e17b067 --- /dev/null +++ b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/application/RequestDBConfig.java @@ -0,0 +1,80 @@ +/*- + * ============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.adapters.requestsdb.application; + + +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.context.properties.ConfigurationProperties; +import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.context.annotation.Profile; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.orm.jpa.JpaTransactionManager; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +@Profile({"!test"}) +@Configuration +@EnableTransactionManagement +@EnableJpaRepositories( + entityManagerFactoryRef = "requestEntityManagerFactory",transactionManagerRef = "requestTransactionManager", + basePackages = { "org.onap.so.db.request.data.repository" } + ) +public class RequestDBConfig { + + @Primary + @Bean(name = "requestDataSource") + @ConfigurationProperties(prefix = "spring.datasource") + public DataSource dataSource() { + return DataSourceBuilder.create().build(); + } + + @Primary + @Bean(name = "requestEntityManagerFactory") + public LocalContainerEntityManagerFactoryBean + entityManagerFactory( + EntityManagerFactoryBuilder builder, + @Qualifier("requestDataSource") DataSource dataSource + ) { + return builder + .dataSource(dataSource) + .packages("org.onap.so.db.request.beans") + .persistenceUnit("requestDB") + .build(); + } + + @Primary + @Bean(name = "requestTransactionManager") + public PlatformTransactionManager transactionManager( + @Qualifier("requestEntityManagerFactory") EntityManagerFactory + entityManagerFactory + ) { + return new JpaTransactionManager(entityManagerFactory); + } + +} diff --git a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/exceptions/MsoRequestsDbException.java b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/exceptions/MsoRequestsDbException.java new file mode 100644 index 0000000000..660761143e --- /dev/null +++ b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/exceptions/MsoRequestsDbException.java @@ -0,0 +1,62 @@ +/*- + * ============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.adapters.requestsdb.exceptions; + + + +import javax.xml.ws.WebFault; + +/** + * This class simply extends Exception (without addition additional functionality) + * to provide an identifier for RequestsDB related exceptions on create, delete, query. + * + * + */ +@WebFault (name="MsoRequestsDbException", faultBean="org.onap.so.adapters.requestsdb.exceptions.MsoRequestsDbExceptionBean", targetNamespace="http://org.onap.so/requestsdb") +public class MsoRequestsDbException extends Exception { + + private static final long serialVersionUID = 1L; + + private MsoRequestsDbExceptionBean faultInfo; + + public MsoRequestsDbException (String msg) { + super(msg); + faultInfo = new MsoRequestsDbExceptionBean (msg); + } + + public MsoRequestsDbException (Throwable e) { + super(e); + faultInfo = new MsoRequestsDbExceptionBean (e.getMessage()); + } + + public MsoRequestsDbException (String msg, Throwable e) { + super (msg, e); + faultInfo = new MsoRequestsDbExceptionBean (msg); + } + + public MsoRequestsDbExceptionBean getFaultInfo() { + return faultInfo; + } + + public void setFaultInfo(MsoRequestsDbExceptionBean faultInfo) { + this.faultInfo = faultInfo; + } +} diff --git a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/exceptions/MsoRequestsDbExceptionBean.java b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/exceptions/MsoRequestsDbExceptionBean.java new file mode 100644 index 0000000000..c836a6b374 --- /dev/null +++ b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/exceptions/MsoRequestsDbExceptionBean.java @@ -0,0 +1,50 @@ +/*- + * ============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.adapters.requestsdb.exceptions; + + +import java.io.Serializable; + +/** + * Jax-WS Fault Bean for MsoRequestsDB Exception + */ +public class MsoRequestsDbExceptionBean implements Serializable { + + private static final long serialVersionUID = 1360000062602372639L; + + private String message; + + public MsoRequestsDbExceptionBean () { + /* Empty constructor */ + } + + public MsoRequestsDbExceptionBean (String message) { + this.message = message; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} |