Search in sources :

Example 16 with Parameter

use of org.finra.herd.model.api.xml.Parameter in project herd by FINRAOS.

the class AddEmrStepsTest method testAddHadoopJarStep.

@Test
public void testAddHadoopJarStep() throws Exception {
    List<FieldExtension> fieldExtensionList = new ArrayList<>();
    FieldExtension exceptionField = new FieldExtension();
    exceptionField.setFieldName("jarLocation");
    exceptionField.setExpression("${jarLocation}");
    fieldExtensionList.add(exceptionField);
    exceptionField = new FieldExtension();
    exceptionField.setFieldName("mainClass");
    exceptionField.setExpression("${mainClass}");
    fieldExtensionList.add(exceptionField);
    exceptionField = new FieldExtension();
    exceptionField.setFieldName("scriptArguments");
    exceptionField.setExpression("${scriptArguments}");
    fieldExtensionList.add(exceptionField);
    List<Parameter> parameters = new ArrayList<>(getCommonParameters("Hadoop jar Step"));
    Parameter parameter = new Parameter("jarLocation", "s3://test-bucket-managed/app-a/test/hadoop-mapreduce-examples-2.4.0.jar");
    parameters.add(parameter);
    parameter = new Parameter("mainClass", "wordcount");
    parameters.add(parameter);
    parameter = new Parameter("scriptArguments", "arg1|arg/|withpipe|arg2|arg3");
    parameters.add(parameter);
    testActivitiAddEmrStepSuccess(AddEmrHadoopJarStep.class.getCanonicalName(), fieldExtensionList, parameters);
}
Also used : FieldExtension(org.activiti.bpmn.model.FieldExtension) ArrayList(java.util.ArrayList) Parameter(org.finra.herd.model.api.xml.Parameter) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 17 with Parameter

use of org.finra.herd.model.api.xml.Parameter in project herd by FINRAOS.

the class ActivitiDelegateTest method testActivitiReportableError.

/**
 * This method tests the scenario when an error that is not workflow related is throws while workflow is executing an Async type task like Timer. This error
 * is logged as ERROR.
 */
@Test(expected = ActivitiException.class)
public void testActivitiReportableError() throws Exception {
    BpmnModel bpmnModel = getBpmnModelForXmlResource(ACTIVITI_XML_HERD_TIMER_WITH_CLASSPATH);
    ServiceTask serviceTask = (ServiceTask) bpmnModel.getProcesses().get(0).getFlowElement("servicetask1");
    FieldExtension exceptionField = new FieldExtension();
    exceptionField.setFieldName("exceptionToThrow");
    exceptionField.setExpression("${exceptionToThrow}");
    serviceTask.getFieldExtensions().add(exceptionField);
    jobDefinitionServiceTestHelper.createJobDefinitionForActivitiXml(getActivitiXmlFromBpmnModel(bpmnModel));
    List<Parameter> parameters = new ArrayList<>();
    Parameter parameter = new Parameter("exceptionToThrow", MockJavaDelegate.EXCEPTION_BPMN_ERROR);
    parameters.add(parameter);
    Job job = jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME, parameters));
    org.activiti.engine.runtime.Job timer = activitiManagementService.createJobQuery().processInstanceId(job.getId()).timers().singleResult();
    if (timer != null) {
        executeWithoutLogging(Arrays.asList(ActivitiRuntimeHelper.class, TimerExecuteNestedActivityJobHandler.class), () -> {
            activitiManagementService.executeJob(timer.getId());
        });
    }
}
Also used : ServiceTask(org.activiti.bpmn.model.ServiceTask) FieldExtension(org.activiti.bpmn.model.FieldExtension) ArrayList(java.util.ArrayList) Parameter(org.finra.herd.model.api.xml.Parameter) TimerExecuteNestedActivityJobHandler(org.activiti.engine.impl.jobexecutor.TimerExecuteNestedActivityJobHandler) Job(org.finra.herd.model.api.xml.Job) BpmnModel(org.activiti.bpmn.model.BpmnModel) Test(org.junit.Test) HerdActivitiServiceTaskTest(org.finra.herd.service.activiti.task.HerdActivitiServiceTaskTest)

Example 18 with Parameter

use of org.finra.herd.model.api.xml.Parameter in project herd by FINRAOS.

