summaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java
diff options
context:
space:
mode:
authorAmichai Hemli <amichai.hemli@intl.att.com>2020-03-08 15:27:26 +0000
committerGerrit Code Review <gerrit@onap.org>2020-03-08 15:27:26 +0000
commitd46b13b53c422a4f3c01fb02012c3315aff6bde6 (patch)
tree205cd5f299d5159cfeb337d43f8125960b14be3b /vid-app-common/src/main/java
parent742d6d369b761220e565f39f2fa09413141ad93f (diff)
parent455f47766ce554ed9354d707992353353753745e (diff)
Merge changes Ibbc7da3a,I8efee06f
* changes: Don't use EELFLoggerDelegate.errorLogger in Async jobs isVfModuleBaseModule() will not throw on model mismatch
Diffstat (limited to 'vid-app-common/src/main/java')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/job/command/CommandUtils.java59
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/job/command/InProgressStatusService.java16
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/job/command/MacroServiceCommand.kt4
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/job/command/MsoRequestBuilder.kt2
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/job/command/ResourceCommand.kt6
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/job/command/RootServiceCommand.kt4
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/job/command/VfmoduleCommand.kt2
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/job/command/VnfCommand.kt6
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/job/impl/DeleteOldJobsSchedulerInitializer.java2
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/job/impl/JobSchedulerInitializer.java19
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/job/impl/JobWorker.java10
11 files changed, 65 insertions, 65 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/CommandUtils.java b/vid-app-common/src/main/java/org/onap/vid/job/command/CommandUtils.java
index 2b6b57ade..fd8f04ce6 100644
--- a/vid-app-common/src/main/java/org/onap/vid/job/command/CommandUtils.java
+++ b/vid-app-common/src/main/java/org/onap/vid/job/command/CommandUtils.java
@@ -20,10 +20,16 @@
package org.onap.vid.job.command;
+import static org.apache.commons.collections4.MapUtils.emptyIfNull;
+
import org.apache.commons.lang3.StringUtils;
+import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.vid.aai.model.ModelVer;
-import org.onap.vid.asdc.AsdcCatalogException;
+import org.onap.vid.model.Group;
+import org.onap.vid.model.GroupProperties;
import org.onap.vid.model.ServiceModel;
+import org.onap.vid.model.VfModule;
+import org.onap.vid.mso.model.ModelInfo;
import org.onap.vid.services.AaiService;
import org.onap.vid.services.VidService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -32,6 +38,8 @@ import org.springframework.stereotype.Component;
@Component
public class CommandUtils {
+ private static final EELFLoggerDelegate Logger = EELFLoggerDelegate.getLogger(CommandUtils.class);
+
private final VidService vidService;
private final AaiService aaiService;
@@ -41,43 +49,34 @@ public class CommandUtils {
this.aaiService = aaiService;
}
- public boolean isVfModuleBaseModule(String serviceModelUuid, String vfModuleModelUUID) throws AsdcCatalogException{
- ServiceModel serviceModel = getServiceModel(serviceModelUuid);
+ public boolean isVfModuleBaseModule(String serviceModelUuid, ModelInfo vfModuleModelInfo) {
+ ServiceModel serviceModel = getServiceModel(serviceModelUuid);
- if (serviceModel.getVfModules() == null) {
- throw createAsdcCatalogVfModuleModelUUIDNotFoundException(serviceModelUuid, vfModuleModelUUID);
- }
-
- return serviceModel.getVfModules()
- .values()
- .stream()
- .filter(vfModule -> StringUtils.equals(vfModule.getUuid(), vfModuleModelUUID))
- .findFirst()
- .orElseThrow(() -> createAsdcCatalogVfModuleModelUUIDNotFoundException(serviceModelUuid, vfModuleModelUUID))
- .getProperties()
- .getBaseModule();
+ return emptyIfNull(serviceModel.getVfModules())
+ .values().stream()
+ .filter(toscaModelInfo -> modelsMatch(vfModuleModelInfo, toscaModelInfo))
+ .map(Group::getProperties)
+ .map(GroupProperties::getBaseModule)
+ .findAny().orElseGet(() -> {
+ Logger.debug(EELFLoggerDelegate.debugLogger,
+ "Could not find vfModule in model with uuid {}, assuming not base module ({})",
+ serviceModelUuid, vfModuleModelInfo);
+ return false;
+ });
}
- public ServiceModel getServiceModel(String serviceModelUuid) throws AsdcCatalogException{
- ServiceModel serviceModel = vidService.getService(serviceModelUuid);
-
- if (serviceModel==null) {
- throw new AsdcCatalogException("Failed to retrieve model with uuid "+serviceModelUuid +" from SDC");
- }
+ private boolean modelsMatch(ModelInfo instanceModelInfo, VfModule toscaModelInfo) {
+ return StringUtils.equals(toscaModelInfo.getCustomizationUuid(), instanceModelInfo.getModelCustomizationId())
+ || StringUtils.equals(toscaModelInfo.getModelCustomizationName(), instanceModelInfo.getModelCustomizationName());
+ }
- return serviceModel;
+ public ServiceModel getServiceModel(String serviceModelUuid) {
+ return vidService.getServiceModelOrThrow(serviceModelUuid);
}
- public String getNewestModelUuid(String serviceModelInvariantId)
- {
+ public String getNewestModelUuid(String serviceModelInvariantId) {
ModelVer serviceModelLatestVersion = aaiService.getNewestModelVersionByInvariantId(serviceModelInvariantId);
-
return serviceModelLatestVersion.getModelVersionId();
}
- private AsdcCatalogException createAsdcCatalogVfModuleModelUUIDNotFoundException(String serviceModelUuid, String vfModuleModelUUID) {
- return new AsdcCatalogException("Failed to find vfModuleModelUUID: " + vfModuleModelUUID +
- "in model with uuid: " + serviceModelUuid);
- }
-
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/InProgressStatusService.java b/vid-app-common/src/main/java/org/onap/vid/job/command/InProgressStatusService.java
index 3d1d78f8b..91bf5de1e 100644
--- a/vid-app-common/src/main/java/org/onap/vid/job/command/InProgressStatusService.java
+++ b/vid-app-common/src/main/java/org/onap/vid/job/command/InProgressStatusService.java
@@ -20,6 +20,11 @@
package org.onap.vid.job.command;
+import static org.onap.vid.utils.TimeUtils.parseZonedDateTime;
+
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeParseException;
+import java.util.UUID;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.vid.job.Job;
import org.onap.vid.job.impl.JobSharedData;
@@ -33,12 +38,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.togglz.core.manager.FeatureManager;
-import java.time.ZonedDateTime;
-import java.time.format.DateTimeParseException;
-import java.util.UUID;
-
-import static org.onap.vid.utils.TimeUtils.parseZonedDateTime;
-
@Service
public class InProgressStatusService {
@@ -86,8 +85,7 @@ public class InProgressStatusService {
public void handleFailedMsoResponse(UUID jobUUID, String requestId, RestObject<AsyncRequestStatus> msoResponse) {
auditService.setFailedAuditStatusFromMso(jobUUID, requestId, msoResponse.getStatusCode(), msoResponse.getRaw());
- LOGGER.error(EELFLoggerDelegate.errorLogger,
- "Failed to get orchestration status for {}. Status code: {}, Body: {}",
+ LOGGER.error("Failed to get orchestration status for {}. Status code: {}, Body: {}",
requestId, msoResponse.getStatusCode(), msoResponse.getRaw());
}
@@ -108,7 +106,7 @@ public class InProgressStatusService {
try {
jobStartTime = parseZonedDateTime(asyncRequestStatusResponse.get().request.startTime);
} catch (DateTimeParseException | NullPointerException e) {
- LOGGER.error(EELFLoggerDelegate.errorLogger, "Failed to parse start time for {}, body: {}. Current time will be used", requestId, asyncRequestStatusResponse.getRaw(), e);
+ LOGGER.error("Failed to parse start time for {}, body: {}. Current time will be used", requestId, asyncRequestStatusResponse.getRaw(), e);
jobStartTime = ZonedDateTime.now();
}
return jobStartTime;
diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/MacroServiceCommand.kt b/vid-app-common/src/main/java/org/onap/vid/job/command/MacroServiceCommand.kt
index 2fdd19100..8ce73d713 100644
--- a/vid-app-common/src/main/java/org/onap/vid/job/command/MacroServiceCommand.kt
+++ b/vid-app-common/src/main/java/org/onap/vid/job/command/MacroServiceCommand.kt
@@ -62,13 +62,13 @@ class MacroServiceCommand @Autowired constructor(
//Aai return bad response while checking names uniqueness
catch (exception : ExceptionWithRequestInfo) {
- Logger.error(EELFLoggerDelegate.errorLogger, "Failed to check name uniqueness in AAI. VID will try again later", exception)
+ Logger.error("Failed to check name uniqueness in AAI. VID will try again later", exception)
throw TryAgainException(exception);
}
//Vid reached to max retries while trying to find unique name in AAI
catch (exception : MaxRetriesException) {
- Logger.error(EELFLoggerDelegate.errorLogger, "Failed to find unused name in AAI", exception)
+ Logger.error("Failed to find unused name in AAI", exception)
throw AbortingException(exception);
}
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/MsoRequestBuilder.kt b/vid-app-common/src/main/java/org/onap/vid/job/command/MsoRequestBuilder.kt
index 063ef6e53..c3fdcdaeb 100644
--- a/vid-app-common/src/main/java/org/onap/vid/job/command/MsoRequestBuilder.kt
+++ b/vid-app-common/src/main/java/org/onap/vid/job/command/MsoRequestBuilder.kt
@@ -210,7 +210,7 @@ class MsoRequestBuilder
try {
asyncInstantiationBL.updateServiceInfo(jobId) { x -> x.serviceInstanceName = serviceInstanceName }
} catch (e: Exception) {
- LOGGER.error(EELFLoggerDelegate.errorLogger, "Failed updating service name {} in serviceInfo", serviceInstanceName, e)
+ LOGGER.error("Failed updating service name {} in serviceInfo", serviceInstanceName, e)
}
return serviceInstanceName
diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/ResourceCommand.kt b/vid-app-common/src/main/java/org/onap/vid/job/command/ResourceCommand.kt
index 4477a9f24..2b5ec0127 100644
--- a/vid-app-common/src/main/java/org/onap/vid/job/command/ResourceCommand.kt
+++ b/vid-app-common/src/main/java/org/onap/vid/job/command/ResourceCommand.kt
@@ -153,7 +153,7 @@ abstract class ResourceCommand(
JobStatus.IN_PROGRESS
}
catch (exception: AbortingException) {
- Logger.error(EELFLoggerDelegate.errorLogger, "caught AbortingException. Set job status to FAILED")
+ Logger.error("caught AbortingException. Set job status to FAILED")
JobStatus.FAILED;
}
}
@@ -330,13 +330,13 @@ abstract class ResourceCommand(
handleInProgressStatus(jobStatus)
} catch (e: javax.ws.rs.ProcessingException) {
// Retry when we can't connect MSO during getStatus
- Logger.error(EELFLoggerDelegate.errorLogger, "Cannot get orchestration status for {}, will retry: {}", requestId, e, e)
+ Logger.error("Cannot get orchestration status for {}, will retry: {}", requestId, e, e)
JobStatus.IN_PROGRESS;
} catch (e: InProgressStatusService.BadResponseFromMso) {
inProgressStatusService.handleFailedMsoResponse(sharedData.jobUuid, requestId, e.msoResponse)
JobStatus.IN_PROGRESS
} catch (e: RuntimeException) {
- Logger.error(EELFLoggerDelegate.errorLogger, "Cannot get orchestration status for {}, stopping: {}", requestId, e, e)
+ Logger.error("Cannot get orchestration status for {}, stopping: {}", requestId, e, e)
JobStatus.STOPPED
}
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/RootServiceCommand.kt b/vid-app-common/src/main/java/org/onap/vid/job/command/RootServiceCommand.kt
index 875de66d6..c4680b2bd 100644
--- a/vid-app-common/src/main/java/org/onap/vid/job/command/RootServiceCommand.kt
+++ b/vid-app-common/src/main/java/org/onap/vid/job/command/RootServiceCommand.kt
@@ -71,13 +71,13 @@ abstract class RootServiceCommand @Autowired constructor(
try {
val requests = auditService.retrieveRequestsFromMsoByServiceIdAndRequestTypeAndScope(serviceInstanceId, requestType, scope)
if (requests.isEmpty() || requests[0].requestId == null) {
- LOGGER.error(EELFLoggerDelegate.errorLogger, "Failed to retrieve requestId with type: $type, scope: $scope for service instanceId $serviceInstanceId ")
+ LOGGER.error("Failed to retrieve requestId with type: $type, scope: $scope for service instanceId $serviceInstanceId ")
return Job.JobStatus.FAILED
}
val createMyselfCommand = planResumeMyselfRestCall(requests[0].requestId, sharedData.userId)
return executeAndHandleMsoInstanceRequest(createMyselfCommand)
} catch (exception: Exception) {
- LOGGER.error(EELFLoggerDelegate.errorLogger, "Failed to resume instanceId $serviceInstanceId ", exception)
+ LOGGER.error("Failed to resume instanceId $serviceInstanceId ", exception)
return Job.JobStatus.FAILED
}
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/VfmoduleCommand.kt b/vid-app-common/src/main/java/org/onap/vid/job/command/VfmoduleCommand.kt
index 68c9f53e1..29d7001e2 100644
--- a/vid-app-common/src/main/java/org/onap/vid/job/command/VfmoduleCommand.kt
+++ b/vid-app-common/src/main/java/org/onap/vid/job/command/VfmoduleCommand.kt
@@ -193,7 +193,7 @@ class VfmoduleCommand @Autowired constructor(
val replaceMyselfCommand = planReplaceMyselfRestCall(commandParentData)
return executeAndHandleMsoInstanceRequest(replaceMyselfCommand)
} catch (exception: Exception) {
- LOGGER.error(EELFLoggerDelegate.errorLogger, "Failed to replace instanceId ${getRequest().instanceId} ", exception)
+ LOGGER.error("Failed to replace instanceId ${getRequest().instanceId} ", exception)
return Job.JobStatus.FAILED
}
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/VnfCommand.kt b/vid-app-common/src/main/java/org/onap/vid/job/command/VnfCommand.kt
index cada6055d..9023682f6 100644
--- a/vid-app-common/src/main/java/org/onap/vid/job/command/VnfCommand.kt
+++ b/vid-app-common/src/main/java/org/onap/vid/job/command/VnfCommand.kt
@@ -61,8 +61,7 @@ class VnfCommand @Autowired constructor(
try {
childJobs = pushChildrenJobsToBroker(vfModulesForChildrenJobs(vfModules), dataForChild, JobType.VolumeGroupInstantiation)
} catch (e: AsdcCatalogException) {
- LOGGER.error(EELFLoggerDelegate.errorLogger, "Failed to retrieve service definitions from SDC, for VfModule is BaseModule.. Error: " + e.message, e)
- //return Job.JobStatus.FAILED
+ LOGGER.error("Failed to retrieve service definitions from SDC, for VfModule is BaseModule.. Error: " + e.message, e)
throw e;
}
}
@@ -92,8 +91,7 @@ class VnfCommand @Autowired constructor(
private fun filterModuleByNeedToCreateBase(vfModule: VfModule): Boolean {
return needToCreateBaseModule ==
commandUtils.isVfModuleBaseModule(
- serviceModelInfoFromRequest().modelVersionId,
- vfModule.modelInfo.modelVersionId)
+ serviceModelInfoFromRequest().modelVersionId, vfModule.modelInfo)
}
override fun planCreateMyselfRestCall(commandParentData: CommandParentData, request: JobAdapter.AsyncJobRequest, userId: String, testApi: String?): MsoRestCallPlan {
diff --git a/vid-app-common/src/main/java/org/onap/vid/job/impl/DeleteOldJobsSchedulerInitializer.java b/vid-app-common/src/main/java/org/onap/vid/job/impl/DeleteOldJobsSchedulerInitializer.java
index 114c20105..981bdeaa7 100644
--- a/vid-app-common/src/main/java/org/onap/vid/job/impl/DeleteOldJobsSchedulerInitializer.java
+++ b/vid-app-common/src/main/java/org/onap/vid/job/impl/DeleteOldJobsSchedulerInitializer.java
@@ -64,7 +64,7 @@ public class DeleteOldJobsSchedulerInitializer {
Trigger deleteOldJobsTrigger = createTrigger();
schedulerFactoryBean.getScheduler().scheduleJob(jobDetail, deleteOldJobsTrigger);
} catch (SchedulerException e) {
- logger.error(EELFLoggerDelegate.errorLogger, "Failed to schedule trigger for delete old jobs: {}", e.getMessage());
+ logger.error("Failed to schedule trigger for delete old jobs: {}", e.getMessage());
throw new GenericUncheckedException(e);
}
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/job/impl/JobSchedulerInitializer.java b/vid-app-common/src/main/java/org/onap/vid/job/impl/JobSchedulerInitializer.java
index b5c2dd74b..bd82ffa7a 100644
--- a/vid-app-common/src/main/java/org/onap/vid/job/impl/JobSchedulerInitializer.java
+++ b/vid-app-common/src/main/java/org/onap/vid/job/impl/JobSchedulerInitializer.java
@@ -20,24 +20,29 @@
package org.onap.vid.job.impl;
+import static org.quartz.SimpleScheduleBuilder.simpleSchedule;
+
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import java.util.List;
+import javax.annotation.PostConstruct;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.vid.exceptions.GenericUncheckedException;
import org.onap.vid.job.Job;
import org.onap.vid.job.JobsBrokerService;
import org.onap.vid.job.command.JobCommandFactory;
-import org.quartz.*;
+import org.quartz.JobBuilder;
+import org.quartz.JobDataMap;
+import org.quartz.JobDetail;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerException;
+import org.quartz.Trigger;
+import org.quartz.TriggerBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Component;
import org.togglz.core.manager.FeatureManager;
-import javax.annotation.PostConstruct;
-import java.util.List;
-
-import static org.quartz.SimpleScheduleBuilder.simpleSchedule;
-
@Component
public class JobSchedulerInitializer {
@@ -94,7 +99,7 @@ public class JobSchedulerInitializer {
try {
scheduler.scheduleJob(jobDetail, asyncWorkerTrigger);
} catch (SchedulerException e) {
- logger.error(EELFLoggerDelegate.errorLogger, "Failed to schedule trigger for async worker jobs: {}", e.getMessage());
+ logger.error("Failed to schedule trigger for async worker jobs: {}", e.getMessage());
throw new GenericUncheckedException(e);
}
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/job/impl/JobWorker.java b/vid-app-common/src/main/java/org/onap/vid/job/impl/JobWorker.java
index c629a665c..c0e006e22 100644
--- a/vid-app-common/src/main/java/org/onap/vid/job/impl/JobWorker.java
+++ b/vid-app-common/src/main/java/org/onap/vid/job/impl/JobWorker.java
@@ -69,7 +69,7 @@ public class JobWorker extends QuartzJobBean {
try {
return jobsBrokerService.pull(topic, UUID.randomUUID().toString());
} catch (Exception e) {
- LOGGER.error(EELFLoggerDelegate.errorLogger, "failed to pull job from queue, breaking: {}", e, e);
+ LOGGER.error("failed to pull job from queue, breaking: {}", e, e);
tryMutingJobFromException(e);
return Optional.empty();
@@ -80,7 +80,7 @@ public class JobWorker extends QuartzJobBean {
try {
jobsBrokerService.pushBack(nextJob);
} catch (Exception e) {
- LOGGER.error(EELFLoggerDelegate.errorLogger, "failed pushing back job to queue: {}", e, e);
+ LOGGER.error("failed pushing back job to queue: {}", e, e);
}
}
@@ -114,7 +114,7 @@ public class JobWorker extends QuartzJobBean {
final JobCommand jobCommand = jobCommandFactory.toCommand(job);
nextCommand = jobCommand.call();
} catch (Exception e) {
- LOGGER.error(EELFLoggerDelegate.errorLogger, "error while executing job from queue: {}", e);
+ LOGGER.error("error while executing job from queue: {}", e, e);
nextCommand = new NextCommand(FAILED);
}
@@ -153,10 +153,10 @@ public class JobWorker extends QuartzJobBean {
LOGGER.info(EELFLoggerDelegate.debugLogger, "muting job: {} ({})", jobException.getJobUuid(), jobException.toString());
final boolean success = jobsBrokerService.mute(jobException.getJobUuid());
if (!success) {
- LOGGER.error(EELFLoggerDelegate.errorLogger, "failed to mute job {}", jobException.getJobUuid());
+ LOGGER.error("failed to mute job {}", jobException.getJobUuid());
}
} catch (Exception e1) {
- LOGGER.error(EELFLoggerDelegate.errorLogger, "failed to mute job: {}", e1, e1);
+ LOGGER.error("failed to mute job: {}", e1, e1);
}
}
}