use of org.eclipse.che.api.workspace.server.devfile.FileContentProvider in project devspaces-images by redhat-developer.
the class DevfileConverterTest method shouldConvertCommandsDuringConvertingDevfileToWorkspaceConfig.
@Test
public void shouldConvertCommandsDuringConvertingDevfileToWorkspaceConfig() throws Exception {
// given
FileContentProvider fileContentProvider = mock(FileContentProvider.class);
DevfileImpl devfile = newDevfile("petclinic");
CommandImpl devfileCommand = mock(CommandImpl.class);
devfile.getCommands().add(devfileCommand);
org.eclipse.che.api.workspace.server.model.impl.CommandImpl workspaceCommand = mock(org.eclipse.che.api.workspace.server.model.impl.CommandImpl.class);
when(commandConverter.toWorkspaceCommand(any(), any())).thenReturn(workspaceCommand);
// when
WorkspaceConfigImpl workspaceConfig = devfileConverter.devFileToWorkspaceConfig(devfile, fileContentProvider);
// then
assertEquals(workspaceConfig.getCommands().size(), 1);
assertSame(workspaceConfig.getCommands().get(0), workspaceCommand);
}
use of org.eclipse.che.api.workspace.server.devfile.FileContentProvider 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));
}
use of org.eclipse.che.api.workspace.server.devfile.FileContentProvider in project devspaces-images by redhat-developer.
the class DefaultEditorProvisioner method apply.
/**
* Provision default editor if there is no editor. Also provisions default plugins for default
* editor regardless whether it is provisioned or set by user.
*
* @param devfile devfile where editor and plugins should be provisioned
* @param contentProvider content provider for plugin references retrieval
*/
public void apply(DevfileImpl devfile, FileContentProvider contentProvider) throws DevfileException {
if (defaultEditorRef == null) {
// there is no default editor configured
return;
}
if ("true".equals(devfile.getAttributes().get(EDITOR_FREE_DEVFILE_ATTRIBUTE))) {
return;
}
List<ComponentImpl> components = devfile.getComponents();
Optional<ComponentImpl> editorOpt = components.stream().filter(t -> EDITOR_COMPONENT_TYPE.equals(t.getType())).findFirst();
boolean isDefaultEditorUsed;
if (!editorOpt.isPresent()) {
components.add(new ComponentImpl(EDITOR_COMPONENT_TYPE, defaultEditorRef));
isDefaultEditorUsed = true;
} else {
Component editor = editorOpt.get();
String editorPublisherAndName = getPluginPublisherAndName(editor, contentProvider);
isDefaultEditorUsed = defaultEditor.equals(editorPublisherAndName);
}
if (isDefaultEditorUsed) {
provisionDefaultPlugins(components, contentProvider);
}
if ("false".equals(devfile.getAttributes().get(PERSIST_VOLUMES_ATTRIBUTE)) && "true".equals(devfile.getAttributes().get(ASYNC_PERSIST_ATTRIBUTE))) {
provisionAsyncStoragePlugin(components, contentProvider);
}
}
use of org.eclipse.che.api.workspace.server.devfile.FileContentProvider in project che-server by eclipse-che.
the class GitlabAuthorizingFileContentProviderTest method shouldPreserveAbsolutePaths.
@Test
public void shouldPreserveAbsolutePaths() throws Exception {
URLFetcher urlFetcher = Mockito.mock(URLFetcher.class);
GitlabUrl gitlabUrl = new GitlabUrl().withHostName("gitlab.net").withUsername("eclipse").withProject("che");
FileContentProvider fileContentProvider = new GitlabAuthorizingFileContentProvider(gitlabUrl, urlFetcher, gitCredentialsManager, personalAccessTokenManager);
String url = "https://gitlab.net/api/v4/projects/eclipse%2Fche/repository/files/devfile.yaml/raw";
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 GithubAuthorizingFileContentProviderTest method shouldExpandRelativePaths.
@Test
public void shouldExpandRelativePaths() throws Exception {
URLFetcher urlFetcher = Mockito.mock(URLFetcher.class);
GithubUrl githubUrl = new GithubUrl().withUsername("eclipse").withRepository("che");
FileContentProvider fileContentProvider = new GithubAuthorizingFileContentProvider(githubUrl, urlFetcher, gitCredentialManager, personalAccessTokenManager);
fileContentProvider.fetchContent("devfile.yaml");
verify(urlFetcher).fetch(eq("https://raw.githubusercontent.com/eclipse/che/HEAD/devfile.yaml"));
}
Aggregations