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