use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project che-server by eclipse-che.
the class OpenShiftPreviewUrlCommandProvisionerTest method shouldDoNothingWhenCantFindServiceForPreviewurl.
@Test
public void shouldDoNothingWhenCantFindServiceForPreviewurl() throws InfrastructureException {
List<CommandImpl> commands = Collections.singletonList(new CommandImpl("a", "a", "a", new PreviewUrlImpl(8080, null), Collections.emptyMap()));
OpenShiftEnvironment env = OpenShiftEnvironment.builder().setCommands(new ArrayList<>(commands)).build();
Mockito.when(mockProject.routes()).thenReturn(mockRoutes);
Mockito.when(mockProject.services()).thenReturn(mockServices);
Mockito.when(mockServices.get()).thenReturn(Collections.emptyList());
previewUrlCommandProvisioner.provision(env, mockProject);
assertTrue(commands.containsAll(env.getCommands()));
assertTrue(env.getCommands().containsAll(commands));
assertEquals(env.getWarnings().get(0).getCode(), Warnings.NOT_ABLE_TO_PROVISION_OBJECTS_FOR_PREVIEW_URL);
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project che-server by eclipse-che.
the class OpenShiftPreviewUrlExposerTest method shouldProvisionRouteWhenNotFound.
@Test
public void shouldProvisionRouteWhenNotFound() throws InternalInfrastructureException {
final int PORT = 8080;
final String SERVER_PORT_NAME = "server-" + PORT;
final String SERVICE_NAME = "servicename";
CommandImpl command = new CommandImpl("a", "a", "a", new PreviewUrlImpl(PORT, null), Collections.emptyMap());
Service service = new Service();
ObjectMeta serviceMeta = new ObjectMeta();
serviceMeta.setName(SERVICE_NAME);
service.setMetadata(serviceMeta);
ServiceSpec serviceSpec = new ServiceSpec();
serviceSpec.setPorts(singletonList(new ServicePort(null, SERVER_PORT_NAME, null, PORT, "TCP", new IntOrString(PORT))));
service.setSpec(serviceSpec);
Map<String, Service> services = new HashMap<>();
services.put(SERVICE_NAME, service);
OpenShiftEnvironment env = OpenShiftEnvironment.builder().setCommands(singletonList(new CommandImpl(command))).setServices(services).setRoutes(new HashMap<>()).build();
previewUrlEndpointsProvisioner.expose(env);
assertEquals(env.getRoutes().size(), 1);
Route provisionedRoute = env.getRoutes().values().iterator().next();
assertEquals(provisionedRoute.getSpec().getTo().getName(), SERVICE_NAME);
assertEquals(provisionedRoute.getSpec().getPort().getTargetPort().getStrVal(), SERVER_PORT_NAME);
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project che-server by eclipse-che.
the class OpenShiftPreviewUrlExposerTest method shouldDoNothingWhenNoCommandWithPreviewUrlDefined.
@Test
public void shouldDoNothingWhenNoCommandWithPreviewUrlDefined() throws InternalInfrastructureException {
CommandImpl command = new CommandImpl("a", "a", "a");
OpenShiftEnvironment env = OpenShiftEnvironment.builder().setCommands(singletonList(new CommandImpl(command))).build();
previewUrlEndpointsProvisioner.expose(env);
assertEquals(env.getCommands().get(0), command);
assertTrue(env.getServices().isEmpty());
assertTrue(env.getRoutes().isEmpty());
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project che-server by eclipse-che.
the class FactoryDaoTest method createWorkspaceConfig.
private static WorkspaceConfigImpl createWorkspaceConfig(int index) {
// Project Sources configuration
final SourceStorageImpl source1 = new SourceStorageImpl();
source1.setType("type1");
source1.setLocation("location1");
source1.setParameters(new HashMap<>(ImmutableMap.of("param1", "value1")));
final SourceStorageImpl source2 = new SourceStorageImpl();
source2.setType("type2");
source2.setLocation("location2");
source2.setParameters(new HashMap<>(ImmutableMap.of("param4", "value1")));
// Project Configuration
final ProjectConfigImpl pCfg1 = new ProjectConfigImpl();
pCfg1.setPath("/path1");
pCfg1.setType("type1");
pCfg1.setName("project1");
pCfg1.setDescription("description1");
pCfg1.getMixins().addAll(asList("mixin1", "mixin2"));
pCfg1.setSource(source1);
final ProjectConfigImpl pCfg2 = new ProjectConfigImpl();
pCfg2.setPath("/path2");
pCfg2.setType("type2");
pCfg2.setName("project2");
pCfg2.setDescription("description2");
pCfg2.getMixins().addAll(asList("mixin3", "mixin4"));
pCfg2.setSource(source2);
final List<ProjectConfigImpl> projects = new ArrayList<>(asList(pCfg1, pCfg2));
// Commands
final CommandImpl cmd1 = new CommandImpl("name1", "cmd1", "type1");
cmd1.getAttributes().putAll(ImmutableMap.of("key1", "value1"));
final CommandImpl cmd2 = new CommandImpl("name2", "cmd2", "type2");
cmd2.getAttributes().putAll(ImmutableMap.of("key4", "value4"));
final List<CommandImpl> commands = new ArrayList<>(asList(cmd1, cmd2));
// Machine configs
final MachineConfigImpl exMachine1 = new MachineConfigImpl();
final ServerConfigImpl serverConf1 = new ServerConfigImpl("2265", "http", "/path1", singletonMap("key", "value"));
final ServerConfigImpl serverConf2 = new ServerConfigImpl("2266", "ftp", "/path2", singletonMap("key", "value"));
exMachine1.setServers(ImmutableMap.of("ref1", serverConf1, "ref2", serverConf2));
exMachine1.setAttributes(singletonMap("att1", "val"));
exMachine1.setEnv(singletonMap("CHE_ENV", "value"));
final MachineConfigImpl exMachine2 = new MachineConfigImpl();
final ServerConfigImpl serverConf3 = new ServerConfigImpl("2333", "https", "/path1", singletonMap("key", "value"));
final ServerConfigImpl serverConf4 = new ServerConfigImpl("2334", "wss", "/path2", singletonMap("key", "value"));
exMachine2.setServers(ImmutableMap.of("ref1", serverConf3, "ref2", serverConf4));
exMachine2.setAttributes(singletonMap("att1", "val"));
exMachine2.setEnv(singletonMap("CHE_ENV2", "value"));
final MachineConfigImpl exMachine3 = new MachineConfigImpl();
final ServerConfigImpl serverConf5 = new ServerConfigImpl("2333", "https", "/path3", singletonMap("key", "value"));
exMachine3.setServers(singletonMap("ref1", serverConf5));
exMachine3.setAttributes(singletonMap("att1", "val"));
exMachine3.setEnv(singletonMap("CHE_ENV3", "value"));
// Environments
final RecipeImpl recipe1 = new RecipeImpl();
recipe1.setLocation("https://eclipse.che/Dockerfile");
recipe1.setType("dockerfile");
recipe1.setContentType("text/x-dockerfile");
recipe1.setContent("content");
final EnvironmentImpl env1 = new EnvironmentImpl();
env1.setMachines(new HashMap<>(ImmutableMap.of("machine1", exMachine1, "machine2", exMachine2, "machine3", exMachine3)));
env1.setRecipe(recipe1);
final RecipeImpl recipe2 = new RecipeImpl();
recipe2.setLocation("https://eclipse.che/Dockerfile");
recipe2.setType("dockerfile");
recipe2.setContentType("text/x-dockerfile");
recipe2.setContent("content");
final EnvironmentImpl env2 = new EnvironmentImpl();
env2.setMachines(new HashMap<>(ImmutableMap.of("machine1", exMachine1, "machine3", exMachine3)));
env2.setRecipe(recipe2);
final Map<String, EnvironmentImpl> environments = ImmutableMap.of("env1", env1, "env2", env2);
// Workspace configuration
final WorkspaceConfigImpl wCfg = new WorkspaceConfigImpl();
wCfg.setDefaultEnv("env1");
wCfg.setName("cfgName_" + index);
wCfg.setDescription("description");
wCfg.setCommands(commands);
wCfg.setProjects(projects);
wCfg.setEnvironments(environments);
return wCfg;
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project che-server by eclipse-che.
the class KubernetesPluginsToolingApplierTest method shouldResolveMachineNameForCommandsInEnvironment.
@Test
public void shouldResolveMachineNameForCommandsInEnvironment() throws Exception {
// given
ChePlugin chePlugin = createChePlugin(createContainer("container"));
String pluginRef = chePlugin.getId();
CommandImpl pluginCommand = new CommandImpl("test-command", "echo Hello World!", "custom");
pluginCommand.getAttributes().put("plugin", pluginRef);
internalEnvironment.getCommands().add(pluginCommand);
// when
applier.apply(runtimeIdentity, internalEnvironment, singletonList(chePlugin));
// then
List<CommandImpl> envCommands = internalEnvironment.getCommands();
assertEquals(envCommands.size(), 1);
CommandImpl envCommand = envCommands.get(0);
assertEquals(envCommand.getName(), pluginCommand.getName());
assertEquals(envCommand.getType(), pluginCommand.getType());
assertEquals(envCommand.getCommandLine(), pluginCommand.getCommandLine());
assertEquals(envCommand.getAttributes().get("plugin"), pluginRef);
validateContainerNameName(envCommand.getAttributes().get(MACHINE_NAME_ATTRIBUTE), "container");
}
Aggregations