Search in sources :

Example 16 with DataGridConnectionRefusedException

use of com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException in project metalnx-web by irods-contrib.

the class PreviewServiceImpl method filePreview.

@Override
public boolean filePreview(String path, String mimeType, HttpServletResponse response) {
    logger.info("getting file preview  for {} ::" + path + " and mimetype :: " + mimeType);
    boolean isCopySuccessFul = true;
    IRODSFileInputStream irodsFileInputStream = null;
    IRODSFile irodsFile = null;
    try {
        IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
        irodsFile = irodsFileFactory.instanceIRODSFile(path);
        irodsFileInputStream = irodsFileFactory.instanceIRODSFileInputStream(irodsFile);
        response.setContentType(mimeType);
        FileCopyUtils.copy(irodsFileInputStream, response.getOutputStream());
    } catch (IOException | JargonException | DataGridConnectionRefusedException e) {
        e.printStackTrace();
        isCopySuccessFul = false;
    } finally {
        try {
            if (irodsFileInputStream != null)
                irodsFileInputStream.close();
            if (irodsFile != null)
                irodsFile.close();
        } catch (Exception e) {
            logger.error("Could not close stream(s): ", e.getMessage());
        }
    }
    return isCopySuccessFul;
}
Also used : IRODSFileFactory(org.irods.jargon.core.pub.io.IRODSFileFactory) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) IRODSFileInputStream(org.irods.jargon.core.pub.io.IRODSFileInputStream) JargonException(org.irods.jargon.core.exception.JargonException) IOException(java.io.IOException) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) IOException(java.io.IOException) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) JargonException(org.irods.jargon.core.exception.JargonException)

Example 17 with DataGridConnectionRefusedException

use of com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException in project metalnx-web by irods-contrib.

the class ResourceServiceImpl method getAllResourceServers.

@Override
public List<DataGridServer> getAllResourceServers(List<DataGridResource> resources) throws DataGridConnectionRefusedException {
    logger.info("Getting all resource servers");
    List<DataGridServer> servers = new ArrayList<>();
    boolean isResourceWithEmptyHost = false;
    for (DataGridResource resource : resources) {
        logger.debug("Listing resource information: {}", resource);
        if (resource.getContextString().contains("isi_host")) {
            continue;
        } else if (!resource.getHost().isEmpty()) {
            DataGridServer server = new DataGridServer();
            try {
                server.setHostname(resource.getHost());
                server.setIp(machineInfoService.getAddress(resource.getHost()));
                server.setResources(getResourcesOfAServer(server.getHostname(), resources));
            } catch (UnknownHostException e) {
                logger.error("Could not retrieve IP address for [{}]", resource.getHost());
                isResourceWithEmptyHost = true;
            } catch (DataGridConnectionRefusedException e) {
                logger.error("Could not get all resources of the server: ", resource.getHost());
                server.setResources(null);
            }
            if (!isResourceWithEmptyHost && !servers.contains(server)) {
                servers.add(server);
            }
        }
        isResourceWithEmptyHost = false;
    }
    Collections.sort(servers);
    return servers;
}
Also used : DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) UnknownHostException(java.net.UnknownHostException) ArrayList(java.util.ArrayList) DataGridResource(com.emc.metalnx.core.domain.entity.DataGridResource) DataGridServer(com.emc.metalnx.core.domain.entity.DataGridServer)

Example 18 with DataGridConnectionRefusedException

use of com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException in project metalnx-web by irods-contrib.

the class FileOperationServiceImpl method copyFileIntoHttpResponse.

/**
 * Copies a buffered input stream from a file to a HTTP response for
 * downloading.
 *
 * @param path
 *            path to the file in iRODS to be added to the HTTP response
 * @param response
 *            HTTP response to let the user download the file
 * @return True, if the file was successfully added to the HTTP response. False,
 *         otherwise.
 * @throws DataGridConnectionRefusedException
 *             is Metalnx cannot connect to the data grid
 */
private boolean copyFileIntoHttpResponse(String path, HttpServletResponse response) throws DataGridConnectionRefusedException {
    boolean isCopySuccessFul = true;
    IRODSFileInputStream irodsFileInputStream = null;
    IRODSFile irodsFile = null;
    logger.debug("Trying to copy path stream {} to user", path);
    try {
        String fileName = path.substring(path.lastIndexOf("/") + 1, path.length());
        logger.debug("The filename is [{}]", fileName);
        logger.debug("Initiating iRodsFileFactory");
        IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
        logger.debug("Getting iRodsFileFactory instance for {}", path);
        irodsFile = irodsFileFactory.instanceIRODSFile(path);
        logger.debug("Creating stream from {}", irodsFile);
        irodsFileInputStream = irodsFileFactory.instanceIRODSFileInputStream(irodsFile);
        // set file mime type
        response.setContentType(CONTENT_TYPE);
        response.setHeader("Content-Disposition", String.format(HEADER_FORMAT, fileName));
        response.setContentLength((int) irodsFile.length());
        FileCopyUtils.copy(irodsFileInputStream, response.getOutputStream());
    } catch (IOException e) {
        logger.error("Could not put the file in the Http response ", e);
        isCopySuccessFul = false;
    } catch (JargonException e) {
        logger.error("Could not copy file in the Http response: ", e.getMessage());
        isCopySuccessFul = false;
    } finally {
        try {
            if (irodsFileInputStream != null)
                irodsFileInputStream.close();
            if (irodsFile != null)
                irodsFile.close();
        } catch (Exception e) {
            logger.error("Could not close stream(s): ", e.getMessage());
        }
    }
    return isCopySuccessFul;
}
Also used : IRODSFileFactory(org.irods.jargon.core.pub.io.IRODSFileFactory) IRODSFileInputStream(org.irods.jargon.core.pub.io.IRODSFileInputStream) JargonException(org.irods.jargon.core.exception.JargonException) IOException(java.io.IOException) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile) DataGridChecksumException(com.emc.metalnx.core.domain.exceptions.DataGridChecksumException) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) DataNotFoundException(org.irods.jargon.core.exception.DataNotFoundException) JargonException(org.irods.jargon.core.exception.JargonException) DataGridReplicateException(com.emc.metalnx.core.domain.exceptions.DataGridReplicateException) DataGridRuleException(com.emc.metalnx.core.domain.exceptions.DataGridRuleException) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) IOException(java.io.IOException)

