use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project che-server by eclipse-che.
the class PluginComponentToWorkspaceApplierTest method shouldProvisionPluginCommandAttributesDuringChePluginComponentApplying.
@Test
public void shouldProvisionPluginCommandAttributesDuringChePluginComponentApplying() throws Exception {
// given
ComponentImpl superPluginComponent = new ComponentImpl();
superPluginComponent.setAlias("super-plugin");
superPluginComponent.setId("eclipse/super-plugin/0.0.1");
superPluginComponent.setType(PLUGIN_COMPONENT_TYPE);
WorkspaceConfigImpl workspaceConfig = new WorkspaceConfigImpl();
CommandImpl command = new CommandImpl();
command.getAttributes().put(COMPONENT_ALIAS_COMMAND_ATTRIBUTE, "super-plugin");
workspaceConfig.getCommands().add(command);
// when
pluginComponentApplier.apply(workspaceConfig, superPluginComponent, null);
// then
assertEquals(workspaceConfig.getCommands().get(0).getAttributes().get(PLUGIN_ATTRIBUTE), "eclipse/super-plugin/0.0.1");
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project devspaces-images by redhat-developer.
the class PreviewUrlExposer method expose.
public void expose(T env) throws InternalInfrastructureException {
List<CommandImpl> previewUrlCommands = env.getCommands().stream().filter(c -> c.getPreviewUrl() != null).collect(Collectors.toList());
List<ServicePort> portsToProvision = new ArrayList<>();
for (CommandImpl command : previewUrlCommands) {
int port = command.getPreviewUrl().getPort();
Optional<Service> foundService = Services.findServiceWithPort(env.getServices().values(), port);
if (foundService.isPresent()) {
if (!hasMatchingEndpoint(env, foundService.get(), port)) {
ServicePort servicePort = Services.findPort(foundService.get(), port).orElseThrow(() -> new InternalInfrastructureException(String.format("Port '%d' in service '%s' not found. This is not expected, please report a bug!", port, foundService.get().getMetadata().getName())));
String serviceName = foundService.get().getMetadata().getName();
externalServerExposer.expose(env, null, serviceName, serviceName, servicePort, Collections.emptyMap());
}
} else {
portsToProvision.add(createServicePort(port));
}
}
if (!portsToProvision.isEmpty()) {
String serverName = generate(SERVER_PREFIX, SERVER_UNIQUE_PART_SIZE) + "-previewUrl";
Service service = new ServerServiceBuilder().withName(serverName).withPorts(portsToProvision).build();
env.getServices().put(serverName, service);
portsToProvision.forEach(port -> externalServerExposer.expose(env, null, service.getMetadata().getName(), service.getMetadata().getName(), port, Collections.emptyMap()));
}
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project devspaces-images by redhat-developer.
the class KubernetesPluginsToolingApplierTest method shouldProvisionPluginsCommandsToEnvironment.
@Test
public void shouldProvisionPluginsCommandsToEnvironment() throws Exception {
// given
Command pluginCommand = new Command().name("test-command").workingDir("~").command(Arrays.asList("./build.sh", "--no-pull"));
// when
applier.apply(runtimeIdentity, internalEnvironment, singletonList(createChePlugin(createContainer("container", pluginCommand))));
// then
List<CommandImpl> envCommands = internalEnvironment.getCommands();
assertEquals(envCommands.size(), 1);
CommandImpl envCommand = envCommands.get(0);
assertEquals(envCommand.getName(), pluginCommand.getName());
assertEquals(envCommand.getCommandLine(), String.join(" ", pluginCommand.getCommand()));
assertEquals(envCommand.getType(), "custom");
assertEquals(envCommand.getAttributes().get(WORKING_DIRECTORY_ATTRIBUTE), pluginCommand.getWorkingDir());
validateContainerNameName(envCommand.getAttributes().get(MACHINE_NAME_ATTRIBUTE), "container");
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project devspaces-images by redhat-developer.
the class PreviewUrlExposerTest method shouldNotProvisionWhenServiceAndIngressFound.
@Test
public void shouldNotProvisionWhenServiceAndIngressFound() throws InternalInfrastructureException {
final int PORT = 8080;
final String SERVER_PORT_NAME = "server-" + PORT;
CommandImpl command = new CommandImpl("a", "a", "a", new PreviewUrlImpl(PORT, null), Collections.emptyMap());
Service service = new Service();
ObjectMeta serviceMeta = new ObjectMeta();
serviceMeta.setName("servicename");
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);
Ingress ingress = new Ingress();
ObjectMeta ingressMeta = new ObjectMeta();
ingressMeta.setName("ingressname");
ingress.setMetadata(ingressMeta);
IngressSpec ingressSpec = new IngressSpec();
IngressRule ingressRule = new IngressRule();
ingressRule.setHost("ingresshost");
IngressBackend ingressBackend = new IngressBackend(null, new IngressServiceBackend("servicename", new ServiceBackendPort(SERVER_PORT_NAME, PORT)));
ingressRule.setHttp(new HTTPIngressRuleValue(singletonList(new HTTPIngressPath(ingressBackend, null, null))));
ingressSpec.setRules(singletonList(ingressRule));
ingress.setSpec(ingressSpec);
Map<String, Service> services = new HashMap<>();
services.put("servicename", service);
Map<String, Ingress> ingresses = new HashMap<>();
ingresses.put("ingressname", ingress);
KubernetesEnvironment env = KubernetesEnvironment.builder().setCommands(singletonList(new CommandImpl(command))).setServices(services).setIngresses(ingresses).build();
assertEquals(env.getIngresses().size(), 1);
previewUrlExposer.expose(env);
assertEquals(env.getIngresses().size(), 1);
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project devspaces-images by redhat-developer.
the class PreviewUrlExposerTest method shouldProvisionIngressWhenNotFound.
@Test
public void shouldProvisionIngressWhenNotFound() throws InternalInfrastructureException {
Mockito.when(externalServiceExposureStrategy.getExternalPath(Mockito.anyString(), Mockito.any())).thenReturn("some-server-path");
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);
KubernetesEnvironment env = KubernetesEnvironment.builder().setCommands(singletonList(new CommandImpl(command))).setServices(services).setIngresses(new HashMap<>()).build();
previewUrlExposer.expose(env);
assertEquals(env.getIngresses().size(), 1);
Ingress provisionedIngress = env.getIngresses().values().iterator().next();
IngressBackend provisionedIngressBackend = provisionedIngress.getSpec().getRules().get(0).getHttp().getPaths().get(0).getBackend();
assertEquals(provisionedIngressBackend.getService().getPort().getName(), SERVER_PORT_NAME);
assertEquals(provisionedIngressBackend.getService().getName(), SERVICE_NAME);
}
Aggregations