Search in sources :

Example 16 with IPod

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

the class NewPodDetectorJob method getOldPods.

private Collection<String> getOldPods(IReplicationController rc) {
    Connection connection = ConnectionsRegistryUtil.getConnectionFor(rc);
    List<IPod> allPods = connection.getResources(ResourceKind.POD, rc.getNamespaceName());
    return ResourceUtils.getPodsFor(rc, allPods).stream().filter(pod -> ResourceUtils.isRuntimePod(pod)).map(p -> p.getName()).collect(Collectors.toList());
}
Also used : ResourceKind(com.openshift.restclient.ResourceKind) Job(org.eclipse.core.runtime.jobs.Job) Collection(java.util.Collection) Status(org.eclipse.core.runtime.Status) OpenShiftCoreActivator(org.jboss.tools.openshift.internal.core.OpenShiftCoreActivator) Collectors(java.util.stream.Collectors) Connection(org.jboss.tools.openshift.core.connection.Connection) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IPod(com.openshift.restclient.model.IPod) List(java.util.List) IStatus(org.eclipse.core.runtime.IStatus) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) ConnectionsRegistryUtil(org.jboss.tools.openshift.core.connection.ConnectionsRegistryUtil) ConnectionsRegistryAdapter(org.jboss.tools.openshift.common.core.connection.ConnectionsRegistryAdapter) ConnectionsRegistrySingleton(org.jboss.tools.openshift.common.core.connection.ConnectionsRegistrySingleton) IConnectionsRegistryListener(org.jboss.tools.openshift.common.core.connection.IConnectionsRegistryListener) Collections(java.util.Collections) IReplicationController(com.openshift.restclient.model.IReplicationController) Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) IPod(com.openshift.restclient.model.IPod)

Example 17 with IPod

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

the class OpenShiftDebugMode method execute.

/**
 * Sends the changes to the deployment config if required. Nothing is done if
 * the deployment config already is in the state that the context is in. If the
 * changes are sent the existing pods are killed and it waits until the new pods
 * are running.
 *
 * @param context
 * @param monitor
 * @throws CoreException
 */
public OpenShiftDebugMode execute(IProgressMonitor monitor) throws CoreException {
    Connection connection = OpenShiftServerUtils.getConnection(context.getServer());
    IResource resource = OpenShiftServerUtils.getResource(context.getServer(), monitor);
    IDeploymentConfig dc = getDeploymentConfig(resource, connection, monitor);
    if (dc == null) {
        throw new CoreException(OpenShiftCoreActivator.statusFactory().errorStatus(NLS.bind("Could not find deployment config for resource {0}. " + "Your build might be still running and pods not created yet or " + "there might be no labels on your pods pointing to the wanted deployment config.", resource != null ? resource.getName() : "")));
    }
    boolean dcUpdated = updateDc(dc, connection, monitor);
    IPod pod = getPod(dcUpdated, dc, connection, monitor);
    context.setPod(pod);
    toggleRouteTimeout(resource, connection, context, monitor);
    toggleDebugger(context, monitor);
    return this;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) OpenShiftCoreException(org.jboss.tools.openshift.common.core.OpenShiftCoreException) Connection(org.jboss.tools.openshift.core.connection.Connection) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IResource(com.openshift.restclient.model.IResource) IPod(com.openshift.restclient.model.IPod)

Example 18 with IPod

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

the class ServerAdapterHandler method getOpenShiftServer.

/**
 * Finds the OpenShift server corresponding to the selection or prompts the
 * user to create one.
 *
 * @param resource
 *            the selected OpenShift {@link IResource}
 *
 * @return the matching OpenShift {@link IServer} or <code>null</code> if
 *         none was found or user cancelled the creation operation.
 */
