use of com.openshift.restclient.model.IResource in project jbosstools-openshift by jbosstools.
the class OpenShiftServerUtils method getResourceChecked.
/**
* Returns the {@link IResource} that's stored in the given server. Throws a
* {@link CoreException} if none was found.
*
* @param server
* @param connection
* @param monitor
* @return
* @throws CoreException
*/
public static IResource getResourceChecked(IServerAttributes server, Connection connection, IProgressMonitor monitor) throws CoreException {
IResource resource = getResource(server, connection, monitor);
if (resource == null) {
String uniqueId = OpenShiftServerUtils.getResourceUniqueId(server);
String projectName = OpenShiftResourceUniqueId.getProjectName(uniqueId);
String resourceName = OpenShiftResourceUniqueId.getResourceName(uniqueId);
String resourceKind = OpenShiftResourceUniqueId.getKind(uniqueId);
throw new CoreException(OpenShiftCoreActivator.statusFactory().errorStatus(NLS.bind("Could not publish server {0}: could not find {1} \"{2}\" in project \"{3}\".", new String[] { server.getName(), resourceKind, resourceName, projectName })));
}
return resource;
}
use of com.openshift.restclient.model.IResource in project jbosstools-openshift by jbosstools.
the class OpenShiftPropertySourceAdapterFactory method getAdapter.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Object getAdapter(Object adaptableObject, Class adapterType) {
if (adapterType == IPropertySource.class) {
Connection connection = Adapters.adapt(adaptableObject, Connection.class);
if (connection != null) {
if (currentConnectionPropertySource != null) {
currentConnectionPropertySource.dispose();
}
return currentConnectionPropertySource = new ConnectionPropertySource(connection);
}
IResource resource = Adapters.adapt(adaptableObject, IResource.class);
if (resource != null) {
switch(resource.getKind()) {
case ResourceKind.BUILD:
return new BuildPropertySource((IBuild) resource);
case ResourceKind.BUILD_CONFIG:
return new BuildConfigPropertySource((IBuildConfig) resource);
case ResourceKind.EVENT:
return new EventPropertySource((IEvent) resource);
case ResourceKind.IMAGE_STREAM:
return new ImageStreamPropertySource((IImageStream) resource);
case ResourceKind.POD:
return new PodPropertySource((IPod) resource);
case ResourceKind.REPLICATION_CONTROLLER:
return new ReplicationControllerPropertySource((IReplicationController) resource);
case ResourceKind.ROUTE:
return new RoutePropertySource((IRoute) resource);
case ResourceKind.SERVICE:
return new ServicePropertySource((IService) resource);
case ResourceKind.PVC:
return new StoragePropertySource((IPersistentVolumeClaim) resource);
default:
return new ResourcePropertySource<>(resource);
}
}
}
return null;
}
use of com.openshift.restclient.model.IResource in project jbosstools-openshift by jbosstools.
the class ResourceContainer method updateWithResources.
void updateWithResources(Collection<IResource> resources) {
Map<IResource, AbstractResourceWrapper<?, ?>> updated = new HashMap<>();
boolean changed = false;
synchronized (childrenLock) {
HashMap<IResource, AbstractResourceWrapper<?, ?>> oldWrappers = new HashMap<>(containedResources);
containedResources.clear();
for (IResource r : resources) {
AbstractResourceWrapper<?, ?> existingWrapper = oldWrappers.remove(r);
if (existingWrapper == null) {
AbstractResourceWrapper<?, ?> newWrapper = createNewWrapper(resources, r);
containedResources.put(r, newWrapper);
changed = true;
} else {
containedResources.put(r, existingWrapper);
updated.put(r, existingWrapper);
}
}
if (!oldWrappers.isEmpty()) {
changed = true;
}
}
if (changed) {
fireChanged();
}
updated.keySet().forEach(r -> {
AbstractResourceWrapper<?, ?> wrapper = updated.get(r);
wrapper.updateWith(r);
});
postUpdate(resources, updated, changed);
}
use of com.openshift.restclient.model.IResource in project jbosstools-openshift by jbosstools.
the class ImportApplicationWizard method init.
@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
if (model.getConnection() != null && model.getSelectedItem() != null) {
return;
}
Connection connection = UIUtils.getFirstElement(selection, Connection.class);
if (connection != null) {
model.setConnection(connection);
} else {
IResource resource = UIUtils.getFirstElement(selection, IResource.class);
if (resource != null) {
setModelConnection(ConnectionsRegistryUtil.safeGetConnectionFor(resource));
model.setSelectedItem(resource);
} else {
IProject project = UIUtils.getFirstElement(selection, IProject.class);
if (project != null) {
setModelConnection(ConnectionsRegistryUtil.safeGetConnectionFor(project));
model.setSelectedItem(project);
}
}
}
}
use of com.openshift.restclient.model.IResource in project jbosstools-openshift by jbosstools.
the class CleanOpenShiftConnectionRequirement method fulfill.
@Override
public void fulfill() {
Connection connection = ConnectionUtils.getConnectionOrDefault(cleanConnection.connectionURL());
assertNotNull("There is no connection with URL " + cleanConnection.connectionURL(), connection);
List<IResource> projects = connection.getResources(ResourceKind.PROJECT);
for (IResource project : projects) {
String projectName = project.getName();
connection.deleteResource(project);
new WaitWhile(new ProjectExists(projectName, connection), TimePeriod.LONG);
}
connection.refresh();
}
Aggregations