Search in sources :

Example 11 with DataGridResource

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

the class MSIServiceImpl method isMSIAPICompatibleInResc.

@Override
public boolean isMSIAPICompatibleInResc(String resource) throws DataGridConnectionRefusedException {
    if (servers == null || servers.isEmpty())
        getMSIInfoForAllServers();
    DataGridServer server = null;
    for (DataGridServer s : servers) {
        for (DataGridResource dgResc : s.getResources()) {
            if (resource.equals(dgResc.getName())) {
                server = s;
                break;
            }
        }
        if (server != null)
            break;
    }
    String apiVersionSupported = DataGridCoreUtils.getAPIVersion(configService.getMsiAPIVersionSupported());
    String apiVersionInstalled = server != null ? DataGridCoreUtils.getAPIVersion(server.getMSIVersion()) : "";
    return apiVersionSupported.equalsIgnoreCase(apiVersionInstalled);
}
Also used : DataGridResource(com.emc.metalnx.core.domain.entity.DataGridResource) DataGridServer(com.emc.metalnx.core.domain.entity.DataGridServer)

Example 12 with DataGridResource

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

the class TestRuleService method setUp.

@Before
public void setUp() throws JargonException, DataGridException, URISyntaxException, IOException {
    // partial mocking
    ruleService = spy(RuleServiceImpl.class);
    MockitoAnnotations.initMocks(this);
    when(configService.getIrodsHost()).thenReturn("icat.test.com");
    when(configService.getMsiAPIVersionSupported()).thenReturn(msiVersion);
    DataGridResource resc = new DataGridResource(1, RESOURCE, "zone", "unixfilesystem", "/test/resc/path");
    resc.setHost("icat.test.com");
    when(resourceService.find(anyString())).thenReturn(resc);
    when(ruleService.executeRule(anyString())).thenReturn(new HashMap<>());
}
Also used : DataGridResource(com.emc.metalnx.core.domain.entity.DataGridResource) RuleServiceImpl(com.emc.metalnx.services.irods.RuleServiceImpl) Before(org.junit.Before)

Example 13 with DataGridResource

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

the class BrowseController method getAvailableRescForPath.

/**
 * Get a list of resources in which an object doesn't have replicas
 *
 * @param model
 * @return list of resources in which an object can be replicated
 * @throws DataGridConnectionRefusedException
 */
@RequestMapping(value = "getAvailableRescForPath/")
public String getAvailableRescForPath(final Model model, @RequestParam("isUpload") final boolean isUpload) throws DataGridConnectionRefusedException {
    logger.info("getAvailableRescForPath()");
    Map<DataGridCollectionAndDataObject, DataGridResource> replicasMap = null;
    List<DataGridResource> resources = resourceService.findFirstLevelResources();
    if (!isUpload) {
        for (String path : sourcePaths) {
            replicasMap = cs.listReplicasByResource(path);
            for (DataGridResource resc : replicasMap.values()) {
                if (resources.contains(resc)) {
                    resources.remove(resc);
                }
            }
        }
    }
    model.addAttribute("resources", resources);
    return "collections/collectionsResourcesForReplica";
}
Also used : DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) DataGridResource(com.emc.metalnx.core.domain.entity.DataGridResource) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with DataGridResource

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

the class ResourceController method getResourcesMap.

private void getResourcesMap(Model model, boolean isDashboard) throws JSONException, DataGridConnectionRefusedException {
    // JSON object that will have all data of resources to be displayed as a tree
    logger.debug("Building JSON Tree");
    JSONArray treeData = new JSONArray();
    JSONObject root = new JSONObject();
    root.put("name", zoneName);
    root.put("icon", isDashboard ? treeImagePathForDashboard : treeImagePath);
    JSONArray childrenOfRoot = new JSONArray();
    dataGridResources = resourceService.findAll();
    Map<String, DataGridResource> dataGridResourcesMap = buildDataGridResourcesMap(dataGridResources);
    for (DataGridResource resc : dataGridResources) {
        if (resc.getParent().equals(zoneName)) {
            addParentToJSON(resc, root, childrenOfRoot, dataGridResourcesMap, isDashboard);
        }
    }
    treeData.put(root);
    logger.debug("JSON Tree finished");
    model.addAttribute("treeData", treeData.toString());
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) DataGridResource(com.emc.metalnx.core.domain.entity.DataGridResource)

Example 15 with DataGridResource

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

the class ResourceController method addResource.

/**
 * Add a resource to the data grid
 *
 * @return the template that renders the add resource from
 * @throws DataGridConnectionRefusedException
 */
@RequestMapping(value = "/add/action/")
public String addResource(@ModelAttribute ResourceForm resourceForm, HttpServletRequest httpServletRequest, RedirectAttributes redirectAttributes) throws DataGridConnectionRefusedException {
    String[] resourceType = httpServletRequest.getParameterMap().get("resourceType");
    String[] resourceParent = httpServletRequest.getParameterMap().get("resourceParent");
    String[] previousPage = httpServletRequest.getParameterMap().get("previousPage");
    String type = resourceType[0];
    String parent = null;
    if (resourceParent != null) {
        parent = resourceParent[0];
        resourceForm.setParent(parent);
    }
    resourceForm.setType(type);
    DataGridResource newDataGridResource = getDataGridResource(resourceForm);
    boolean resourceCreatedSuccessfully = resourceService.createResource(newDataGridResource);
    // a parent resource can be any other existing resource, but it can also be set
    // as
    // the zone, which means a resource has no parent.
    boolean isParentSetAndDifferentFromZone = false;
    if (parent != null && parent.compareTo(irodsServices.getCurrentUserZone()) != 0) {
        isParentSetAndDifferentFromZone = true;
    }
    // child of another resource B
    if (resourceCreatedSuccessfully) {
        String child = newDataGridResource.getName();
        if (isParentSetAndDifferentFromZone) {
            resourceService.addChildToResource(parent, child);
        }
    }
    redirectAttributes.addFlashAttribute("resourceAddedSuccessfully", resourceForm.getName());
    if (previousPage[0].contains("map")) {
        return "redirect:/resources/map/";
    }
    return "redirect:/resources/";
}
Also used : DataGridResource(com.emc.metalnx.core.domain.entity.DataGridResource) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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