Search in sources :

Example 6 with DataGridResource

use of com.emc.metalnx.core.domain.entity.DataGridResource in project metalnx-web by irods-contrib.

the class ResourceController method isValidResourceName.

/*
	 * *****************************************************************************
	 * ********* ****************************** VALIDATION METHODS
	 * ************************************
	 * *****************************************************************************
	 * *********
	 */
/**
 * Validates a resource name in iRODS
 *
 * @param resourceName
 *            which is the resource name to be validated
 * @return true, if the username can be used. False, otherwise.
 * @throws DataGridConnectionRefusedException
 */
@ResponseBody
@RequestMapping(value = "isValidResourceName/{resourceName}/", method = RequestMethod.GET)
public String isValidResourceName(@PathVariable String resourceName) throws DataGridConnectionRefusedException {
    String rc = "false";
    if (resourceName.compareTo("") != 0) {
        // if no resources are found with this name, it means this resource name can be
        // used
        DataGridResource dataGridResource = resourceService.find(resourceName);
        rc = dataGridResource == null ? "true" : "false";
        if (resourceName.contains("%20") || resourceName.contains(" ")) {
            rc = "false";
        }
    }
    return rc;
}
Also used : DataGridResource(com.emc.metalnx.core.domain.entity.DataGridResource) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with DataGridResource

use of com.emc.metalnx.core.domain.entity.DataGridResource in project metalnx-web by irods-contrib.

the class ResourceController method viewResourceInfo.

/**
 * Gets all information of a resource
 *
 * @return
 * @throws DataGridConnectionRefusedException
 */
@RequestMapping(value = "/viewInfo/{resourceName}", method = RequestMethod.GET)
@ResponseBody
public String viewResourceInfo(@PathVariable String resourceName) throws DataGridConnectionRefusedException {
    logger.info("creating JSON for resource info");
    JSONObject jsonObject = null;
    DataGridResource dataGridResource = null;
    try {
        jsonObject = new JSONObject();
        if (resourceName.compareTo(zoneName) == 0) {
            jsonObject.put("zoneName", zoneName);
        } else {
            dataGridResource = resourceService.find(resourceName);
            if (dataGridResource != null) {
                jsonObject.put("name", dataGridResource.getName());
                // TODO2 - resource type is being returned in contextString variable and not in
                // type
                jsonObject.put("type", dataGridResource.getType());
                jsonObject.put("zone", dataGridResource.getZone());
                jsonObject.put("host", dataGridResource.getHost());
                jsonObject.put("path", dataGridResource.getPath());
                jsonObject.put("parent", dataGridResource.getParent());
                jsonObject.put("info", dataGridResource.getInfo());
                jsonObject.put("status", dataGridResource.getStatus());
                jsonObject.put("ip", machineInfoService.getAddress(dataGridResource.getHost()));
            }
        }
    } catch (JSONException e) {
        logger.error("Could not create JSON for resource info: ", e);
    } catch (UnknownHostException e) {
        logger.error("Could not find the IP address of " + dataGridResource.getHost());
    }
    return jsonObject.toString();
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) UnknownHostException(java.net.UnknownHostException) JSONException(org.codehaus.jettison.json.JSONException) DataGridResource(com.emc.metalnx.core.domain.entity.DataGridResource) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 8 with DataGridResource

use of com.emc.metalnx.core.domain.entity.DataGridResource in project metalnx-web by irods-contrib.

the class UploadServiceImpl method processUploadRules.

/**
 * @param targetPath
 * @param destResc
 * @param targetFile
 * @throws DataGridConnectionRefusedException
 * @throws JargonException
 * @throws IOException
 * @throws DataGridRuleException
 * @throws FileNotFoundException
 */
