use of com.openshift.restclient.model.IResource in project jbosstools-openshift by jbosstools.
the class ConnectionWrapper method refresh.
void refresh(ProjectWrapper projectWrapper) {
resourceCache.flush(projectWrapper.getWrapped().getNamespaceName());
IProject project = projectWrapper.getWrapped();
IOpenShiftConnection connection = projectWrapper.getParent().getWrapped();
WatchManager.getInstance().stopWatch(project, connection);
WatchManager.getInstance().startWatch(project, connection);
Collection<IResource> resources = new HashSet<>();
for (String kind : RESOURCE_KINDS) {
resources.addAll(getWrapped().getResources(kind, project.getNamespaceName()));
}
resources.forEach(r -> resourceCache.add(r));
projectWrapper.updateWithResources(resources);
}
use of com.openshift.restclient.model.IResource 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.IResource in project jbosstools-openshift by jbosstools.
the class DeployImageJob method doRun.
@Override
protected IStatus doRun(IProgressMonitor monitor) {
try {
final Connection connection = parameters.getConnection();
final String name = parameters.getResourceName();
if (updateTriggerIfUpdate(connection, parameters.getProject().getName(), name)) {
return Status.OK_STATUS;
}
Map<String, IResource> resources = generateResources(connection, name);
// validate
Collection<IResource> existing = findExistingResources(connection, resources.values());
// TODO may need to disregard if only error is the imagestream - TBD
if (!existing.isEmpty()) {
return createErrorStatusForExistingResources(existing);
}
// create
created = createResources(connection, resources.values());
} catch (Exception e) {
String message = NLS.bind("Unable to create resources to deploy image {0}", parameters.getImageName());
OpenShiftUIActivator.getDefault().getLogger().logError(message, e);
return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID, message, e);
}
return Status.OK_STATUS;
}
use of com.openshift.restclient.model.IResource in project jbosstools-openshift by jbosstools.
the class RefreshResourcesJob method doRun.
@Override
protected IStatus doRun(IProgressMonitor monitor) {
try {
monitor.beginTask("Refreshing OpenShift resources...", IProgressMonitor.UNKNOWN);
refreshedResources.clear();
Collection<IResource> resources = model.getResources();
if (resources == null || resources.isEmpty())
return Status.OK_STATUS;
for (IResource resource : resources) {
if (ResourceKind.STATUS.equals(resource.getKind())) {
continue;
}
Connection connection = ConnectionsRegistryUtil.safeGetConnectionFor(resource);
if (connection != null) {
IResource newValue = ((Connection) connection).refresh(resource);
IResource oldValue = resourcesAdded ? null : resource;
refreshedResources.add(newValue);
ConnectionsRegistrySingleton.getInstance().fireConnectionChanged(connection, ConnectionProperties.PROPERTY_RESOURCE, oldValue, newValue);
}
}
} catch (Exception e) {
return new Status(Status.ERROR, OpenShiftUIActivator.PLUGIN_ID, "Exception refreshing resources", e);
} finally {
monitor.done();
}
return Status.OK_STATUS;
}
use of com.openshift.restclient.model.IResource in project jbosstools-openshift by jbosstools.
the class ResourceCreationJobUtils method findExistingResources.
/*
* MAYBE this should be part of Connection in an exists method?
*/
public static Collection<IResource> findExistingResources(Connection connection, Collection<IResource> resources) {
List<IResource> existing = new ArrayList<>(resources.size());
for (IResource resource : resources) {
try {
IResource found = connection.refresh(resource);
existing.add(found);
} catch (OpenShiftException e) {
// this is expected if the resource is not found
// @TODO change to NotFoundException of some kind
}
}
return existing;
}
Aggregations