private IServer getOpenShiftServer(final IResource resource) {
    if (resource == null) {
        return null;
    }
    IResource source = null;
    IRoute route = null;
    if (resource instanceof IService) {
        source = (IService) resource;
    } else if (resource instanceof IRoute) {
        route = (IRoute) resource;
        final IRoute localRoute = route;
        source = (IService) route.getProject().getResources(ResourceKind.SERVICE).stream().filter(s -> ResourceUtils.areRelated(localRoute, (IService) s)).findFirst().orElseGet(() -> null);
    } else if (resource instanceof IReplicationController) {
        source = resource;
    } else if (resource instanceof IPod) {
        final Collection<IService> services = ResourceUtils.getServicesFor((IPod) resource, resource.getProject().getResources(ResourceKind.SERVICE));
        if (!services.isEmpty()) {
            source = services.iterator().next();
        } else {
            source = ResourceUtils.getDeploymentConfigOrReplicationControllerFor((IPod) resource);
        }
    }
    if (source != null) {
        final Connection connection = ConnectionsRegistryUtil.safeGetConnectionFor(source);
        return openOrCreateServerAdapter(source, route, connection);
    }
    return null;
}
Also used : ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) ServerSettingsWizard(org.jboss.tools.openshift.internal.ui.server.ServerSettingsWizard) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ResourceUtils(org.jboss.tools.openshift.internal.core.util.ResourceUtils) OpenShiftResourceUniqueId(org.jboss.tools.openshift.core.util.OpenShiftResourceUniqueId) CoreException(org.eclipse.core.runtime.CoreException) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) HandlerUtil(org.eclipse.ui.handlers.HandlerUtil) IPod(com.openshift.restclient.model.IPod) UIUtils(org.jboss.tools.openshift.internal.common.ui.utils.UIUtils) PartInitException(org.eclipse.ui.PartInitException) CommonNavigator(org.eclipse.ui.navigator.CommonNavigator) OpenShiftUIActivator(org.jboss.tools.openshift.internal.ui.OpenShiftUIActivator) IService(com.openshift.restclient.model.IService) IResource(com.openshift.restclient.model.IResource) ResourceKind(com.openshift.restclient.ResourceKind) NLS(org.eclipse.osgi.util.NLS) Collection(java.util.Collection) IServer(org.eclipse.wst.server.core.IServer) OpenShiftServerUtils(org.jboss.tools.openshift.core.server.OpenShiftServerUtils) ExecutionException(org.eclipse.core.commands.ExecutionException) Display(org.eclipse.swt.widgets.Display) Connection(org.jboss.tools.openshift.core.connection.Connection) WizardUtils(org.jboss.tools.common.ui.WizardUtils) IRoute(com.openshift.restclient.model.route.IRoute) ConnectionsRegistryUtil(org.jboss.tools.openshift.core.connection.ConnectionsRegistryUtil) ISelection(org.eclipse.jface.viewers.ISelection) AbstractHandler(org.eclipse.core.commands.AbstractHandler) IServerWorkingCopy(org.eclipse.wst.server.core.IServerWorkingCopy) IReplicationController(com.openshift.restclient.model.IReplicationController) Connection(org.jboss.tools.openshift.core.connection.Connection) IRoute(com.openshift.restclient.model.route.IRoute) Collection(java.util.Collection) IResource(com.openshift.restclient.model.IResource) IService(com.openshift.restclient.model.IService) IReplicationController(com.openshift.restclient.model.IReplicationController) IPod(com.openshift.restclient.model.IPod)

Example 19 with IPod

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

the class PortForwardingUtils method getForwardablePorts.

/**
 * Returns the {@link PortPair} for the given {@code pod}
 * @param pod the pod to analyze
 * @return an <strong>immutable</strong> {@link Set} of {@link PortPair}
 */
public static Set<IPortForwardable.PortPair> getForwardablePorts(final IPod pod) {
    final Set<IPortForwardable.PortPair> ports = new HashSet<>();
    final IPortForwardable forwardable = REGISTRY.get(pod);
    if (forwardable != null && forwardable.getPortPairs() != null) {
        ports.addAll(forwardable.getPortPairs());
    } else if (pod.getContainerPorts() != null) {
        pod.getContainerPorts().stream().map(containerPort -> new IPortForwardable.PortPair(containerPort)).forEach(portPair -> ports.add(portPair));
    }
    return Collections.unmodifiableSet(ports);
}
Also used : IPortForwardable(com.openshift.restclient.capability.resources.IPortForwardable) OutputStream(java.io.OutputStream) Arrays(java.util.Arrays) MultiStatus(org.eclipse.core.runtime.MultiStatus) IPortForwardable(com.openshift.restclient.capability.resources.IPortForwardable) Collection(java.util.Collection) Set(java.util.Set) IOException(java.io.IOException) HashMap(java.util.HashMap) ServerSocket(java.net.ServerSocket) HashSet(java.util.HashSet) IPod(com.openshift.restclient.model.IPod) OCBinaryOperation(org.jboss.tools.openshift.internal.core.OCBinaryOperation) CapabilityVisitor(com.openshift.restclient.capability.CapabilityVisitor) Map(java.util.Map) ConnectionsRegistryUtil(org.jboss.tools.openshift.core.connection.ConnectionsRegistryUtil) OpenShiftBinaryOption(com.openshift.restclient.capability.IBinaryCapability.OpenShiftBinaryOption) PortPair(com.openshift.restclient.capability.resources.IPortForwardable.PortPair) Collections(java.util.Collections) PortPair(com.openshift.restclient.capability.resources.IPortForwardable.PortPair) PortPair(com.openshift.restclient.capability.resources.IPortForwardable.PortPair) HashSet(java.util.HashSet)

Example 20 with IPod

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

the class PodLogsHandler method handleEvent.

@Override
protected void handleEvent(ExecutionEvent event) {
    IPod pod = getSelectedElement(event, IPod.class);
    if (pod == null) {
        pod = getPodFromBuild(event);
        if (pod == null) {
            MessageDialog.openError(HandlerUtil.getActiveShell(event), "No pod selected", "Unable to determine the build pod in order to retrieve its log.");
            return;
        }
    }
    showLogs(pod, event);
}
Also used : IPod(com.openshift.restclient.model.IPod)

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