Search in sources :

Example 11 with DevfileFormatException

use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException in project che-server by eclipse-che.

the class KubernetesComponentValidator method validateEntrypointSelector.

private void validateEntrypointSelector(Component component, List<HasMetadata> filteredObjects) throws DevfileException {
    if (component.getEntrypoints() == null || component.getEntrypoints().isEmpty()) {
        return;
    }
    for (Entrypoint ep : component.getEntrypoints()) {
        ContainerSearch search = new ContainerSearch(ep.getParentName(), ep.getParentSelector(), ep.getContainerName());
        List<Container> cs = search.search(filteredObjects);
        if (cs.isEmpty()) {
            throw new DevfileFormatException(format("Component '%s' of type '%s' contains an entry point that doesn't match any" + " container.", getIdentifiableComponentName(component), component.getType()));
        }
    }
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) Entrypoint(org.eclipse.che.api.core.model.workspace.devfile.Entrypoint) DevfileFormatException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException)

Example 12 with DevfileFormatException

use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException in project che-server by eclipse-che.

the class KubernetesComponentValidator method validateComponent.

@Override
public void validateComponent(Component component, FileContentProvider contentProvider) throws DevfileFormatException {
    try {
        List<HasMetadata> selectedObjects = validateSelector(component, contentProvider);
        validateEntrypointSelector(component, selectedObjects);
    } catch (Exception e) {
        throw new DevfileFormatException(format("Failed to validate content reference of component '%s' of type '%s': %s", getIdentifiableComponentName(component), component.getType(), e.getMessage()), e);
    }
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) DevfileFormatException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException) DevfileException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileException) IOException(java.io.IOException) ValidationException(org.eclipse.che.api.core.ValidationException) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) DevfileFormatException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException)

Example 13 with DevfileFormatException

use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException in project che-server by eclipse-che.

the class WorkspaceEntityProvider method readFrom.

@Override
public WorkspaceDto readFrom(Class<WorkspaceDto> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
    try {
        JsonNode wsNode = mapper.readTree(entityStream);
        JsonNode devfileNode = wsNode.path("devfile");
        if (!devfileNode.isNull() && !devfileNode.isMissingNode()) {
            devfileParser.parseJson(devfileNode.toString());
        }
        return DtoFactory.getInstance().createDtoFromJson(wsNode.toString(), WorkspaceDto.class);
    } catch (DevfileFormatException e) {
        throw new BadRequestException(e.getMessage());
    } catch (IOException e) {
        throw new WebApplicationException(e.getMessage(), e);
    }
}
Also used : WebApplicationException(jakarta.ws.rs.WebApplicationException) BadRequestException(jakarta.ws.rs.BadRequestException) JsonNode(com.fasterxml.jackson.databind.JsonNode) DevfileFormatException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException) IOException(java.io.IOException)

Example 14 with DevfileFormatException

use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException in project che-server by eclipse-che.

the class DevfileParser method parse.

private DevfileImpl parse(JsonNode parsed, ObjectMapper mapper, Map<String, String> overrideProperties) throws DevfileFormatException, OverrideParameterException {
    if (parsed == null) {
        throw new DevfileFormatException("Unable to parse Devfile - provided source is empty");
    }
    DevfileImpl devfile;
    try {
        parsed = overridePropertiesApplier.applyPropertiesOverride(parsed, overrideProperties);
        schemaValidator.validate(parsed);
        devfile = mapper.treeToValue(parsed, DevfileImpl.class);
    } catch (JsonProcessingException e) {
        throw new DevfileFormatException(e.getMessage());
    }
    integrityValidator.validateDevfile(devfile);
    return devfile;
}
Also used : DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) DevfileFormatException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 15 with DevfileFormatException

use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException in project devspaces-images by redhat-developer.

the class UserDevfileEntityProvider method readFrom.

@Override
public UserDevfileDto readFrom(Class<UserDevfileDto> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
    try {
        JsonNode wsNode = mapper.readTree(entityStream);
        JsonNode devfileNode = wsNode.path("devfile");
        if (!devfileNode.isNull() && !devfileNode.isMissingNode()) {
            devfileParser.parseJson(devfileNode.toString());
        } else {
            throw new BadRequestException("Mandatory field `devfile` is not defined.");
        }
        return DtoFactory.getInstance().createDtoFromJson(wsNode.toString(), UserDevfileDto.class);
    } catch (DevfileFormatException e) {
        throw new BadRequestException(e.getMessage());
    } catch (IOException e) {
        throw new WebApplicationException(e.getMessage(), e);
    }
}
Also used : WebApplicationException(jakarta.ws.rs.WebApplicationException) BadRequestException(jakarta.ws.rs.BadRequestException) JsonNode(com.fasterxml.jackson.databind.JsonNode) DevfileFormatException(org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException) IOException(java.io.IOException)

Aggregations

DevfileFormatException (org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException)22 IOException (java.io.IOException)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 BadRequestException (jakarta.ws.rs.BadRequestException)4 WebApplicationException (jakarta.ws.rs.WebApplicationException)4 ValidationException (org.eclipse.che.api.core.ValidationException)4 Component (org.eclipse.che.api.core.model.workspace.devfile.Component)4 Devfile (org.eclipse.che.api.core.model.workspace.devfile.Devfile)4 DevfileException (org.eclipse.che.api.workspace.server.devfile.exception.DevfileException)4 Test (org.testng.annotations.Test)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 Container (io.fabric8.kubernetes.api.model.Container)2 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)2 JsonReader (jakarta.json.JsonReader)2 StringReader (java.io.StringReader)2 String.format (java.lang.String.format)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2