Search in sources :

Example 1 with IPod

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

the class OpenShiftServerUtils method getAllPods.

/**
 * Returns all pods for the given server. Returns an empty list otherwise.
 *
 * @param server
 * @return
 */
public static Collection<IPod> getAllPods(IServer server, IProgressMonitor monitor) {
    Connection connection = getConnection(server);
    if (connection == null) {
        return Collections.emptyList();
    }
    IResource resource = getResource(server, connection, monitor);
    if (resource == null) {
        return Collections.emptyList();
    }
    List<IPod> collection = new ArrayList<>();
    List<IPod> pods = connection.getResources(ResourceKind.POD, resource.getNamespaceName());
    List<IPod> servicePods = ResourceUtils.getPodsFor(resource, pods);
    collection.addAll(pods);
    collection.addAll(servicePods);
    return collection;
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) ArrayList(java.util.ArrayList) IResource(com.openshift.restclient.model.IResource) IPod(com.openshift.restclient.model.IPod)

Example 2 with IPod

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

the class PodLogsHandler method getPodFromBuild.

private IPod getPodFromBuild(ExecutionEvent event) {
    IBuild build = getSelectedElement(event, IBuild.class);
    if (build != null) {
        final String buildName = build.getName();
        Connection connection = ConnectionsRegistryUtil.safeGetConnectionFor(build);
        List<IPod> pods = connection.getResources(ResourceKind.POD, build.getNamespaceName());
        for (IPod pod : pods) {
            if (buildName.equals(pod.getAnnotation(OpenShiftAPIAnnotations.BUILD_NAME))) {
                return pod;
            }
        }
    }
    return null;
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) IPod(com.openshift.restclient.model.IPod) IBuild(com.openshift.restclient.model.IBuild)

Example 3 with IPod

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

the class PortForwardingHandler method handleEvent.

@Override
protected void handleEvent(ExecutionEvent event) {
    ISelection selection = UIUtils.getCurrentSelection(event);
    final IPod pod = UIUtils.getFirstElement(selection, IPod.class);
    if (pod == null) {
        MessageDialog.openError(HandlerUtil.getActiveShell(event), "No pod selection", "No pod was selected for port forwarding.");
    }
    openDialog(pod);
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) IPod(com.openshift.restclient.model.IPod)

Example 4 with IPod

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

the class ResourceUtils method getDeploymentConfigFor.

private static IDeploymentConfig getDeploymentConfigFor(IService service, Connection connection) {
    if (service == null) {
        return null;
    }
    String dcName = getDeploymentConfigNameFor(service);
    if (dcName != null) {
        return getDeploymentConfigByName(dcName, service, connection);
    } else {
        String namespace = service.getNamespaceName();
        IReplicationController rc = getReplicationControllerFor(service, connection.getResources(ResourceKind.REPLICATION_CONTROLLER, namespace));
        if (rc == null) {
            return null;
        }
        List<IPod> allPods = connection.getResources(ResourceKind.POD, namespace);
        List<IPod> pods = allPods.stream().filter(pod -> areRelated((IPod) pod, rc)).collect(Collectors.toList());
        if (CollectionUtils.isEmpty(pods)) {
            return null;
        }
        List<IDeploymentConfig> dcs = connection.getResources(ResourceKind.DEPLOYMENT_CONFIG, namespace);
        return dcs.stream().filter(dc -> areRelated((IService) service, (IDeploymentConfig) dc, pods)).findFirst().orElse(null);
    }
}
Also used : Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) IBuildConfig(com.openshift.restclient.model.IBuildConfig) KeyValueFilterFactory(org.jboss.tools.openshift.internal.common.core.util.KeyValueFilterFactory) URISyntaxException(java.net.URISyntaxException) CoreException(org.eclipse.core.runtime.CoreException) IDeploymentImageChangeTrigger(com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger) IProject(com.openshift.restclient.model.IProject) HashSet(java.util.HashSet) IPod(com.openshift.restclient.model.IPod) IClientCapability(com.openshift.restclient.capability.resources.IClientCapability) CollectionUtils(org.apache.commons.collections.CollectionUtils) EGitUtils(org.jboss.tools.openshift.egit.core.EGitUtils) Map(java.util.Map) KeyValueFilter(org.jboss.tools.openshift.internal.common.core.util.KeyValueFilterFactory.KeyValueFilter) URIish(org.eclipse.jgit.transport.URIish) OpenShiftResourceSelectors(org.jboss.tools.openshift.core.OpenShiftResourceSelectors) ITags(com.openshift.restclient.capability.resources.ITags) IImageStreamImport(com.openshift.restclient.model.image.IImageStreamImport) StatusFactory(org.jboss.tools.foundation.core.plugin.log.StatusFactory) IService(com.openshift.restclient.model.IService) IResource(com.openshift.restclient.model.IResource) ResourceKind(com.openshift.restclient.ResourceKind) MapUtils(org.apache.commons.collections.MapUtils) NLS(org.eclipse.osgi.util.NLS) Collection(java.util.Collection) IBuild(com.openshift.restclient.model.IBuild) Set(java.util.Set) OpenShiftCoreActivator(org.jboss.tools.openshift.internal.core.OpenShiftCoreActivator) Collectors(java.util.stream.Collectors) IObjectReference(com.openshift.restclient.model.IObjectReference) Connection(org.jboss.tools.openshift.core.connection.Connection) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) OpenShiftAPIAnnotations(org.jboss.tools.openshift.core.OpenShiftAPIAnnotations) IClient(com.openshift.restclient.IClient) CapabilityVisitor(com.openshift.restclient.capability.CapabilityVisitor) IRoute(com.openshift.restclient.model.route.IRoute) Optional(java.util.Optional) ModelNode(org.jboss.dmr.ModelNode) Comparator(java.util.Comparator) Collections(java.util.Collections) IReplicationController(com.openshift.restclient.model.IReplicationController) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IReplicationController(com.openshift.restclient.model.IReplicationController) IPod(com.openshift.restclient.model.IPod) IService(com.openshift.restclient.model.IService)

