use of org.eclipse.che.api.workspace.server.devfile.FileContentProvider in project che-server by eclipse-che.
the class GithubAuthorizingFileContentProviderTest method shouldPreserveAbsolutePaths.
@Test
public void shouldPreserveAbsolutePaths() throws Exception {
URLFetcher urlFetcher = Mockito.mock(URLFetcher.class);
GithubUrl githubUrl = new GithubUrl().withUsername("eclipse").withRepository("che");
FileContentProvider fileContentProvider = new GithubAuthorizingFileContentProvider(githubUrl, urlFetcher, gitCredentialManager, personalAccessTokenManager);
String url = "https://raw.githubusercontent.com/foo/bar/devfile.yaml";
fileContentProvider.fetchContent(url);
verify(urlFetcher).fetch(eq(url));
}
use of org.eclipse.che.api.workspace.server.devfile.FileContentProvider in project che-server by eclipse-che.
the class DevfileConverterTest method shouldConvertComponentsDuringConvertingDevfileToWorkspaceConfig.
@Test
public void shouldConvertComponentsDuringConvertingDevfileToWorkspaceConfig() throws Exception {
// given
DevfileImpl devfile = newDevfile("petclinic");
ComponentImpl component = new ComponentImpl();
component.setType(COMPONENT_TYPE);
devfile.getComponents().add(component);
FileContentProvider fileContentProvider = mock(FileContentProvider.class);
// when
WorkspaceConfigImpl workspaceConfig = devfileConverter.devFileToWorkspaceConfig(devfile, fileContentProvider);
// then
verify(componentToWorkspaceApplier).apply(workspaceConfig, component, fileContentProvider);
}
use of org.eclipse.che.api.workspace.server.devfile.FileContentProvider in project che-server by eclipse-che.
the class DevfileConverterTest method shouldProvisionDevfileAttributesAsConfigAttributesDuringConvertingDevfileToWorkspaceConfig.
@Test
public void shouldProvisionDevfileAttributesAsConfigAttributesDuringConvertingDevfileToWorkspaceConfig() throws Exception {
// given
FileContentProvider fileContentProvider = mock(FileContentProvider.class);
Map<String, String> devfileAttributes = new HashMap<>();
devfileAttributes.put(PERSIST_VOLUMES_ATTRIBUTE, "false");
devfileAttributes.put("anotherAttribute", "value");
DevfileImpl devfile = newDevfile("petclinic");
devfile.getAttributes().putAll(devfileAttributes);
// when
WorkspaceConfigImpl config = devfileConverter.devFileToWorkspaceConfig(devfile, fileContentProvider);
// then
assertEquals(config.getAttributes(), devfileAttributes);
}
use of org.eclipse.che.api.workspace.server.devfile.FileContentProvider in project che-server by eclipse-che.
the class DevfileConverterTest method shouldThrowAnExceptionIfDevfileApiVersionIsMissingDuringConvertingDevfileToWorkspaceConfig.
@Test(expectedExceptions = DevfileFormatException.class, expectedExceptionsMessageRegExp = "Provided Devfile has no API version specified")
public void shouldThrowAnExceptionIfDevfileApiVersionIsMissingDuringConvertingDevfileToWorkspaceConfig() throws Exception {
// given
FileContentProvider fileContentProvider = mock(FileContentProvider.class);
DevfileImpl devfile = new DevfileImpl();
devfile.setName("petclinic");
// when
devfileConverter.devFileToWorkspaceConfig(devfile, fileContentProvider);
}
use of org.eclipse.che.api.workspace.server.devfile.FileContentProvider in project che-server by eclipse-che.
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