Search in sources :

Example 6 with IContainer

use of com.openshift.restclient.model.IContainer in project jbosstools-openshift by jbosstools.

the class ResourceMocks method createContainer.

public static IContainer createContainer(String name, Set<IPort> ports, IProbe livenessProbe, IProbe readinessProbe) {
    IContainer container = mock(IContainer.class);
    doReturn(name).when(container).getName();
    doReturn(ports).when(container).getPorts();
    doReturn(livenessProbe).when(container).getLivenessProbe();
    doReturn(readinessProbe).when(container).getReadinessProbe();
    return container;
}
Also used : IContainer(com.openshift.restclient.model.IContainer)

Example 7 with IContainer

use of com.openshift.restclient.model.IContainer in project jbosstools-openshift by jbosstools.

the class DeployImageJobTest method testStubDeploymentConfig.

@Test
public void testStubDeploymentConfig() {
    IImageStream is = givenAnImageStreamTo(project.getName(), DOCKER_TAG);
    IResource resource = job.stubDeploymentConfig(factory, RESOURCE_NAME, DOCKER_TAG, is);
    assertTrue(resource instanceof IDeploymentConfig);
    IDeploymentConfig dc = (IDeploymentConfig) resource;
    assertEquals("Exp. replicas to match incoming params", parameters.getReplicas(), dc.getReplicas());
    assertEquals("Exp. the selector key to be the resourceName", RESOURCE_NAME, dc.getReplicaSelector().get(DeployImageJob.SELECTOR_KEY));
    IContainer container = dc.getContainer(RESOURCE_NAME);
    assertNotNull("Exp. to find a container with the resource name", container);
    Collection<IDeploymentTrigger> triggers = dc.getTriggers();
    assertTrue("Exp. a config change trigger", triggers.stream().filter(t -> DeploymentTriggerType.CONFIG_CHANGE.equals(t.getType())).findFirst().isPresent());
    // assert ict matches container spec
    Optional<IDeploymentTrigger> icTrigger = triggers.stream().filter(t -> DeploymentTriggerType.IMAGE_CHANGE.equals(t.getType())).findFirst();
    assertTrue(icTrigger.isPresent());
    IDeploymentImageChangeTrigger imageChangeTrigger = (IDeploymentImageChangeTrigger) icTrigger.get();
    Collection<String> names = imageChangeTrigger.getContainerNames();
    assertEquals(1, names.size());
    assertEquals("Exp. the container and trigger names to match", container.getName(), names.iterator().next());
    assertTrue(imageChangeTrigger.isAutomatic());
    assertEquals(ResourceKind.IMAGE_STREAM_TAG, imageChangeTrigger.getKind());
    assertEquals("Exp. the trigger to point to the imagestream name", new DockerImageURI(null, null, is.getName(), DOCKER_TAG.getTag()), imageChangeTrigger.getFrom());
    assertEquals("Exp. the trigger to point to the imagestream name", is.getNamespaceName(), imageChangeTrigger.getNamespace());
}
Also used : Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IDeploymentImageChangeTrigger(com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger) IStatus(org.eclipse.core.runtime.IStatus) DeployImageJob(org.jboss.tools.openshift.internal.ui.job.DeployImageJob) IDeploymentTrigger(com.openshift.restclient.model.deploy.IDeploymentTrigger) Matchers.eq(org.mockito.Matchers.eq) IResourceVisitor(org.jboss.tools.openshift.test.util.ResourceMocks.IResourceVisitor) Mockito.doReturn(org.mockito.Mockito.doReturn) ResourceKind(com.openshift.restclient.ResourceKind) Collection(java.util.Collection) Status(org.eclipse.core.runtime.Status) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) Matchers.any(org.mockito.Matchers.any) List(java.util.List) ICommonAttributes(org.jboss.tools.openshift.core.ICommonAttributes) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) ResourceMocks.createResource(org.jboss.tools.openshift.test.util.ResourceMocks.createResource) Mockito.mock(org.mockito.Mockito.mock) ResourceFactory(com.openshift.internal.restclient.ResourceFactory) Mock(org.mockito.Mock) IImageStream(com.openshift.restclient.model.IImageStream) RunWith(org.junit.runner.RunWith) Mockito.spy(org.mockito.Mockito.spy) Matchers.anyString(org.mockito.Matchers.anyString) IProject(com.openshift.restclient.model.IProject) ArrayList(java.util.ArrayList) ResourceMocks.createConnection(org.jboss.tools.openshift.test.util.ResourceMocks.createConnection) IResourceFactory(com.openshift.restclient.IResourceFactory) Before(org.junit.Before) DockerImageURI(com.openshift.restclient.images.DockerImageURI) IResource(com.openshift.restclient.model.IResource) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Connection(org.jboss.tools.openshift.core.connection.Connection) Mockito.verify(org.mockito.Mockito.verify) IDeployImageParameters(org.jboss.tools.openshift.internal.ui.wizard.deployimage.IDeployImageParameters) Assert.assertNull(org.junit.Assert.assertNull) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) IClient(com.openshift.restclient.IClient) DeploymentTriggerType(com.openshift.restclient.model.deploy.DeploymentTriggerType) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) IContainer(com.openshift.restclient.model.IContainer) DockerImageURI(com.openshift.restclient.images.DockerImageURI) IImageStream(com.openshift.restclient.model.IImageStream) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IDeploymentTrigger(com.openshift.restclient.model.deploy.IDeploymentTrigger) Matchers.anyString(org.mockito.Matchers.anyString) IContainer(com.openshift.restclient.model.IContainer) IDeploymentImageChangeTrigger(com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger) IResource(com.openshift.restclient.model.IResource) Test(org.junit.Test)

Example 8 with IContainer

