Search in sources :

Example 6 with RegServerAccessParamsDto

use of org.finra.herd.model.dto.RegServerAccessParamsDto in project herd by FINRAOS.

the class RetentionExpirationDestroyerApp method go.

/**
 * Runs the application by parsing the command line arguments and calling the controller to export business object data that passed its relative retention
 * expiration. This is the main entry into the application class itself and is typically called from a main method.
 *
 * @param args the command line arguments passed to the program
 *
 * @return the return value of the application
 * @throws Exception if any problems were encountered
 */
protected ToolsCommonConstants.ReturnValue go(String[] args) throws Exception {
    // Create the Spring application context.
    ApplicationContext applicationContext = createApplicationContext();
    // Parse the command line arguments and return a return value if we shouldn't continue processing (e.g. we displayed usage information, etc.).
    ToolsCommonConstants.ReturnValue returnValue = parseCommandLineArguments(args, applicationContext);
    if (returnValue != null) {
        return returnValue;
    }
    // Create a DTO to communicate with herd registration server.
    RegServerAccessParamsDto regServerAccessParamsDto = RegServerAccessParamsDto.builder().withRegServerHost(argParser.getStringValue(regServerHostOpt)).withRegServerPort(regServerPort).withUseSsl(useSsl).withUsername(argParser.getStringValue(usernameOpt)).withPassword(argParser.getStringValue(passwordOpt)).build();
    // Call the controller with the user specified parameters to perform the upload.
    RetentionExpirationDestroyerController controller = applicationContext.getBean(RetentionExpirationDestroyerController.class);
    controller.performRetentionExpirationDestruction(argParser.getFileValue(localInputFileOpt), regServerAccessParamsDto);
    // No exceptions were returned so return success.
    return ToolsCommonConstants.ReturnValue.SUCCESS;
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ToolsCommonConstants(org.finra.herd.tools.common.ToolsCommonConstants) RegServerAccessParamsDto(org.finra.herd.model.dto.RegServerAccessParamsDto)

Example 7 with RegServerAccessParamsDto

use of org.finra.herd.model.dto.RegServerAccessParamsDto in project herd by FINRAOS.

the class RetentionExpirationExporterControllerTest method testPerformRetentionExpirationExport.

@Test
public void testPerformRetentionExpirationExport() throws Exception {
    File outputFile = new File(LOCAL_OUTPUT_FILE);
    // Create and initialize the registration server DTO.
    RegServerAccessParamsDto regServerAccessParamsDto = RegServerAccessParamsDto.builder().withRegServerHost(WEB_SERVICE_HOSTNAME).withRegServerPort(WEB_SERVICE_HTTPS_PORT).withUseSsl(true).withUsername(WEB_SERVICE_HTTPS_USERNAME).withPassword(WEB_SERVICE_HTTPS_PASSWORD).build();
    // Perform the retention expiration export.
    retentionExpirationExporterController.performRetentionExpirationExport(NAMESPACE, BUSINESS_OBJECT_DEFINITION_NAME, outputFile, regServerAccessParamsDto, UDC_SERVICE_HOSTNAME);
    // Create the expected URI.
    String expectedUri = String.format("https://%s/data-entities/%s/%s", UDC_SERVICE_HOSTNAME, NAMESPACE, BUSINESS_OBJECT_DEFINITION_NAME);
    // Create the expected output file content.
    String expectedOutputFileContent = ("\"Namespace\",\"Business Object Definition Name\",\"Business Object Format Usage\",\"Business Object Format File Type\"," + "\"Business Object Format Version\",\"Primary Partition Value\",\"Sub-Partition Value 1\",\"Sub-Partition Value 2\"," + "\"Sub-Partition Value 3\",\"Sub-Partition Value 4\",\"Business Object Data Version\",\"Business Object Definition Display Name\"," + "\"Business Object Definition URI\"") + System.lineSeparator() + String.format("\"%s\",\"%s\",\"%s\",\"%s\",\"%d\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%d\",\"%s\",\"%s\"%n", NAMESPACE, BUSINESS_OBJECT_DEFINITION_NAME, BUSINESS_OBJECT_FORMAT_USAGE, BUSINESS_OBJECT_FORMAT_FILE_TYPE, BUSINESS_OBJECT_FORMAT_VERSION, "primaryPartitionValue", "subPartitionValue1", "subPartitionValue2", "subPartitionValue3", "subPartitionValue4", BUSINESS_OBJECT_DATA_VERSION, BUSINESS_OBJECT_DEFINITION_DISPLAY_NAME, expectedUri) + String.format("\"%s\",\"%s\",\"%s\",\"%s\",\"%d\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%d\",\"%s\",\"%s\"%n", NAMESPACE, BUSINESS_OBJECT_DEFINITION_NAME, BUSINESS_OBJECT_FORMAT_USAGE, BUSINESS_OBJECT_FORMAT_FILE_TYPE, BUSINESS_OBJECT_FORMAT_VERSION, "primaryPartitionValue", "", "", "", "", BUSINESS_OBJECT_DATA_VERSION, BUSINESS_OBJECT_DEFINITION_DISPLAY_NAME, expectedUri);
    // Validate the output file.
    String outputFileContent;
    try (FileInputStream inputStream = new FileInputStream(outputFile)) {
        outputFileContent = IOUtils.toString(inputStream, Charset.defaultCharset());
    }
    assertEquals(expectedOutputFileContent, outputFileContent);
}
Also used : RegServerAccessParamsDto(org.finra.herd.model.dto.RegServerAccessParamsDto) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 8 with RegServerAccessParamsDto

use of org.finra.herd.model.dto.RegServerAccessParamsDto in project herd by FINRAOS.

the class UploaderControllerTest method testPerformUploadInvalidLocalDir.

@Test
public void testPerformUploadInvalidLocalDir() throws Exception {
    // Create uploader input manifest file in LOCAL_TEMP_PATH_INPUT directory
    File manifestFile = createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), getTestUploaderInputManifestDto());
    Assert.assertTrue(manifestFile.isFile());
    // Try to run upload by specifying a non-existing local directory.
    S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = getTestS3FileTransferRequestParamsDto();
    s3FileTransferRequestParamsDto.setLocalPath(Paths.get(LOCAL_TEMP_PATH_INPUT.toString(), "I_DO_NOT_EXIST").toString());
    RegServerAccessParamsDto regServerAccessParamsDto = RegServerAccessParamsDto.builder().withRegServerHost(WEB_SERVICE_HOSTNAME).withRegServerPort(WEB_SERVICE_HTTPS_PORT).withUseSsl(true).withUsername(WEB_SERVICE_HTTPS_USERNAME).withPassword(WEB_SERVICE_HTTPS_PASSWORD).build();
    try {
        uploaderController.performUpload(regServerAccessParamsDto, manifestFile, s3FileTransferRequestParamsDto, false, false, TEST_RETRY_ATTEMPTS, TEST_RETRY_DELAY_SECS);
        fail("Should throw an IllegalArgumentException when local directory does not exist.");
    } catch (IllegalArgumentException e) {
        assertTrue(e.getMessage().startsWith("Invalid local base directory"));
    }
}
Also used : S3FileTransferRequestParamsDto(org.finra.herd.model.dto.S3FileTransferRequestParamsDto) RegServerAccessParamsDto(org.finra.herd.model.dto.RegServerAccessParamsDto) File(java.io.File) ManifestFile(org.finra.herd.model.dto.ManifestFile) Test(org.junit.Test)

