Search in sources :

Example 31 with DataGridResource

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

the class StorageServiceImpl method totalUsedStorageOfAServer.

@Override
public long totalUsedStorageOfAServer(String hostname, String diskInfoJson, List<DataGridResource> currentServerResources) throws DataGridConnectionRefusedException {
    logger.info("Get total used storage of a specific server {}", hostname);
    long totalUsed = 0;
    if (hostname == null || diskInfoJson == null || hostname.isEmpty() || diskInfoJson.isEmpty()) {
        return totalUsed;
    }
    HashMap<String, String> usedMap = null;
    List<DataGridResource> dataGridResources = null;
    try {
        dataGridResources = resourceService.getResourcesOfAServer(hostname, currentServerResources);
    } catch (DataGridConnectionRefusedException e) {
        logger.error("Could not get resources from server ", hostname);
        // we will use all known resources of this server stored in cache
        if (currentServerResources != null) {
            dataGridResources = currentServerResources;
        } else {
            dataGridResources = new ArrayList<DataGridResource>();
        }
    }
    try {
        usedMap = createMapPartitionAndAmountUsed(diskInfoJson);
        for (String mountedOn : usedMap.keySet()) {
            boolean foundResc = false;
            for (DataGridResource dataGridResource : dataGridResources) {
                String resourcePath = dataGridResource.getPath();
                if (resourcePath.startsWith(mountedOn)) {
                    totalUsed += Long.parseLong(usedMap.get(mountedOn));
                    foundResc = true;
                    dataGridResources.remove(dataGridResource);
                    break;
                }
            }
            if (foundResc) {
                continue;
            }
        }
    } catch (JsonProcessingException e) {
        logger.info("Could not parse total used storage information for: ", hostname);
    } catch (IOException e) {
        logger.info("Could not parse total used storage information for: ", hostname);
    } catch (NumberFormatException e) {
        logger.info("Could not format String:{} ", e.getMessage());
    }
    return totalUsed * blockSize;
}
Also used : DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) ArrayList(java.util.ArrayList) DataGridResource(com.emc.metalnx.core.domain.entity.DataGridResource) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 32 with DataGridResource

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

the class StorageServiceImpl method totalAvailableStorageOfAServer.

@Override
public long totalAvailableStorageOfAServer(String hostname, String diskInfoJson, List<DataGridResource> currentServerResources) throws DataGridConnectionRefusedException {
    logger.info("Get total available storage of a specific server {}", hostname);
    long totalAvailable = 0;
    if (hostname == null || diskInfoJson == null || hostname.isEmpty() || diskInfoJson.isEmpty()) {
        return totalAvailable;
    }
    HashMap<String, String> availableMap = null;
    List<DataGridResource> dataGridResources = null;
    try {
        dataGridResources = resourceService.getResourcesOfAServer(hostname, currentServerResources);
    } catch (DataGridConnectionRefusedException e) {
        logger.error("Could not get resources from server ", hostname);
        // we will use all known resources of this server stored in cache
        if (currentServerResources != null) {
            dataGridResources = currentServerResources;
        } else {
            dataGridResources = new ArrayList<DataGridResource>();
        }
    }
    try {
        availableMap = createMapPartitionAndAmountAvailable(diskInfoJson);
        for (String mountedOn : availableMap.keySet()) {
            boolean foundResc = false;
            for (DataGridResource dataGridResource : dataGridResources) {
                String resourcePath = dataGridResource.getPath();
                if (resourcePath.startsWith(mountedOn)) {
                    totalAvailable += Long.parseLong(availableMap.get(mountedOn));
                    foundResc = true;
                    dataGridResources.remove(dataGridResource);
                    break;
                }
            }
            if (foundResc) {
                continue;
            }
        }
    } catch (JsonProcessingException e) {
        logger.info("Could not parse total available storage information for: ", hostname);
    } catch (IOException e) {
        logger.info("Could not parse total available storage information for: ", hostname);
    } catch (NumberFormatException e) {
        logger.info("Could not format String:{} ", e.getMessage());
    }
    return totalAvailable * blockSize;
}
Also used : DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) ArrayList(java.util.ArrayList) DataGridResource(com.emc.metalnx.core.domain.entity.DataGridResource) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 33 with DataGridResource

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

the class TestPluginService method testMSICompatibility.

@Test
public void testMSICompatibility() throws DataGridConnectionRefusedException, DataGridRuleException {
    DataGridResource resc = new DataGridResource();
    resc.setName("demoResc");
    List<DataGridResource> rescs = new ArrayList<>();
    rescs.add(resc);
    servers.get(0).setResources(rescs);
    assertTrue(msiService.isMSIAPICompatibleInResc("demoResc"));
}
Also used : ArrayList(java.util.ArrayList) DataGridResource(com.emc.metalnx.core.domain.entity.DataGridResource) Test(org.junit.Test)

Example 34 with DataGridResource

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

the class TestResourceService method setUp.

@Before
public void setUp() throws DataGridConnectionRefusedException {
    long time = System.currentTimeMillis();
    parentRescName = "testResc" + time;
    childRescName = "testRescChild" + time;
    Date date = new Date();
    parentResc = new DataGridResource();
    parentResc.setName(parentRescName);
    parentResc.setType("compound");
    parentResc.setZone(zone);
    parentResc.setCreateTime(date);
    parentResc.setModifyTime(date);
    parentResc.setFreeSpaceDate(date);
    parentResc.setPath("/var/lib/irods/iRODS/Vault2");
    parentResc.setHost(host);
    childResc = new DataGridResource();
    childResc.setName(childRescName);
    childResc.setType("unixfilesystem");
    childResc.setZone(zone);
    childResc.setCreateTime(date);
    childResc.setModifyTime(date);
    childResc.setFreeSpaceDate(date);
    childResc.setPath("/var/lib/irods/iRODS/Vault2");
    childResc.setHost(host);
    resourceService.createResource(parentResc);
}
Also used : DataGridResource(com.emc.metalnx.core.domain.entity.DataGridResource) Date(java.util.Date) Before(org.junit.Before)

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