private void processUploadRules(String targetPath, String destResc, IRODSFile targetFile) throws DataGridConnectionRefusedException, JargonException, IOException, DataGridRuleException, FileNotFoundException {
    // Getting list of resources for upload
    HashMap<String, String> resourceMap = null;
    logger.info("getting resourceMap for upload");
    ResourceAO resourceAO = is.getResourceAO();
    resourceMap = DataGridUtils.buildMapForResourcesNamesAndMountPoints(resourceAO.findAll());
    String objPath = targetFile.getCanonicalPath();
    logger.info("getting file path");
    String filePath = resourceMap.get(destResc) + objPath.substring(objPath.indexOf("/", 1), objPath.length());
    logger.info("file path:{}", filePath);
    logger.info("get resource based on dest:{}", destResc);
    DataGridResource dgDestResc = resourceService.find(destResc);
    if (dgDestResc == null) {
        logger.info("no resource found, ignoring rules");
    /*
			 * this may be further refined in issue File upload when no resource defined can
			 * result in NPE #29 as this functionality is better understood. This gives an
			 * escape route as something of a temporary work-around - mc
			 */
    }
    String host = dgDestResc.getHost();
    logger.info("executing rules...");
    rs.execBamCramMetadataRule(host, objPath, filePath);
    rs.execVCFMetadataRule(host, objPath, filePath);
    rs.execPopulateMetadataRule(host, objPath);
    rs.execImageRule(host, objPath, filePath);
    rs.execIlluminaMetadataRule(dgDestResc, targetPath, objPath);
    rs.execManifestFileRule(host, targetPath, objPath, filePath);
    logger.info("rules executed");
}
Also used : ResourceAO(org.irods.jargon.core.pub.ResourceAO) DataGridResource(com.emc.metalnx.core.domain.entity.DataGridResource)

Example 9 with DataGridResource

use of com.emc.metalnx.core.domain.entity.DataGridResource in project metalnx-web by irods-contrib.

the class BrowseController method getFileInfo.

/**
 * Gets checksum, total number of replicas and where each replica lives in the
 * data grid for a specific data object
 *
 * @param model
 * @param path
 *            path to the data object to get checksum and replica information
 * @return the template that shows the data object information
 * @throws DataGridException
 * @throws FileNotFoundException
 */
@RequestMapping(value = "/info/", method = RequestMethod.POST)
public String getFileInfo(final Model model, final String path) throws DataGridException, FileNotFoundException {
    logger.info("CollectionController getInfoFile() starts :: " + path);
    DataGridCollectionAndDataObject dataGridObj = null;
    Map<DataGridCollectionAndDataObject, DataGridResource> replicasMap = null;
    try {
        dataGridObj = cs.findByName(path);
        if (dataGridObj != null && !dataGridObj.isCollection()) {
            replicasMap = cs.listReplicasByResource(path);
            dataGridObj.setChecksum(cs.getChecksum(path));
            dataGridObj.setNumberOfReplicas(cs.getTotalNumberOfReplsForDataObject(path));
            dataGridObj.setReplicaNumber(String.valueOf(cs.getReplicationNumber(path)));
            permissionsService.resolveMostPermissiveAccessForUser(dataGridObj, loggedUserUtils.getLoggedDataGridUser());
        }
    } catch (DataGridConnectionRefusedException e) {
        logger.error("Could not connect to the data grid", e);
        throw e;
    } catch (DataGridException e) {
        logger.error("Could not get file info for {}", path, e);
        throw e;
    } catch (FileNotFoundException e) {
        logger.error("file does not exist for:{}", path, e);
        throw e;
    }
    model.addAttribute("collectionAndDataObject", dataGridObj);
    model.addAttribute("currentCollection", dataGridObj);
    model.addAttribute("replicasMap", replicasMap);
    model.addAttribute("infoFlag", true);
    logger.info("CollectionController getInfoFile() ends !!");
    return "collections/info :: infoView";
// return "collections/info";
}
Also used : DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) FileNotFoundException(org.irods.jargon.core.exception.FileNotFoundException) DataGridResource(com.emc.metalnx.core.domain.entity.DataGridResource) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with DataGridResource

