in data-orchestrator/data-orchestrator-service/data-orchestrator-api-server/src/main/java/org/apache/airavata/datalake/orchestrator/handlers/async/OrchestratorEventProcessor.java [70:143]
private List<GenericResource> createResourceWithParentDirectories(String hostName, String storageId, String basePath,
String resourcePath, String resourceType, String user,
Map<String, GenericResource> resourceCache)
throws Exception {
List<GenericResource> resourceList = new ArrayList<>();
String parentType = "Storage";
String[] splitted = resourcePath.substring(basePath.length()).split("/");
String currentPath = basePath.endsWith("/") ? basePath.substring(0, basePath.length() - 1) : basePath;
String parentId = storageId;
for (int i = 0; i < splitted.length - 1; i++) {
String resourceName = splitted[i];
currentPath = currentPath + "/" + resourceName;
/*if (resourceCache.containsKey(currentPath)) {
resourceList.add(resourceCache.get(currentPath));
parentId = resourceCache.get(currentPath).getResourceId();
logger.info("Using cached resource with path {} for path {}", currentPath,
resourceCache.get(currentPath).getResourcePath());
continue;
}*/
String resourceId = Utils.getId(storageId + ":" + currentPath);
Optional<GenericResource> optionalGenericResource =
this.drmsConnector.createResource(notification.getAuthToken(),
notification.getTenantId(),
resourceId, resourceName, currentPath, parentId, "COLLECTION", parentType, user);
if (optionalGenericResource.isPresent()) {
parentId = optionalGenericResource.get().getResourceId();
parentType = "COLLECTION";
Map<String, String> metadata = new HashMap<>();
metadata.put("resourcePath", currentPath);
metadata.put("hostName", hostName);
this.drmsConnector.addResourceMetadata(notification.getAuthToken(),
notification.getTenantId(), parentId, user, parentType, metadata);
resourceCache.put(currentPath, optionalGenericResource.get());
resourceList.add(optionalGenericResource.get());
} else {
logger.error("Could not create a resource for path {}", currentPath);
throw new Exception("Could not create a resource for path " + currentPath);
}
}
currentPath = currentPath + "/" + splitted[splitted.length - 1];
Optional<GenericResource> optionalGenericResource =
this.drmsConnector.createResource(notification.getAuthToken(),
notification.getTenantId(),
Utils.getId(storageId + ":" + currentPath),
splitted[splitted.length - 1], currentPath,
parentId, resourceType, parentType, user);
if (optionalGenericResource.isPresent()) {
GenericResource genericResource = optionalGenericResource.get();
Map<String, String> metadata = new HashMap<>();
metadata.put("resourcePath", currentPath);
metadata.put("hostName", hostName);
this.drmsConnector.addResourceMetadata(notification.getAuthToken(),
notification.getTenantId(), genericResource.getResourceId(), user, resourceType, metadata);
resourceList.add(genericResource);
} else {
logger.error("Could not create a resource for path {}", currentPath);
throw new Exception("Could not create a resource for path " + currentPath);
}
return resourceList;
}