the class AddEmrMasterSecurityGroupTest method testAddEmrMasterSecurityGroup.

@Test
public void testAddEmrMasterSecurityGroup() throws Exception {
    // Create a pipe-separated list of security group IDs.
    final String securityGroupIds = EC2_SECURITY_GROUP_1 + "|" + EC2_SECURITY_GROUP_2;
    // Create EC2 on-demand pricing entities required for testing.
    ec2OnDemandPricingDaoTestHelper.createEc2OnDemandPricingEntities();
    // Create the namespace entity.
    NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
    // Create a trusting AWS account.
    trustingAccountDaoTestHelper.createTrustingAccountEntity(AWS_ACCOUNT_ID, AWS_ROLE_ARN);
    // Create an EMR cluster definition.
    emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, EMR_CLUSTER_DEFINITION_NAME, IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream()));
    // Create an EMR cluster definition override with an AWS account ID.
    EmrClusterDefinition emrClusterDefinitionOverride = new EmrClusterDefinition();
    emrClusterDefinitionOverride.setAccountId(AWS_ACCOUNT_ID);
    // Create an EMR cluster.
    emrService.createCluster(new EmrClusterCreateRequest(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, EMR_CLUSTER_NAME, NO_DRY_RUN, emrClusterDefinitionOverride));
    List<FieldExtension> fieldExtensionList = new ArrayList<>();
    fieldExtensionList.add(buildFieldExtension("namespace", "${namespace}"));
    fieldExtensionList.add(buildFieldExtension("emrClusterDefinitionName", "${emrClusterDefinitionName}"));
    fieldExtensionList.add(buildFieldExtension("emrClusterName", "${emrClusterName}"));
    fieldExtensionList.add(buildFieldExtension("securityGroupIds", "${securityGroupIds}"));
    fieldExtensionList.add(buildFieldExtension("accountId", "${accountId}"));
    List<Parameter> parameters = new ArrayList<>();
    parameters.add(buildParameter("namespace", NAMESPACE));
    parameters.add(buildParameter("emrClusterDefinitionName", EMR_CLUSTER_DEFINITION_NAME));
    parameters.add(buildParameter("emrClusterName", EMR_CLUSTER_NAME));
    parameters.add(buildParameter("securityGroupIds", securityGroupIds));
    parameters.add(buildParameter("accountId", AWS_ACCOUNT_ID));
    Map<String, Object> variableValuesToValidate = new HashMap<>();
    variableValuesToValidate.put(AddEmrMasterSecurityGroup.VARIABLE_EMR_MASTER_SECURITY_GROUPS, securityGroupIds);
    testActivitiServiceTaskSuccess(AddEmrMasterSecurityGroup.class.getCanonicalName(), fieldExtensionList, parameters, variableValuesToValidate);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) EmrClusterCreateRequest(org.finra.herd.model.api.xml.EmrClusterCreateRequest) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EmrClusterDefinition(org.finra.herd.model.api.xml.EmrClusterDefinition) FieldExtension(org.activiti.bpmn.model.FieldExtension) Parameter(org.finra.herd.model.api.xml.Parameter) Test(org.junit.Test)

Example 19 with Parameter

use of org.finra.herd.model.api.xml.Parameter in project herd by FINRAOS.

the class SystemJobServiceTest method testRunSystemJobBusinessObjectDataFinalizeRestoreInvalidParameters.