use of com.emc.metalnx.core.domain.entity.DataGridResource in project metalnx-web by irods-contrib.

the class ServerServiceImpl method getAllNonResourceServers.

@Override
public List<DataGridServer> getAllNonResourceServers(List<DataGridServer> servers, HashMap<String, DataGridServer> serverMapInCache, List<DataGridResource> dataGridResources) throws DataGridConnectionRefusedException {
    logger.info("Getting the list of all non-resource servers from the Grid using Resource cache");
    List<DataGridServer> nonResourceServers = new ArrayList<DataGridServer>();
    for (DataGridServer server : servers) {
        if (server.getHostname().compareToIgnoreCase("localhost") == 0) {
            continue;
        }
        ObjectMapper mapper = new ObjectMapper();
        String mounts = null;
        try {
            String serverInfo = getServerInfo(server.getHostname());
            JsonNode json = mapper.readTree(serverInfo);
            mounts = json.get("mounts").toString();
        } catch (JsonProcessingException e) {
            logger.error("Could not parse server information", e.getMessage());
        } catch (IOException e) {
            logger.error("Could not parse server information", e.getMessage());
        }
        if (mounts != null && !mounts.isEmpty()) {
            HashMap<String, String> hashMap = ServerUtil.getNFSMountMap(mounts);
            List<DataGridResource> resources = null;
            try {
                logger.info("Getting resources of a server {}", server.getHostname());
                resources = resourceService.getResourcesOfAServer(server.getHostname(), dataGridResources);
            } catch (DataGridConnectionRefusedException e) {
                // any
                if (serverMapInCache != null) {
                    resources = serverMapInCache.get(server.getHostname()).getResources();
                } else {
                    resources = new ArrayList<DataGridResource>();
                }
            }
            for (DataGridResource resource : resources) {
                if (hashMap.containsKey(resource.getPath())) {
                    String host = hashMap.get(resource.getPath());
                    DataGridServer newServer = new DataGridServer();
                    try {
                        host = reverseDnsLookup.compareTo("true") == 0 ? machineInfoService.getHostName(host) : host;
                        newServer.setHostname(host);
                        newServer.setIp(machineInfoService.getAddress(host));
                    } catch (UnknownHostException e) {
                        logger.error("Could not resolve IP address for " + host);
                    }
                    if (!nonResourceServers.contains(newServer)) {
                        nonResourceServers.add(newServer);
                    }
                }
            }
        }
    }
    return nonResourceServers.isEmpty() ? null : nonResourceServers;
}
Also used : DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) UnknownHostException(java.net.UnknownHostException) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) DataGridServer(com.emc.metalnx.core.domain.entity.DataGridServer) DataGridResource(com.emc.metalnx.core.domain.entity.DataGridResource) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

DataGridResource (com.emc.metalnx.core.domain.entity.DataGridResource)34 ArrayList (java.util.ArrayList)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)6 DataGridServer (com.emc.metalnx.core.domain.entity.DataGridServer)5 IOException (java.io.IOException)4 UnknownHostException (java.net.UnknownHostException)4 JargonException (org.irods.jargon.core.exception.JargonException)4 ResourceAO (org.irods.jargon.core.pub.ResourceAO)4 DataGridCollectionAndDataObject (com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 Date (java.util.Date)3 JSONObject (org.codehaus.jettison.json.JSONObject)3 DataGridResourceType (com.emc.metalnx.core.domain.entity.DataGridResourceType)2 DataGridRule (com.emc.metalnx.core.domain.entity.DataGridRule)2 DataGridServerException (com.emc.metalnx.core.domain.exceptions.DataGridServerException)2 ResourceForm (com.emc.metalnx.modelattribute.resource.ResourceForm)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 JSONArray (org.codehaus.jettison.json.JSONArray)2