Search in sources :

Example 6 with GenericException

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;
}
Also used : Stateless(javax.ejb.Stateless) ModelRegistryDTO(io.hops.hopsworks.api.modelregistry.dto.ModelRegistryDTO) ModelsBuilder(io.hops.hopsworks.api.modelregistry.models.ModelsBuilder) Collection(java.util.Collection) ModelRegistryException(io.hops.hopsworks.exceptions.ModelRegistryException) Collectors(java.util.stream.Collectors) Project(io.hops.hopsworks.persistence.entity.project.Project) Settings(io.hops.hopsworks.common.util.Settings) Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) TransactionAttributeType(javax.ejb.TransactionAttributeType) GenericException(io.hops.hopsworks.exceptions.GenericException) DatasetSharedWith(io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith) MetadataException(io.hops.hopsworks.exceptions.MetadataException) TransactionAttribute(javax.ejb.TransactionAttribute) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) UriInfo(javax.ws.rs.core.UriInfo) Users(io.hops.hopsworks.persistence.entity.user.Users) EJB(javax.ejb.EJB) SchematizedTagException(io.hops.hopsworks.exceptions.SchematizedTagException) Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) DatasetSharedWith(io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith) ModelRegistryDTO(io.hops.hopsworks.api.modelregistry.dto.ModelRegistryDTO)

Example 7 with GenericException

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();
}
Also used : Hosts(io.hops.hopsworks.persistence.entity.host.Hosts) HostServices(io.hops.hopsworks.persistence.entity.kagent.HostServices) GenericException(io.hops.hopsworks.exceptions.GenericException)

Example 8 with GenericException

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);
    }
}
Also used : Response(javax.ws.rs.core.Response) Family(javax.ws.rs.core.Response.Status.Family) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) GenericException(io.hops.hopsworks.exceptions.GenericException) KeyManagementException(java.security.KeyManagementException)

Example 9 with GenericException

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");
    }
}
Also used : StreamSource(javax.xml.transform.stream.StreamSource) JAXBException(javax.xml.bind.JAXBException) StringReader(java.io.StringReader) Unmarshaller(javax.xml.bind.Unmarshaller) GenericException(io.hops.hopsworks.exceptions.GenericException)

Example 10 with GenericException

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());
    }
}
Also used : Cookie(javax.servlet.http.Cookie) HttpServletRequest(javax.servlet.http.HttpServletRequest) ProjectException(io.hops.hopsworks.exceptions.ProjectException) GenericException(io.hops.hopsworks.exceptions.GenericException)

Aggregations

GenericException (io.hops.hopsworks.exceptions.GenericException)43 Users (io.hops.hopsworks.persistence.entity.user.Users)17 Project (io.hops.hopsworks.persistence.entity.project.Project)16 ProjectException (io.hops.hopsworks.exceptions.ProjectException)13 DatasetException (io.hops.hopsworks.exceptions.DatasetException)12 ServiceException (io.hops.hopsworks.exceptions.ServiceException)12 IOException (java.io.IOException)12 Path (javax.ws.rs.Path)11 ElasticException (io.hops.hopsworks.exceptions.ElasticException)10 HopsSecurityException (io.hops.hopsworks.exceptions.HopsSecurityException)10 JobException (io.hops.hopsworks.exceptions.JobException)9 ProvenanceException (io.hops.hopsworks.exceptions.ProvenanceException)9 Produces (javax.ws.rs.Produces)9 Dataset (io.hops.hopsworks.persistence.entity.dataset.Dataset)8 ArrayList (java.util.ArrayList)8 TransactionAttribute (javax.ejb.TransactionAttribute)8 ServiceDiscoveryException (com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException)6 UserException (io.hops.hopsworks.exceptions.UserException)6 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)6 HdfsUsers (io.hops.hopsworks.persistence.entity.hdfs.user.HdfsUsers)6