use of com.openshift.restclient.model.IContainer in project jbosstools-openshift by jbosstools.

the class OpenShiftDebugMode method updateContainerDebugPort.

private void updateContainerDebugPort(IDeploymentConfig dc, DebugContext context) {
    Collection<IContainer> containers = dc.getContainers();
    if (CollectionUtils.isEmpty(containers)) {
        return;
    }
    // TODO: support multiple containers
    IContainer firstContainer = containers.iterator().next();
    IPort currentContainerPort = getCurrentContainerPort(firstContainer.getPorts());
    boolean modified = false;
    Set<IPort> ports = new HashSet<>(firstContainer.getPorts());
    if (context.isDebugEnabled()) {
        modified = addReplaceDebugPort(context.getDebugPort(), currentContainerPort, ports);
    } else {
        modified = removeDebugPort(currentContainerPort, ports);
    }
    if (modified) {
        firstContainer.setPorts(ports);
    }
}
Also used : IPort(com.openshift.restclient.model.IPort) IContainer(com.openshift.restclient.model.IContainer) HashSet(java.util.HashSet)

Example 9 with IContainer

use of com.openshift.restclient.model.IContainer in project jbosstools-openshift by jbosstools.

the class LivenessProbe method getLivenessProbe.

private IProbe getLivenessProbe(IDeploymentConfig dc) {
    Collection<IContainer> containers = dc.getContainers();
    if (null == containers) {
        return null;
    }
    IContainer container = containers.stream().findFirst().orElse(null);
    if (container == null) {
        return null;
    }
    return container.getLivenessProbe();
}
Also used : IContainer(com.openshift.restclient.model.IContainer)

Example 10 with IContainer

use of com.openshift.restclient.model.IContainer in project jbosstools-openshift by jbosstools.

the class PodLogsHandler method showLogs.

protected void showLogs(IPod pod, ExecutionEvent event) {
    if (pod == null) {
        showDialog(event, "No pod selected", "No pod was selected to retrieve a log.");
        return;
    }
    if (!ArrayUtils.contains(STATES, pod.getStatus())) {
        showDialog(event, "Logs Unavailable", NLS.bind(INVALID_POD_STATUS_MESSAGE, pod.getStatus()));
        return;
    }
    Collection<IContainer> containers = pod.getContainers();
    if (containers.isEmpty()) {
        showDialog(event, "Logs Unavailable", "There are no containers from which to retrieve logs");
        return;
    }
    String containerName = null;
    if (containers.size() > 1) {
        List<String> names = containers.stream().map(c -> c.getName()).collect(Collectors.toList());
        Collections.sort(names);
        ElementListSelectionDialog dialog = new ElementListSelectionDialog(HandlerUtil.getActiveShell(event), new LabelProvider());
        dialog.setElements(names.toArray());
        dialog.setTitle("Pod Containers");
        dialog.setMessage("Select a pod container");
        dialog.setMultipleSelection(false);
        int result = dialog.open();
        if (Window.CANCEL == result) {
            return;
        }
        containerName = (String) dialog.getFirstResult();
    } else if (containers.size() == 1) {
        containerName = containers.iterator().next().getName();
    }
    new PodLogsJob(pod, containerName).schedule();
}
Also used : ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) ResourceKind(com.openshift.restclient.ResourceKind) NLS(org.eclipse.osgi.util.NLS) Collection(java.util.Collection) IBuild(com.openshift.restclient.model.IBuild) Collectors(java.util.stream.Collectors) Connection(org.jboss.tools.openshift.core.connection.Connection) HandlerUtil(org.eclipse.ui.handlers.HandlerUtil) IPod(com.openshift.restclient.model.IPod) List(java.util.List) Window(org.eclipse.jface.window.Window) UIUtils(org.jboss.tools.openshift.internal.common.ui.utils.UIUtils) OpenShiftAPIAnnotations(org.jboss.tools.openshift.core.OpenShiftAPIAnnotations) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) PodLogsJob(org.jboss.tools.openshift.internal.ui.job.PodLogsJob) ConnectionsRegistryUtil(org.jboss.tools.openshift.core.connection.ConnectionsRegistryUtil) ISelection(org.eclipse.jface.viewers.ISelection) ElementListSelectionDialog(org.eclipse.ui.dialogs.ElementListSelectionDialog) Collections(java.util.Collections) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) LabelProvider(org.eclipse.jface.viewers.LabelProvider) IContainer(com.openshift.restclient.model.IContainer) ArrayUtils(org.apache.commons.lang.ArrayUtils) PodLogsJob(org.jboss.tools.openshift.internal.ui.job.PodLogsJob) ElementListSelectionDialog(org.eclipse.ui.dialogs.ElementListSelectionDialog) IContainer(com.openshift.restclient.model.IContainer) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Aggregations

IContainer (com.openshift.restclient.model.IContainer)10 Test (org.junit.Test)5 IPort (com.openshift.restclient.model.IPort)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4 ResourceKind (com.openshift.restclient.ResourceKind)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 List (java.util.List)2 LabelProvider (org.eclipse.jface.viewers.LabelProvider)2 Connection (org.jboss.tools.openshift.core.connection.Connection)2 ResourceFactory (com.openshift.internal.restclient.ResourceFactory)1 IClient (com.openshift.restclient.IClient)1 IResourceFactory (com.openshift.restclient.IResourceFactory)1 DockerImageURI (com.openshift.restclient.images.DockerImageURI)1 IBuild (com.openshift.restclient.model.IBuild)1 IDeploymentConfig (com.openshift.restclient.model.IDeploymentConfig)1 IImageStream (com.openshift.restclient.model.IImageStream)1 IPod (com.openshift.restclient.model.IPod)1 IProject (com.openshift.restclient.model.IProject)1