use of io.hops.hopsworks.exceptions.GenericException in project hopsworks by logicalclocks.
the class ModelRegistryBuilder method build.
// Build collection
public ModelRegistryDTO build(UriInfo uriInfo, ResourceRequest resourceRequest, Users user, Project project) throws GenericException, ModelRegistryException, SchematizedTagException, MetadataException {
ModelRegistryDTO dto = new ModelRegistryDTO();
uri(dto, uriInfo, project);
expand(dto, resourceRequest);
Collection<Dataset> dsInProject = project.getDatasetCollection();
// Add all datasets shared with the project
dsInProject.addAll(project.getDatasetSharedWithCollection().stream().filter(DatasetSharedWith::getAccepted).map(DatasetSharedWith::getDataset).collect(Collectors.toList()));
Collection<Dataset> modelsDatasets = dsInProject.stream().filter(ds -> ds.getName().equals(Settings.HOPS_MODELS_DATASET)).collect(Collectors.toList());
dto.setCount((long) modelsDatasets.size());
for (Dataset ds : modelsDatasets) {
ModelRegistryDTO modelRegistryDTO = build(uriInfo, resourceRequest, user, project, ds.getProject());
if (modelRegistryDTO != null) {
dto.addItem(modelRegistryDTO);
}
}
return dto;
}
use of io.hops.hopsworks.exceptions.GenericException in project hopsworks by logicalclocks.
the class HostServicesController method webOp.
private String webOp(Action operation, List<HostServices> services) throws GenericException {
if (operation == null) {
throw new IllegalArgumentException("The action is not valid, valid action are " + Arrays.toString(Action.values()));
}
if (services == null || services.isEmpty()) {
throw new IllegalArgumentException("service was not provided.");
}
StringBuilder result = new StringBuilder();
boolean success = false;
int exception = Response.Status.BAD_REQUEST.getStatusCode();
for (HostServices service : services) {
Hosts h = service.getHost();
if (h != null) {
String ip = h.getPublicOrPrivateIp();
String agentPassword = h.getAgentPassword();
try {
result.append(service.toString()).append(" ").append(web.serviceOp(operation.value(), ip, agentPassword, service.getGroup(), service.getName()));
success = true;
} catch (GenericException ex) {
if (services.size() == 1) {
throw ex;
} else {
exception = ex.getErrorCode().getRespStatus().getStatusCode();
result.append(service.toString()).append(" ").append(ex.getErrorCode().getRespStatus()).append(" ").append(ex.getMessage());
}
}
} else {
result.append(service.toString()).append(" ").append("host not found: ").append(service.getHost());
}
result.append("\n");
}
if (!success) {
throw new GenericException(RESTCodes.GenericErrorCode.UNKNOWN_ERROR, Level.SEVERE, "webOp error, exception: " + exception + ", " + "result: " + result.toString());
}
return result.toString();
}
use of io.hops.hopsworks.exceptions.GenericException in project hopsworks by logicalclocks.
the class WebCommunication method fetchContent.
private String fetchContent(String url, String agentPassword) throws GenericException {
String content = NOT_AVAILABLE;
try {
Response response = getWebResource(url, agentPassword);
int code = response.getStatus();
Family res = Response.Status.Family.familyOf(code);
content = response.readEntity(String.class);
if (res == Response.Status.Family.SUCCESSFUL) {
return content;
} else {
throw new GenericException(RESTCodes.GenericErrorCode.UNKNOWN_ERROR, Level.SEVERE, "response status: " + response.getStatus(), "Error code:" + code + " Reason: " + content);
}
} catch (KeyManagementException | NoSuchAlgorithmException e) {
logger.log(Level.SEVERE, null, e);
throw new GenericException(RESTCodes.GenericErrorCode.UNKNOWN_ERROR, Level.SEVERE, null, e.getMessage(), e);
}
}
use of io.hops.hopsworks.exceptions.GenericException in project hopsworks by logicalclocks.
the class HopsworksJAXBContext method unmarshal.
public <V> V unmarshal(String json, Class<V> type) throws GenericException {
try {
Unmarshaller unmarshaller = context.createUnmarshaller();
StreamSource ss = new StreamSource(new StringReader(json));
return unmarshaller.unmarshal(ss, type).getValue();
} catch (JAXBException e) {
throw new GenericException(RESTCodes.GenericErrorCode.ILLEGAL_STATE, Level.INFO, "jaxb unmarshall exception");
}
}
use of io.hops.hopsworks.exceptions.GenericException in project hopsworks by logicalclocks.
the class ProjectsManagementBean method deleteProject.
public void deleteProject() {
logger.log(Level.INFO, "Deleting project: " + projectQuotasSelected.getName());
Cookie[] cookies = ((HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest()).getCookies();
try {
String sessionId = "";
for (Cookie cookie : cookies) {
if (cookie.getName().equalsIgnoreCase("SESSION")) {
sessionId = cookie.getValue();
break;
}
}
projectController.removeProject(projectQuotasSelected.getOwnerEmail(), projectQuotasSelected.getId(), sessionId);
projectsQuotas.remove(projectQuotasSelected);
projectQuotasSelected = null;
MessagesController.addInfoMessage("Project deleted!");
} catch (ProjectException | GenericException ex) {
logger.log(Level.SEVERE, "Failed to delete project " + projectQuotasSelected.getName(), ex);
MessagesController.addErrorMessage("Deletion failed", "Failed deleting project " + projectQuotasSelected.getName());
}
}
Aggregations