use of org.irods.jargon.core.pub.domain.Resource in project metalnx-web by irods-contrib.
the class ResourceServiceImpl method findAll.
@Override
public List<DataGridResource> findAll() throws DataGridConnectionRefusedException {
logger.info("Find all resources in the grid");
List<DataGridResource> dataGridResources = new ArrayList<DataGridResource>();
ResourceAO resourceAO = irodsServices.getResourceAO();
try {
List<Resource> resources = resourceAO.findAll();
for (Resource irodsResource : resources) {
DataGridResource newDataGridResource = getDataGridResource(irodsResource);
dataGridResources.add(newDataGridResource);
for (Resource r : resources) {
if (r.getParentName().equals(irodsResource.getName())) {
newDataGridResource.addChildResc(r.getName());
}
}
}
} catch (JargonException e) {
logger.error("Could not find all resources: ", e);
}
logger.debug("got all resources");
// sorting this list alphabetically
Collections.sort(dataGridResources);
logger.debug("sorted...");
return dataGridResources;
}
use of org.irods.jargon.core.pub.domain.Resource in project metalnx-web by irods-contrib.
the class ResourceServiceImpl method getImmediateChildren.
@Override
public List<String> getImmediateChildren(String resourceName) throws DataGridConnectionRefusedException {
try {
ResourceAO resourceAO = irodsServices.getResourceAO();
Resource irodsResource = resourceAO.findByName(resourceName);
return irodsResource.getImmediateChildren();
} catch (JargonException e) {
logger.error("Could not get immediate children of resource " + resourceName + ": ", e);
}
return new ArrayList<String>();
}
use of org.irods.jargon.core.pub.domain.Resource in project metalnx-web by irods-contrib.
the class ResourceServiceImpl method createResource.
@Override
public boolean createResource(DataGridResource newDataGridResource) throws DataGridConnectionRefusedException {
try {
ResourceAO resourceAO = irodsServices.getResourceAO();
ZoneAO zoneAO = irodsServices.getZoneAO();
// mapping data grid resource to iRODS Resource
Resource irodsResource = new Resource();
irodsResource.setName(newDataGridResource.getName());
irodsResource.setType(newDataGridResource.getType());
irodsResource.setZone(zoneAO.getZoneByName(newDataGridResource.getZone()));
irodsResource.setCreateTime(newDataGridResource.getCreateTime());
irodsResource.setModifyTime(newDataGridResource.getModifyTime());
irodsResource.setStatus(newDataGridResource.getStatus());
irodsResource.setInfo(newDataGridResource.getInfo());
irodsResource.setParentName(newDataGridResource.getParent());
irodsResource.setVaultPath(newDataGridResource.getPath());
irodsResource.setLocation(newDataGridResource.getHost());
// context string is not always set
if (newDataGridResource.getContextString() != null) {
irodsResource.setContextString(newDataGridResource.getContextString());
}
// adding the new resource to iRODS
resourceAO.addResource(irodsResource);
return true;
} catch (JargonException e) {
logger.error("Could not create resource: ", e);
}
return false;
}
use of org.irods.jargon.core.pub.domain.Resource in project metalnx-web by irods-contrib.
the class RuleDeploymentServiceImpl method deployRule.
@Override
public void deployRule(MultipartFile file) throws DataGridException, JargonException {
logger.info("Deploying rule");
if (file == null) {
logger.error("File could not be sent to the data grid. Rule file is null.");
throw new DataGridException("Rule file is null.");
}
if (!ruleCacheExists()) {
logger.info("Rule cache does not exist. Creating one.");
createRuleCache();
}
InputStream inputStream;
try {
inputStream = file.getInputStream();
} catch (IOException e) {
logger.error("Could not get input stream from rule file: ", e.getMessage());
throw new DataGridException("Could not get input stream from ruleFile.");
}
// Getting DataObjectAO in order to create the new rule file
IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
Stream2StreamAO stream2StreamA0 = irodsServices.getStream2StreamAO();
IRODSFile targetFile = null;
try {
String ruleCacheDirPath = getRuleCachePath();
String ruleName = file.getOriginalFilename().isEmpty() ? file.getName() : file.getOriginalFilename();
targetFile = irodsFileFactory.instanceIRODSFile(ruleCacheDirPath, ruleName);
stream2StreamA0.transferStreamToFileUsingIOStreams(inputStream, (File) targetFile, 0, BUFFER_SIZE);
String resourceName = irodsServices.getDefaultStorageResource();
Resource resc = irodsServices.getResourceAO().findByName(resourceName);
String vaultPath = resc.getVaultPath();
String host = resc.getLocation();
String ruleVaultPath = String.format("%s/%s/%s", vaultPath, RULE_CACHE_DIR_NAME, ruleName);
String ruleNameWithoutExtension = FilenameUtils.removeExtension(ruleName);
ruleService.execDeploymentRule(host, ruleNameWithoutExtension, ruleVaultPath);
} catch (JargonException e) {
if (targetFile != null)
fos.deleteDataObject(targetFile.getPath(), true);
logger.error("Upload stream failed from Metalnx to the data grid. {}", e.getMessage());
throw new DataGridException("Upload failed. Resource(s) might be full.");
} finally {
try {
// Closing streams opened
inputStream.close();
} catch (IOException e) {
logger.error("Could close stream: ", e.getMessage());
}
}
}
Aggregations