Example 19 with DataGridConnectionRefusedException

use of com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException in project metalnx-web by irods-contrib.

the class GroupServiceImpl method deleteGroupByGroupname.

@Override
public boolean deleteGroupByGroupname(String groupname) throws DataGridConnectionRefusedException {
    boolean groupDeleted = false;
    UserGroupAO groupAO = irodsServices.getGroupAO();
    try {
        DataGridGroup group = groupDao.findByGroupnameAndZone(groupname, configService.getIrodsZone());
        // remove group from the data grid
        groupAO.removeUserGroup(groupname);
        // Removing group bookmarks associated to this group
        userBookmarkService.removeBookmarkBasedOnPath(String.format("/%s/home/%s", configService.getIrodsZone(), groupname));
        groupBookmarkService.removeBookmarkBasedOnGroup(group);
        // remove user from the Mlx database
        groupDeleted = groupDao.deleteByGroupname(groupname);
    } catch (JargonException e) {
        logger.error("Could not execute removeUserGroup(String groupname)/" + "deleteByGroupname(groupname) on UserGroupAO/GroupDao class(es): ", e);
    } catch (Exception e) {
        logger.error("Could not execute delete group (dao)");
    }
    return groupDeleted;
}
Also used : JargonException(org.irods.jargon.core.exception.JargonException) UserGroupAO(org.irods.jargon.core.pub.UserGroupAO) DataGridGroup(com.emc.metalnx.core.domain.entity.DataGridGroup) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) DuplicateDataException(org.irods.jargon.core.exception.DuplicateDataException) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) JargonException(org.irods.jargon.core.exception.JargonException)

Example 20 with DataGridConnectionRefusedException

use of com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException in project metalnx-web by irods-contrib.

the class GroupServiceImpl method updateMemberList.

@Override
public boolean updateMemberList(DataGridGroup group, List<DataGridUser> users) throws DataGridConnectionRefusedException {
    try {
        UserGroupAO groupAO = irodsServices.getGroupAO();
        // Users that are currently on this group
        List<User> usersFromIrods = groupAO.listUserGroupMembers(group.getGroupname());
        // Building set with iRODS IDs already on this group
        HashMap<Long, User> idsFromIrods = new HashMap<Long, User>();
        for (User userFromIrods : usersFromIrods) {
            idsFromIrods.put(Long.valueOf(userFromIrods.getId()), userFromIrods);
        }
        // Building set with iRODS IDs coming from UI
        HashMap<Long, DataGridUser> idsFromUi = new HashMap<Long, DataGridUser>();
        for (DataGridUser userFromUi : users) {
            idsFromUi.put(userFromUi.getDataGridId(), userFromUi);
        }
        // Resolving differences from UI to iRODS
        Set<Long> keysFromUi = idsFromUi.keySet();
        Set<Long> keysFromIrods = idsFromIrods.keySet();
        for (Long dataGridId : keysFromUi) {
            if (!keysFromIrods.contains(dataGridId)) {
                attachUserToGroup(idsFromUi.get(dataGridId), group);
            }
        }
        for (Long dataGridId : keysFromIrods) {
            if (!keysFromUi.contains(dataGridId)) {
                DataGridUser user = new DataGridUser();
                user.setUsername(idsFromIrods.get(dataGridId).getName());
                removeUserFromGroup(user, group);
            }
        }
        return true;
    } catch (Exception e) {
        logger.info("Could not update [" + group.getGroupname() + "]: ", e);
    }
    return false;
}
Also used : DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) User(org.irods.jargon.core.pub.domain.User) DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) UserGroupAO(org.irods.jargon.core.pub.UserGroupAO) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) DuplicateDataException(org.irods.jargon.core.exception.DuplicateDataException) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) JargonException(org.irods.jargon.core.exception.JargonException)

Aggregations

DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)24 JargonException (org.irods.jargon.core.exception.JargonException)17 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)10 DataGridCollectionAndDataObject (com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 IOException (java.io.IOException)7 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)6 ArrayList (java.util.ArrayList)6 DataGridResource (com.emc.metalnx.core.domain.entity.DataGridResource)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 HashMap (java.util.HashMap)5 FileNotFoundException (org.irods.jargon.core.exception.FileNotFoundException)5 IRODSFile (org.irods.jargon.core.pub.io.IRODSFile)4 IRODSFileFactory (org.irods.jargon.core.pub.io.IRODSFileFactory)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 DataGridPageContext (com.emc.metalnx.core.domain.entity.DataGridPageContext)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ConnectException (java.net.ConnectException)3 UserGroupAO (org.irods.jargon.core.pub.UserGroupAO)3 DataGridGroup (com.emc.metalnx.core.domain.entity.DataGridGroup)2