Search in sources :

Example 1 with JobDefinitionParameterEntity

use of org.finra.herd.model.jpa.JobDefinitionParameterEntity in project herd by FINRAOS.

the class JobDefinitionServiceImpl method createJobDefinitionFromEntity.

/**
 * Creates the job definition from the persisted entity.
 *
 * @param jobDefinitionEntity the newly persisted job definition entity.
 *
 * @return the job definition.
 */
private JobDefinition createJobDefinitionFromEntity(JobDefinitionEntity jobDefinitionEntity) throws IOException {
    // Create the business object definition information.
    JobDefinition jobDefinition = new JobDefinition();
    jobDefinition.setId(jobDefinitionEntity.getId());
    jobDefinition.setNamespace(jobDefinitionEntity.getNamespace().getCode());
    jobDefinition.setJobName(jobDefinitionEntity.getName());
    jobDefinition.setDescription(jobDefinitionEntity.getDescription());
    String s3BucketName = jobDefinitionEntity.getS3BucketName();
    String s3ObjectKey = jobDefinitionEntity.getS3ObjectKey();
    if (s3BucketName != null && s3ObjectKey != null) {
        S3PropertiesLocation s3PropertiesLocation = new S3PropertiesLocation();
        s3PropertiesLocation.setBucketName(s3BucketName);
        s3PropertiesLocation.setKey(s3ObjectKey);
        jobDefinition.setS3PropertiesLocation(s3PropertiesLocation);
    }
    // Retrieve Activiti XML from activiti.
    ProcessDefinition processDefinition = activitiRepositoryService.createProcessDefinitionQuery().processDefinitionId(jobDefinitionEntity.getActivitiId()).singleResult();
    InputStream xmlStream = activitiRepositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getResourceName());
    jobDefinition.setActivitiJobXml(IOUtils.toString(xmlStream));
    // Add in the parameters.
    List<Parameter> parameters = new ArrayList<>();
    jobDefinition.setParameters(parameters);
    for (JobDefinitionParameterEntity parameterEntity : jobDefinitionEntity.getParameters()) {
        Parameter parameter = new Parameter(parameterEntity.getName(), parameterEntity.getValue());
        jobDefinitionHelper.maskPassword(parameter);
        parameters.add(parameter);
    }
    // Populate the "last updated by" user ID.
    jobDefinition.setLastUpdatedByUserId(jobDefinitionEntity.getUpdatedBy());
    return jobDefinition;
}
Also used : S3PropertiesLocation(org.finra.herd.model.api.xml.S3PropertiesLocation) InputStream(java.io.InputStream) JobDefinitionParameterEntity(org.finra.herd.model.jpa.JobDefinitionParameterEntity) ArrayList(java.util.ArrayList) Parameter(org.finra.herd.model.api.xml.Parameter) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) JobDefinition(org.finra.herd.model.api.xml.JobDefinition)

Example 2 with JobDefinitionParameterEntity

use of org.finra.herd.model.jpa.JobDefinitionParameterEntity in project herd by FINRAOS.

the class JobServiceImpl method getParameters.

/**
 * Gets the parameters from the given {@link JobDefinitionEntity} and {@link JobCreateRequest} and their respective S3 locations provided. If there are any
 * parameter conflicts, this method will automatically merge them by a predefined precedence, from least to greatest: <ol> <li>Job Definition S3
 * location</li> <li>Job Definition parameters</li> <li>Job Create Request S3 location</li> <li>Job Create Request parameters</li> </ol>
 *
 * @param jobDefinitionEntity {@link JobDefinitionEntity}
 * @param jobCreateRequest {@link JobCreateRequest}
 *
 * @return merged parameters
 */