Example 5 with IPod

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

the class PortForwardingUtilsTest method shouldStartPortForwardingOnSinglePort.

@Test
@SuppressWarnings("unchecked")
public void shouldStartPortForwardingOnSinglePort() {
    // given
    final IPod pod = Mockito.mock(IPod.class);
    final PortPair port = Mockito.mock(PortPair.class);
    final IPortForwardable portForwardable = Mockito.mock(IPortForwardable.class);
    Mockito.when(pod.accept(Mockito.any(CapabilityVisitor.class), Mockito.any(IPortForwardable.class))).thenReturn(portForwardable);
    Mockito.when(portForwardable.isForwarding()).thenReturn(true);
    // when
    final IPortForwardable startPortForwarding = PortForwardingUtils.startPortForwarding(pod, port);
    // then
    assertThat(startPortForwarding).isNotNull().isEqualTo(portForwardable);
    assertThat(PortForwardingUtils.isPortForwardingStarted(pod)).isTrue();
}
Also used : IPortForwardable(com.openshift.restclient.capability.resources.IPortForwardable) PortPair(com.openshift.restclient.capability.resources.IPortForwardable.PortPair) CapabilityVisitor(com.openshift.restclient.capability.CapabilityVisitor) IPod(com.openshift.restclient.model.IPod) Test(org.junit.Test)

Aggregations

IPod (com.openshift.restclient.model.IPod)27 Connection (org.jboss.tools.openshift.core.connection.Connection)11 Test (org.junit.Test)9 IResource (com.openshift.restclient.model.IResource)8 ResourceKind (com.openshift.restclient.ResourceKind)6 IPortForwardable (com.openshift.restclient.capability.resources.IPortForwardable)6 PortPair (com.openshift.restclient.capability.resources.IPortForwardable.PortPair)6 IReplicationController (com.openshift.restclient.model.IReplicationController)6 HashMap (java.util.HashMap)6 IConnection (org.jboss.tools.openshift.common.core.connection.IConnection)6 CapabilityVisitor (com.openshift.restclient.capability.CapabilityVisitor)5 Collection (java.util.Collection)5 List (java.util.List)5 Map (java.util.Map)5 ResourceUtils (org.jboss.tools.openshift.internal.core.util.ResourceUtils)5 IBuild (com.openshift.restclient.model.IBuild)4 IDeploymentConfig (com.openshift.restclient.model.IDeploymentConfig)4 IService (com.openshift.restclient.model.IService)4 CoreException (org.eclipse.core.runtime.CoreException)4 ISelection (org.eclipse.jface.viewers.ISelection)4