Example 9 with RegServerAccessParamsDto

use of org.finra.herd.model.dto.RegServerAccessParamsDto in project herd by FINRAOS.

the class UploaderControllerTest method runUpload.

/**
 * Runs a normal upload scenario.
 *
 * @param numOfThreads the maximum number of threads to use for file transfer to S3
 * @param attributes the attributes to be associated with the test data being uploaded
 * @param createNewVersion if not set, only initial version of the business object data is allowed to be created
 * @param force if set, allows upload to proceed when the latest version of the business object data has UPLOADING status by invalidating that version
 * @param hostname optional override of the default web service hostname.
 * @param storageName optional storage name
 */
protected void runUpload(Integer numOfThreads, HashMap<String, String> attributes, Boolean createNewVersion, Boolean force, String hostname, String storageName) throws Exception {
    String hostnameToUse = hostname == null ? WEB_SERVICE_HOSTNAME : hostname;
    // Create local data files in LOCAL_TEMP_PATH_INPUT directory
    for (ManifestFile manifestFile : testManifestFiles) {
        createLocalFile(LOCAL_TEMP_PATH_INPUT.toString(), manifestFile.getFileName(), FILE_SIZE_1_KB);
    }
    // Create uploader input manifest file in LOCAL_TEMP_PATH_INPUT directory
    UploaderInputManifestDto uploaderInputManifestDto = getTestUploaderInputManifestDto();
    uploaderInputManifestDto.setAttributes(attributes);
    uploaderInputManifestDto.setStorageName(storageName);
    File manifestFile = createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto);
    Assert.assertTrue(manifestFile.isFile());
    // Perform the upload.
    S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = getTestS3FileTransferRequestParamsDto();
    s3FileTransferRequestParamsDto.setLocalPath(LOCAL_TEMP_PATH_INPUT.toString());
    s3FileTransferRequestParamsDto.setMaxThreads(numOfThreads);
    RegServerAccessParamsDto regServerAccessParamsDto = RegServerAccessParamsDto.builder().withRegServerHost(hostnameToUse).withRegServerPort(WEB_SERVICE_HTTPS_PORT).withUseSsl(true).withUsername(WEB_SERVICE_HTTPS_USERNAME).withPassword(WEB_SERVICE_HTTPS_PASSWORD).build();
    uploaderController.performUpload(regServerAccessParamsDto, manifestFile, s3FileTransferRequestParamsDto, createNewVersion, force, TEST_RETRY_ATTEMPTS, TEST_RETRY_DELAY_SECS);
}
Also used : S3FileTransferRequestParamsDto(org.finra.herd.model.dto.S3FileTransferRequestParamsDto) UploaderInputManifestDto(org.finra.herd.model.dto.UploaderInputManifestDto) RegServerAccessParamsDto(org.finra.herd.model.dto.RegServerAccessParamsDto) File(java.io.File) ManifestFile(org.finra.herd.model.dto.ManifestFile) ManifestFile(org.finra.herd.model.dto.ManifestFile)

