use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileException in project che-server by eclipse-che.
the class DevfileVersionDetector method devfileMajorVersion.
/**
* Gives major version of the devfile.
*
* <pre>
* 1 -> 1
* 1.0.0 -> 1
* 1.99 -> 1
* 2.0.0 -> 2
* 2.1 -> 2
* a.a -> DevfileException
* a -> DevfileException
* </pre>
*
* @param devfile to inspect
* @return major version of the devfile
* @throws DevfileException when can't find the field with version
*/
public int devfileMajorVersion(JsonNode devfile) throws DevfileException {
String version = devfileVersion(devfile);
int dot = version.indexOf(".");
final String majorVersion = dot > 0 ? version.substring(0, dot) : version;
try {
return Integer.parseInt(majorVersion);
} catch (NumberFormatException nfe) {
throw new DevfileException("Unable to parse devfile version. This is not a valid devfile.", nfe);
}
}
use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileException in project che-server by eclipse-che.
the class DevfileSchemaValidator method validate.
public void validate(JsonNode contentNode) throws DevfileFormatException {
try {
List<Problem> validationErrors = new ArrayList<>();
ProblemHandler handler = ProblemHandler.collectingTo(validationErrors);
String devfileVersion = devfileVersionDetector.devfileVersion(contentNode);
if (!schemasByVersion.containsKey(devfileVersion)) {
throw new DevfileFormatException(String.format("Version '%s' of the devfile is not supported. Supported versions are '%s'.", devfileVersion, SUPPORTED_VERSIONS));
}
JsonSchema schema = schemasByVersion.get(devfileVersion);
try (JsonReader reader = service.createReader(new StringReader(jsonMapper.writeValueAsString(contentNode)), schema, handler)) {
reader.read();
}
if (!validationErrors.isEmpty()) {
String error = errorMessageComposer.extractMessages(validationErrors, new StringBuilder());
throw new DevfileFormatException(error);
}
} catch (DevfileException dfe) {
throw new DevfileFormatException(format("Devfile schema validation failed. Error: %s", dfe.getMessage()));
} catch (IOException e) {
throw new DevfileFormatException("Unable to validate Devfile. Error: " + e.getMessage());
}
}
use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileException in project che-server by eclipse-che.
the class PluginFQNParser method evaluateFqn.
/**
* Evaluates plugin FQN from provided reference by trying to fetch and parse its meta information.
*
* @param reference plugin reference to evaluate FQN from
* @param fileContentProvider content provider instance to perform plugin meta requests
* @return plugin FQN evaluated from given reference
* @throws InfrastructureException if plugin reference is invalid or inaccessible
*/
public ExtendedPluginFQN evaluateFqn(String reference, FileContentProvider fileContentProvider) throws InfrastructureException {
JsonNode contentNode;
try {
String pluginMetaContent = fileContentProvider.fetchContent(reference);
contentNode = yamlReader.readTree(pluginMetaContent);
} catch (DevfileException | IOException e) {
throw new InfrastructureException(format("Plugin reference URL '%s' is invalid.", reference), e);
}
JsonNode publisher = contentNode.path("publisher");
if (publisher.isMissingNode()) {
throw new InfrastructureException(formatMessage(reference, "publisher"));
}
JsonNode name = contentNode.get("name");
if (name.isMissingNode()) {
throw new InfrastructureException(formatMessage(reference, "name"));
}
JsonNode version = contentNode.get("version");
if (version.isMissingNode()) {
throw new InfrastructureException(formatMessage(reference, "version"));
}
if (!version.isValueNode()) {
throw new InfrastructureException(format("Plugin specified by reference URL '%s' has version field that cannot be parsed to string", reference));
}
return new ExtendedPluginFQN(reference, publisher.textValue(), name.textValue(), version.asText());
}
use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileException in project devspaces-images by redhat-developer.
the class DevfileConverterTest method shouldThrowServerExceptionIfAnyDevfileExceptionOccursOnConvertingDevfileToWorkspaceConfig.
@Test(expectedExceptions = ServerException.class, expectedExceptionsMessageRegExp = "error")
public void shouldThrowServerExceptionIfAnyDevfileExceptionOccursOnConvertingDevfileToWorkspaceConfig() throws Exception {
devfileConverter = spy(devfileConverter);
doThrow(new DevfileException("error")).when(devfileConverter).devFileToWorkspaceConfig(any(), any());
devfileConverter.convert(new DevfileImpl());
}
use of org.eclipse.che.api.workspace.server.devfile.exception.DevfileException in project devspaces-images by redhat-developer.
the class DockerimageComponentToWorkspaceApplier method apply.
/**
* Applies changes on workspace config according to the specified dockerimage component.
*
* <p>Dockerimage component is provisioned as Deployment in Kubernetes recipe.<br>
* Generated deployment contains container with environment variables, memory limit, docker image,
* arguments and commands specified in component.<br>
* Also, environment is provisioned with machine config with volumes and servers specified, then
* Kubernetes infra will created needed PVC, Services, Ingresses, Routes according to specified
* configuration.
*
* @param workspaceConfig workspace config on which changes should be applied
* @param dockerimageComponent dockerimage component that should be applied
* @param contentProvider optional content provider that may be used for external component
* resource fetching
* @throws DevfileException if specified workspace config already has default environment where
* dockerimage component should be stored
* @throws IllegalArgumentException if specified workspace config or plugin component is null
* @throws IllegalArgumentException if specified component has type different from dockerimage
*/
@Override
public void apply(WorkspaceConfigImpl workspaceConfig, ComponentImpl dockerimageComponent, FileContentProvider contentProvider) throws DevfileException {
checkArgument(workspaceConfig != null, "Workspace config must not be null");
checkArgument(dockerimageComponent != null, "Component must not be null");
checkArgument(DOCKERIMAGE_COMPONENT_TYPE.equals(dockerimageComponent.getType()), format("Plugin must have `%s` type", DOCKERIMAGE_COMPONENT_TYPE));
String componentAlias = dockerimageComponent.getAlias();
String machineName = componentAlias == null ? toMachineName(dockerimageComponent.getImage()) : componentAlias;
MachineConfigImpl machineConfig = createMachineConfig(dockerimageComponent, componentAlias);
List<HasMetadata> componentObjects = createComponentObjects(dockerimageComponent, machineName);
k8sEnvProvisioner.provision(workspaceConfig, KubernetesEnvironment.TYPE, componentObjects, ImmutableMap.of(machineName, machineConfig));
workspaceConfig.getCommands().stream().filter(c -> componentAlias != null && componentAlias.equals(c.getAttributes().get(Constants.COMPONENT_ALIAS_COMMAND_ATTRIBUTE))).forEach(c -> c.getAttributes().put(MACHINE_NAME_ATTRIBUTE, machineName));
}
Aggregations