private Map<String, Object> getParameters(JobDefinitionEntity jobDefinitionEntity, JobCreateRequest jobCreateRequest) {
    Map<String, Object> mergedParameters = new HashMap<>();
    // Get parameters from job definition S3 location
    putParametersFromS3(jobDefinitionEntity.getS3BucketName(), jobDefinitionEntity.getS3ObjectKey(), mergedParameters);
    // Get parameters from job definition parameters
    for (JobDefinitionParameterEntity definitionParam : jobDefinitionEntity.getParameters()) {
        mergedParameters.put(definitionParam.getName(), definitionParam.getValue());
    }
    // Get parameters from job create request S3 location
    S3PropertiesLocation s3PropertiesLocation = jobCreateRequest.getS3PropertiesLocation();
    if (s3PropertiesLocation != null) {
        putParametersFromS3(s3PropertiesLocation.getBucketName(), s3PropertiesLocation.getKey(), mergedParameters);
    }
    // Get parameters from job create request parameters
    mergedParameters.putAll(toMap(jobCreateRequest.getParameters()));
    return mergedParameters;
}
Also used : S3PropertiesLocation(org.finra.herd.model.api.xml.S3PropertiesLocation) HashMap(java.util.HashMap) JobDefinitionParameterEntity(org.finra.herd.model.jpa.JobDefinitionParameterEntity)

Example 3 with JobDefinitionParameterEntity

use of org.finra.herd.model.jpa.JobDefinitionParameterEntity in project herd by FINRAOS.

the class JobDefinitionServiceImpl method createOrUpdateJobDefinitionEntity.

/**
 * Creates a new job definition entity from the request information.
 *
 * @param jobDefinitionEntity an optional existing job definition entity to update. If null, then a new one will be created.
 * @param namespaceEntity the namespace entity.
 * @param jobName the job name.
 * @param description the job definition description.
 * @param activitiId the Activiti Id.
 * @param parameters the job definition parameters.
 *
 * @return the newly created or existing updated job definition entity.
 */
private JobDefinitionEntity createOrUpdateJobDefinitionEntity(JobDefinitionEntity jobDefinitionEntity, NamespaceEntity namespaceEntity, String jobName, String description, String activitiId, List<Parameter> parameters, S3PropertiesLocation s3PropertiesLocation) {
    JobDefinitionEntity jobDefinitionEntityLocal = jobDefinitionEntity;
    // If a job definition entity doesn't yet exist, create a new one.
    if (jobDefinitionEntityLocal == null) {
        jobDefinitionEntityLocal = new JobDefinitionEntity();
    }
    // Create a new entity.
    jobDefinitionEntityLocal.setName(jobName);
    jobDefinitionEntityLocal.setNamespace(namespaceEntity);
    jobDefinitionEntityLocal.setDescription(description);
    jobDefinitionEntityLocal.setActivitiId(activitiId);
    // Set or clear S3 properties location
    String bucketName = null;
    String key = null;
    if (s3PropertiesLocation != null) {
        bucketName = s3PropertiesLocation.getBucketName();
        key = s3PropertiesLocation.getKey();
    }
    jobDefinitionEntityLocal.setS3BucketName(bucketName);
    jobDefinitionEntityLocal.setS3ObjectKey(key);
    // Create the parameters.
    List<JobDefinitionParameterEntity> parameterEntities = new ArrayList<>();
    // As per generated JobDefinitionCreateRequest class, getParameters() never returns null.
    if (!CollectionUtils.isEmpty(parameters)) {
        for (Parameter parameter : parameters) {
            JobDefinitionParameterEntity parameterEntity = new JobDefinitionParameterEntity();
            parameterEntities.add(parameterEntity);
            parameterEntity.setName(parameter.getName());
            parameterEntity.setValue(parameter.getValue());
        }
    }
    // Set the new list of parameters on the entity.
    jobDefinitionEntityLocal.setParameters(parameterEntities);
    return jobDefinitionEntityLocal;
}
Also used : JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) JobDefinitionParameterEntity(org.finra.herd.model.jpa.JobDefinitionParameterEntity) ArrayList(java.util.ArrayList) Parameter(org.finra.herd.model.api.xml.Parameter)

Aggregations

JobDefinitionParameterEntity (org.finra.herd.model.jpa.JobDefinitionParameterEntity)3 ArrayList (java.util.ArrayList)2 Parameter (org.finra.herd.model.api.xml.Parameter)2 S3PropertiesLocation (org.finra.herd.model.api.xml.S3PropertiesLocation)2 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)1 JobDefinition (org.finra.herd.model.api.xml.JobDefinition)1 JobDefinitionEntity (org.finra.herd.model.jpa.JobDefinitionEntity)1