Example 10 with RegServerAccessParamsDto

use of org.finra.herd.model.dto.RegServerAccessParamsDto in project herd by FINRAOS.

the class AbstractUploaderTest method setupEnv.

/**
 * Sets up the test environment.
 */
@Before
public void setupEnv() throws IOException {
    super.setupEnv();
    // Initialize the uploader web client instance.
    RegServerAccessParamsDto regServerAccessParamsDto = RegServerAccessParamsDto.builder().withRegServerHost(WEB_SERVICE_HOSTNAME).withRegServerPort(WEB_SERVICE_HTTPS_PORT).withUseSsl(true).withUsername(WEB_SERVICE_HTTPS_USERNAME).withPassword(WEB_SERVICE_HTTPS_PASSWORD).build();
    uploaderWebClient.setRegServerAccessParamsDto(regServerAccessParamsDto);
}
Also used : RegServerAccessParamsDto(org.finra.herd.model.dto.RegServerAccessParamsDto) Before(org.junit.Before)

Aggregations

RegServerAccessParamsDto (org.finra.herd.model.dto.RegServerAccessParamsDto)24 Test (org.junit.Test)13 File (java.io.File)12 S3FileTransferRequestParamsDto (org.finra.herd.model.dto.S3FileTransferRequestParamsDto)9 Before (org.junit.Before)5 ManifestFile (org.finra.herd.model.dto.ManifestFile)4 ApplicationContext (org.springframework.context.ApplicationContext)4 Path (java.nio.file.Path)3 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)3 S3KeyPrefixInformation (org.finra.herd.model.api.xml.S3KeyPrefixInformation)3 Storage (org.finra.herd.model.api.xml.Storage)3 StorageUnit (org.finra.herd.model.api.xml.StorageUnit)3 DownloaderInputManifestDto (org.finra.herd.model.dto.DownloaderInputManifestDto)3 S3FileTransferResultsDto (org.finra.herd.model.dto.S3FileTransferResultsDto)3 UploaderInputManifestDto (org.finra.herd.model.dto.UploaderInputManifestDto)3 S3Service (org.finra.herd.service.S3Service)3 BusinessObjectDataHelper (org.finra.herd.service.helper.BusinessObjectDataHelper)3 StorageFileHelper (org.finra.herd.service.helper.StorageFileHelper)3 StorageHelper (org.finra.herd.service.helper.StorageHelper)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3