Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ClientConfiguration.init(config.findString("storage.api.host"), config.findInteger("storage.api.port"));
- AprameyaClient client = new AprameyaClient();
- ResourceCreateRequest request = new ResourceCreateRequest();
- request.bucket = ctx.getProviderName().toUpperCase();
- request.co = ctx.getProviderName().toLowerCase();
- request.client = "INGESTOR";
- request.destination = STORAGE_AREA;
- request.resourceType = RESOURCE_TYPE;
- request.name = ctx.getFetchId();
- request.resources = new ArrayList<ResourceCreateInfo>();
- ArrayList<String> createdFilesForCleanup = new ArrayList<String>(paths.size());
- List<String> resources = null;
- try {
- for(String path: paths) {
- String filePath = ( (!path.startsWith("/"))? storageBase:"") + "/" + path;
- File fileToSave = new File(filePath);
- String fileName = fileToSave.getName();
- if(!fileToSave.exists()) {
- logger.error("File " + fileToSave.getAbsolutePath() + " does not exist");
- continue;
- }
- String tmpFileName = fileName + "-" + Long.toString(new java.util.Date().getTime());
- String outfilePath = tmpPath + "/" + tmpFileName;
- logger.info("Copying file " + fileToSave.getAbsolutePath() + " to storage file " + outfilePath);
- copyFileToStorage(fileToSave.getAbsolutePath(), outfilePath);
- createdFilesForCleanup.add(outfilePath);
- ResourceSourceInfo res = new ResourceSourceInfo();
- res.host = "";
- res.pass = "";
- res.port = "0";
- res.protocol = "file";
- res.user = "";
- res.path = "temp/" + tmpFileName;
- ResourceCreateInfo rc = new ResourceCreateInfo();
- rc.contentType = detectMimeType( fileName );
- rc.variant = "original";
- rc.group = ctx.getFetchId();
- rc.name = fileName;
- rc.source = res;
- request.resources.add(rc);
- System.out.println("Files to save: " + filePath);
- }
- ObjectMapper mapper = new ObjectMapper();
- logger.info(mapper.writeValueAsString(request));
- logger.info("Making storage call t osave meta files.");
- ResourceCreateResponse response = client.createResource(request);
- logger.info("Storage call succeeded");
- resources = new Vector<String>();
- for (MinimalResourceMetadata resource : response.resources) {
- resources.add(resource.id);
- logger.info("Resource id for file " + resource.name + " is " + resource.id);
- }
- }
- catch (Exception e) {
- logger.error("Error occurred while saving meta files to storage.", e);
- }
- finally {
- for(String fileToRemove: createdFilesForCleanup) {
- File cleanup = new File(fileToRemove);
- if(cleanup.delete()) {
- logger.info("Removed file " + cleanup);
- }
- else {
- logger.error("Failed to remove file: " + cleanup);
- }
- }
- }
- return resources;
Add Comment
Please, Sign In to add comment