Search in sources :

Example 1 with Resource

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;
}
Also used : ResourceAO(org.irods.jargon.core.pub.ResourceAO) JargonException(org.irods.jargon.core.exception.JargonException) ArrayList(java.util.ArrayList) Resource(org.irods.jargon.core.pub.domain.Resource) DataGridResource(com.emc.metalnx.core.domain.entity.DataGridResource) DataGridResource(com.emc.metalnx.core.domain.entity.DataGridResource)

Example 2 with Resource

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>();
}
Also used : ResourceAO(org.irods.jargon.core.pub.ResourceAO) JargonException(org.irods.jargon.core.exception.JargonException) Resource(org.irods.jargon.core.pub.domain.Resource) DataGridResource(com.emc.metalnx.core.domain.entity.DataGridResource) ArrayList(java.util.ArrayList)

Example 3 with Resource

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;
}
Also used : ResourceAO(org.irods.jargon.core.pub.ResourceAO) JargonException(org.irods.jargon.core.exception.JargonException) Resource(org.irods.jargon.core.pub.domain.Resource) DataGridResource(com.emc.metalnx.core.domain.entity.DataGridResource) ZoneAO(org.irods.jargon.core.pub.ZoneAO)

Example 4 with Resource

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());
        }
    }
}
Also used : IRODSFileFactory(org.irods.jargon.core.pub.io.IRODSFileFactory) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) InputStream(java.io.InputStream) Stream2StreamAO(org.irods.jargon.core.pub.Stream2StreamAO) JargonException(org.irods.jargon.core.exception.JargonException) Resource(org.irods.jargon.core.pub.domain.Resource) IOException(java.io.IOException) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile)

Aggregations

JargonException (org.irods.jargon.core.exception.JargonException)4 Resource (org.irods.jargon.core.pub.domain.Resource)4 DataGridResource (com.emc.metalnx.core.domain.entity.DataGridResource)3 ResourceAO (org.irods.jargon.core.pub.ResourceAO)3 ArrayList (java.util.ArrayList)2 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Stream2StreamAO (org.irods.jargon.core.pub.Stream2StreamAO)1 ZoneAO (org.irods.jargon.core.pub.ZoneAO)1 IRODSFile (org.irods.jargon.core.pub.io.IRODSFile)1 IRODSFileFactory (org.irods.jargon.core.pub.io.IRODSFileFactory)1