From 6ad41e3ccd398a2721f41ad61c80b7bb03f7d127 Mon Sep 17 00:00:00 2001 From: Ittay Stern Date: Mon, 31 Dec 2018 17:21:27 +0200 Subject: Merge from ECOMP's repository Main Features -------------- - Async-Instantiation jobs mechanism major update; still WIP (package `org.onap.vid.job`) - New features in View/Edit: Activate fabric configuration; show related networks; soft delete - Support AAI service-tree traversal (`AAIServiceTree`) - In-memory cache for SDC models and certain A&AI queries (`CacheProviderWithLoadingCache`) - Upgrade TOSCA Parser and add parsing options; fix malformed TOSCA models - Resolve Cloud-Owner values for MSO - Pass X-ONAP headers to MSO Infrastructure -------------- - Remove codehaus' jackson mapper; use soley fasterxml 2.9.7 - Surefire invokes both TestNG and JUnit tests - Support Kotlin source files - AaiController2 which handles errors in a "Spring manner" - Inline generated-sources and remove jsonschema2pojo Quality -------- - Cumulative bug fixes (A&AI API, UI timeouts, and many more) - Many Sonar issues cleaned-up - Some unused classes removed - Minor changes in vid-automation project, allowing some API verification to run Hard Merges ------------ - HTTP Clients (MSO, A&AI, WebConfig, OutgoingRequestHeadersTest) - Moved `package org.onap.vid.controllers` to `controller`, without plural -- just to keep semantic sync with ECOMP. Reference commit in ECOMP: 3d1141625 Issue-ID: VID-378 Change-Id: I9c8d1e74caa41815891d441fc0760bb5f29c5788 Signed-off-by: Ittay Stern --- .../job/impl/JobsBrokerServiceInDatabaseImpl.java | 75 ++++++++++++++++------ 1 file changed, 56 insertions(+), 19 deletions(-) (limited to 'vid-app-common/src/main/java/org/onap/vid/job/impl/JobsBrokerServiceInDatabaseImpl.java') diff --git a/vid-app-common/src/main/java/org/onap/vid/job/impl/JobsBrokerServiceInDatabaseImpl.java b/vid-app-common/src/main/java/org/onap/vid/job/impl/JobsBrokerServiceInDatabaseImpl.java index e286cc4aa..e87478794 100644 --- a/vid-app-common/src/main/java/org/onap/vid/job/impl/JobsBrokerServiceInDatabaseImpl.java +++ b/vid-app-common/src/main/java/org/onap/vid/job/impl/JobsBrokerServiceInDatabaseImpl.java @@ -2,15 +2,15 @@ package org.onap.vid.job.impl; import org.apache.commons.lang3.StringUtils; import org.hibernate.SessionFactory; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.core.service.DataAccessService; +import org.onap.portalsdk.core.util.SystemProperties; import org.onap.vid.exceptions.GenericUncheckedException; import org.onap.vid.exceptions.OperationNotAllowedException; import org.onap.vid.job.Job; import org.onap.vid.job.JobsBrokerService; import org.onap.vid.properties.VidProperties; import org.onap.vid.utils.DaoUtils; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.onap.portalsdk.core.service.DataAccessService; -import org.onap.portalsdk.core.util.SystemProperties; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -21,6 +21,8 @@ import java.sql.Timestamp; import java.time.LocalDateTime; import java.util.*; +import static org.onap.vid.job.Job.JobStatus.CREATING; + @Service public class JobsBrokerServiceInDatabaseImpl implements JobsBrokerService { @@ -56,7 +58,6 @@ public class JobsBrokerServiceInDatabaseImpl implements JobsBrokerService { @Override public UUID add(Job job) { final JobDaoImpl jobDao = castToJobDaoImpl(job); - jobDao.setUuid(UUID.randomUUID()); dataAccessService.saveDomainObject(jobDao, DaoUtils.getPropsMap()); return job.getUuid(); } @@ -102,23 +103,30 @@ public class JobsBrokerServiceInDatabaseImpl implements JobsBrokerService { return Timestamp.valueOf(LocalDateTime.now().minusSeconds(pollingIntervalSeconds)); } + private String selectQueryByJobStatus(Job.JobStatus topic){ + + String intervalCondition = (topic==CREATING) ? "" : (" and MODIFIED_DATE <= '" + nowMinusInterval()+"'"); + return "" + + "select * from VID_JOB" + + " where" + + // select only non-deleted in-progress jobs + " JOB_STATUS = '" + topic + "'" + + " and TAKEN_BY is null" + + " and DELETED_AT is null" + + // give some breath, don't select jos that were recently reached + intervalCondition + + // take the oldest handled one + " order by MODIFIED_DATE ASC" + + // select only one result + " limit 1"; + } + private String sqlQueryForTopic(Job.JobStatus topic) { switch (topic) { case IN_PROGRESS: - return "" + - "select * from VID_JOB" + - " where" + - // select only non-deleted in-progress jobs - " JOB_STATUS = 'IN_PROGRESS'" + - " and TAKEN_BY is null" + - " and DELETED_AT is null" + - // give some breath, don't select jos that were recently reached - " and MODIFIED_DATE <= '" + nowMinusInterval() + - // take the oldest handled one - "' order by MODIFIED_DATE ASC" + - // select only one result - " limit 1"; - + case RESOURCE_IN_PROGRESS: + case CREATING: + return selectQueryByJobStatus(topic); case PENDING: return "" + // select only pending jobs @@ -137,9 +145,10 @@ public class JobsBrokerServiceInDatabaseImpl implements JobsBrokerService { // don't take jobs from templates that already in-progress/failed "and TEMPLATE_Id not in \n" + "(select TEMPLATE_Id from vid_job where" + + " TEMPLATE_Id IS NOT NULL and("+ " (JOB_STATUS='FAILED' and DELETED_AT is null)" + // failed but not deleted " or JOB_STATUS='IN_PROGRESS'" + - " or TAKEN_BY IS NOT NULL)" + " \n " + + " or TAKEN_BY IS NOT NULL))" + " \n " + // prefer older jobs, but the earlier in each bulk "order by has_any_in_progress_job, CREATED_DATE, INDEX_IN_BULK " + // select only one result @@ -233,4 +242,32 @@ public class JobsBrokerServiceInDatabaseImpl implements JobsBrokerService { throw new OperationNotAllowedException("Service deletion failed"); } } + + @Override + public boolean mute(UUID jobId) { + if (jobId == null) { + return false; + } + + final String prefix = "DUMP"; + int updatedEntities; + + // Changing the topic (i.e. `job.status`) makes the job non-fetchable. + String hqlUpdate = "" + + "update JobDaoImpl job set" + + " job.status = concat('" + prefix + "_', job.status)," + + // empty `takenBy`, because some logics treat taken as in-progress + " takenBy = null" + + " where " + + " job.id = :id" + + // if prefix already on the topic -- no need to do it twice. + " and job.status NOT LIKE '" + prefix + "\\_%'"; + + updatedEntities = DaoUtils.tryWithSessionAndTransaction(sessionFactory, session -> + session.createQuery(hqlUpdate) + .setText("id", jobId.toString()) + .executeUpdate()); + + return updatedEntities != 0; + } } -- cgit 1.2.3-korg