Search in sources :

Example 21 with DataGridResource

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

the class ResourceController method addParentToJSON.

/*
	 * *****************************************************************************
	 * ****** ****************************** PRIVATE METHODS
	 * ************************************
	 * *****************************************************************************
	 * ******
	 */
/**
 * Add a resource and its children to a JSON Tree
 *
 * @param rescParent
 * @param jsonParent
 * @param jsonChildren
 * @param dataGridResourcesMap
 */
private void addParentToJSON(DataGridResource rescParent, JSONObject jsonParent, JSONArray jsonChildren, Map<String, DataGridResource> dataGridResourcesMap, boolean isDashboard) {
    if (rescParent == null)
        return;
    String icon = isDashboard ? treeImagePathForDashboard : treeImagePath;
    try {
        JSONObject element = new JSONObject();
        element.put("name", rescParent.getName());
        element.put("icon", icon);
        JSONArray childrenOfElement = new JSONArray();
        for (String childResource : rescParent.getChildren()) {
            DataGridResource child = dataGridResourcesMap.get(childResource);
            addParentToJSON(child, element, childrenOfElement, dataGridResourcesMap, isDashboard);
        }
        jsonChildren.put(element);
        jsonParent.put("children", jsonChildren);
    } catch (JSONException e) {
        logger.error("Could not create JSON Tree: ", e);
    }
    return;
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) JSONException(org.codehaus.jettison.json.JSONException) DataGridResource(com.emc.metalnx.core.domain.entity.DataGridResource)

Example 22 with DataGridResource

use of com.emc.metalnx.core.domain.entity.DataGridResource 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 23 with DataGridResource

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

the class ResourceServiceImpl method deleteResource.

@Override
public boolean deleteResource(String resourceName) {
    if (resourceName.isEmpty()) {
        logger.error("Could not delete resource: name cannot be empty.");
        return false;
    }
    boolean isResourceDeleted = true;
    try {
        DataGridResource dgRescToRemove = find(resourceName);
        if (dgRescToRemove == null) {
            logger.error("Could not delete resource: resource {} not found.", resourceName);
            return false;
        }
        ResourceAO resourceAO = irodsServices.getResourceAO();
        // that resource and its parent
        if (!dgRescToRemove.isFirstLevelResc()) {
            resourceAO.removeChildFromResource(dgRescToRemove.getParent(), resourceName);
        }
        deleteChildrenFromResource(dgRescToRemove);
        resourceAO.deleteResource(resourceName);
    } catch (Exception e) {
        logger.error("Could not delete resource " + resourceName + ": ", e);
        isResourceDeleted = false;
    }
    return isResourceDeleted;
}
Also used : ResourceAO(org.irods.jargon.core.pub.ResourceAO) DataGridResource(com.emc.metalnx.core.domain.entity.DataGridResource) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) JargonException(org.irods.jargon.core.exception.JargonException) UnknownHostException(java.net.UnknownHostException) DataGridServerException(com.emc.metalnx.core.domain.exceptions.DataGridServerException)

Example 24 with DataGridResource

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

the class ResourceServiceImpl method getResourcesOfAServer.

@Override
public List<DataGridResource> getResourcesOfAServer(String serverName, List<DataGridResource> dataGridResources) throws DataGridConnectionRefusedException {
    logger.info("Get resources of a specific server (using cache)");
    if (dataGridResources == null || dataGridResources.isEmpty()) {
        logger.info("No cache provided. Calling the grid.");
        dataGridResources = findAll();
    }
    List<DataGridResource> dataGridResourcesOfAServer = new ArrayList<DataGridResource>();
    for (DataGridResource dataGridResource : dataGridResources) {
        if (dataGridResource.getHost().compareTo(serverName) == 0) {
            dataGridResourcesOfAServer.add(dataGridResource);
        }
    }
    return dataGridResourcesOfAServer;
}
Also used : ArrayList(java.util.ArrayList) DataGridResource(com.emc.metalnx.core.domain.entity.DataGridResource)

Example 25 with DataGridResource

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

the class ResourceServiceImpl method find.

@Override
public DataGridResource find(String resourceName) throws DataGridConnectionRefusedException {
    logger.info("Find specific resource by name");
    if (resourceName == null || resourceName.isEmpty()) {
        return null;
    }
    DataGridResource dgResc = null;
    List<DataGridResource> resources = findAll();
    for (DataGridResource r : resources) {
        if (resourceName.equals(r.getName())) {
            dgResc = r;
            break;
        }
    }
    logger.info("resource found:{}", dgResc);
    return dgResc;
}
Also used : DataGridResource(com.emc.metalnx.core.domain.entity.DataGridResource)

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