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());
}
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;
}
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;
}
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);
}
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);
}
Aggregations