diff --git a/commons/pac-batch-commons/src/main/java/com/tmobile/pacman/commons/dto/JobDoneMessage.java b/commons/pac-batch-commons/src/main/java/com/tmobile/pacman/commons/dto/JobDoneMessage.java index 9af8fad8ba..102077edfe 100644 --- a/commons/pac-batch-commons/src/main/java/com/tmobile/pacman/commons/dto/JobDoneMessage.java +++ b/commons/pac-batch-commons/src/main/java/com/tmobile/pacman/commons/dto/JobDoneMessage.java @@ -15,11 +15,22 @@ ******************************************************************************/ package com.tmobile.pacman.commons.dto; +import com.fasterxml.jackson.annotation.JsonProperty; + public class JobDoneMessage { private String jobName; + // NOTE: 'paladinCloudTenantId' is currently sent by the legacy shipper while 'tenantId' is sent + // by the delta engine; it's not clear if different recipients will use what's available so + // both are sent here. private String paladinCloudTenantId; + @JsonProperty("tenant_id") + private String tenantId; private String source; private String enricherSource; + @JsonProperty("tenant_name") + private String tenantName; + private String[] assetTypes; + public String getJobName() { return jobName; @@ -53,10 +64,20 @@ public void setEnricherSource(String enricherSource) { this.enricherSource = enricherSource; } + public String getTenantName() { return tenantName; } + public String[] getAssetTypes() { return assetTypes; } + public JobDoneMessage (String jobName, String paladinCloudTenantId, String source, String enricherSource) { + this(jobName, paladinCloudTenantId, source, enricherSource, null, null); + } + + public JobDoneMessage (String jobName, String paladinCloudTenantId, String source, String enricherSource, String tenantName, String[] assetTypes) { this.jobName = jobName; this.paladinCloudTenantId = paladinCloudTenantId; + this.tenantId = paladinCloudTenantId; + this.tenantName = tenantName; this.source = source; this.enricherSource = enricherSource; + this.assetTypes = assetTypes; } } diff --git a/jobs/pacman-data-shipper/src/main/java/com/tmobile/cso/pacman/datashipper/Main.java b/jobs/pacman-data-shipper/src/main/java/com/tmobile/cso/pacman/datashipper/Main.java index 541175f5fa..09c372d5c9 100644 --- a/jobs/pacman-data-shipper/src/main/java/com/tmobile/cso/pacman/datashipper/Main.java +++ b/jobs/pacman-data-shipper/src/main/java/com/tmobile/cso/pacman/datashipper/Main.java @@ -15,6 +15,7 @@ ******************************************************************************/ package com.tmobile.cso.pacman.datashipper; +import com.tmobile.cso.pacman.datashipper.config.ConfigManager; import com.tmobile.cso.pacman.datashipper.dto.DatasourceData; import com.tmobile.cso.pacman.datashipper.entity.*; import com.tmobile.cso.pacman.datashipper.es.ESManager; @@ -23,11 +24,10 @@ import com.tmobile.pacman.commons.aws.sqs.SQSManager; import com.tmobile.pacman.commons.dto.JobDoneMessage; import com.tmobile.pacman.commons.jobs.PacmanJob; +import java.util.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.*; - @PacmanJob(methodToexecute = "shipData", jobName = "data-shipper", desc = "Job to load data from s3 to OP", priority = 5) public class Main implements Constants { private static final Logger LOGGER = LoggerFactory.getLogger(Main.class); @@ -107,10 +107,28 @@ public static Map shipData(Map params) { errorList.add(errorMap); LOGGER.error("Error while updating stats", e); } + + // Route all assets through the asset state service, which will route to the policy engine + // once it's done processing. SQSManager sqsManager = SQSManager.getInstance(); - JobDoneMessage jobDoneMessage = new JobDoneMessage(ds + "-Shipper-Job", tenantId, ds, null); - String sqsMessageID = sqsManager.sendSQSMessage(jobDoneMessage, System.getenv("SHIPPER_SQS_QUEUE_URL")); - LOGGER.debug("Shipper done SQS message ID: {}", sqsMessageID); + boolean isAsset = ds.equalsIgnoreCase("azure") + || ds.equalsIgnoreCase("aws") + || ds.equalsIgnoreCase("gcp"); + if (isAsset) { + List assetTypes = new ArrayList<>(ConfigManager.getTypesWithDisplayName(ds).keySet()); + Collections.sort(assetTypes); + JobDoneMessage jobDoneMessage = new JobDoneMessage(ds + "-Shipper-Job", tenantId, + ds, null, null, assetTypes.toArray(new String[0])); + String sqsMessageID = + sqsManager.sendSQSMessage(jobDoneMessage, System.getenv("ASSET_STATE_QUEUE_URL")); + LOGGER.debug("Done SQS message ID: {}", sqsMessageID); + } else { + JobDoneMessage jobDoneMessage = new JobDoneMessage(ds + "-Shipper-Job", tenantId, ds, null); + String sqsMessageID = + sqsManager.sendSQSMessage(jobDoneMessage, System.getenv("SHIPPER_SQS_QUEUE_URL")); + LOGGER.debug("Shipper done SQS message ID: {}", sqsMessageID); + } + Map status = ErrorManageUtil.formErrorCode(jobName, errorList); LOGGER.info("Job Return Status {} ", status); return status;