@Test
public void testRunSystemJobBusinessObjectDataFinalizeRestoreInvalidParameters() throws Exception {
    // Try to run a system job when too many parameters are specified.
    try {
        systemJobService.runSystemJob(new SystemJobRunRequest(BusinessObjectDataFinalizeRestoreJob.JOB_NAME, Arrays.asList(new Parameter(ATTRIBUTE_NAME_1_MIXED_CASE, ATTRIBUTE_VALUE_1), new Parameter(ATTRIBUTE_NAME_2_MIXED_CASE, ATTRIBUTE_VALUE_2))));
        fail("Should throw an IllegalArgumentException when too many parameters are specified.");
    } catch (IllegalArgumentException e) {
        assertEquals(String.format("Too many parameters are specified for \"%s\" system job.", BusinessObjectDataFinalizeRestoreJob.JOB_NAME), e.getMessage());
    }
    // Try to run a system job when invalid parameter name is specified.
    try {
        systemJobService.runSystemJob(new SystemJobRunRequest(BusinessObjectDataFinalizeRestoreJob.JOB_NAME, Arrays.asList(new Parameter(ATTRIBUTE_NAME_1_MIXED_CASE, ATTRIBUTE_VALUE_1))));
        fail("Should throw an IllegalArgumentException when invalid parameter name is specified.");
    } catch (IllegalArgumentException e) {
        assertEquals(String.format("Parameter \"%s\" is not supported by \"%s\" system job.", ATTRIBUTE_NAME_1_MIXED_CASE, BusinessObjectDataFinalizeRestoreJob.JOB_NAME), e.getMessage());
    }
    // Try to run a system job when invalid parameter value is specified.
    try {
        systemJobService.runSystemJob(new SystemJobRunRequest(BusinessObjectDataFinalizeRestoreJob.JOB_NAME, Arrays.asList(new Parameter(ConfigurationValue.BDATA_FINALIZE_RESTORE_JOB_MAX_BDATA_INSTANCES.getKey(), "NOT_AN_INTEGER"))));
        fail("Should throw an IllegalArgumentException when invalid parameter value is specified.");
    } catch (IllegalArgumentException e) {
        assertEquals(String.format("Parameter \"%s\" specifies a non-integer value \"NOT_AN_INTEGER\".", ConfigurationValue.BDATA_FINALIZE_RESTORE_JOB_MAX_BDATA_INSTANCES.getKey()), e.getMessage());
    }
}
Also used : SystemJobRunRequest(org.finra.herd.model.api.xml.SystemJobRunRequest) Parameter(org.finra.herd.model.api.xml.Parameter) Test(org.junit.Test)

Example 20 with Parameter

use of org.finra.herd.model.api.xml.Parameter in project herd by FINRAOS.

the class SystemJobServiceTest method testRunSystemJobFileUploadCleanup.

// File upload cleanup system job
@Test
public void testRunSystemJobFileUploadCleanup() throws Exception {
    // Create the system job run request.
    SystemJobRunRequest systemJobRunRequest = new SystemJobRunRequest(FileUploadCleanupJob.JOB_NAME, Arrays.asList(new Parameter(ConfigurationValue.FILE_UPLOAD_CLEANUP_JOB_THRESHOLD_MINUTES.getKey(), String.valueOf(INTEGER_VALUE))));
    // Request to run the system job.
    SystemJobRunResponse resultSystemJobRunResponse = systemJobService.runSystemJob(systemJobRunRequest);
    // Validate the returned object.
    assertEquals(new SystemJobRunResponse(FileUploadCleanupJob.JOB_NAME, Arrays.asList(new Parameter(ConfigurationValue.FILE_UPLOAD_CLEANUP_JOB_THRESHOLD_MINUTES.getKey(), String.valueOf(INTEGER_VALUE)))), resultSystemJobRunResponse);
}
Also used : SystemJobRunRequest(org.finra.herd.model.api.xml.SystemJobRunRequest) Parameter(org.finra.herd.model.api.xml.Parameter) SystemJobRunResponse(org.finra.herd.model.api.xml.SystemJobRunResponse) Test(org.junit.Test)

Aggregations

Parameter (org.finra.herd.model.api.xml.Parameter)148 Test (org.junit.Test)121 ArrayList (java.util.ArrayList)98 FieldExtension (org.activiti.bpmn.model.FieldExtension)64 HashMap (java.util.HashMap)61 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)30 Job (org.finra.herd.model.api.xml.Job)30 SystemJobRunRequest (org.finra.herd.model.api.xml.SystemJobRunRequest)20 SystemJobRunResponse (org.finra.herd.model.api.xml.SystemJobRunResponse)14 S3PropertiesLocation (org.finra.herd.model.api.xml.S3PropertiesLocation)13 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)13 BusinessObjectDataAttribute (org.finra.herd.model.api.xml.BusinessObjectDataAttribute)12 JobDefinition (org.finra.herd.model.api.xml.JobDefinition)9 BusinessObjectDataAttributeEntity (org.finra.herd.model.jpa.BusinessObjectDataAttributeEntity)9 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)8 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)7 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)6 JobAction (org.finra.herd.model.api.xml.JobAction)6 NotificationRegistrationKey (org.finra.herd.model.api.xml.NotificationRegistrationKey)6 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)5