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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations