Search in sources :

Example 56 with IResource

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;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IResource(com.openshift.restclient.model.IResource)

Example 57 with IResource

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;
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection) IResource(com.openshift.restclient.model.IResource)

Example 58 with IResource

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);
}
Also used : HashMap(java.util.HashMap) IResource(com.openshift.restclient.model.IResource)

Example 59 with IResource

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);
            }
        }
    }
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection) IResource(com.openshift.restclient.model.IResource) IProject(com.openshift.restclient.model.IProject)

Example 60 with IResource

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();
}
Also used : WaitWhile(org.eclipse.reddeer.common.wait.WaitWhile) ProjectExists(org.jboss.tools.openshift.reddeer.condition.core.ProjectExists) CleanConnection(org.jboss.tools.openshift.reddeer.requirement.CleanOpenShiftConnectionRequirement.CleanConnection) Connection(org.jboss.tools.openshift.core.connection.Connection) IResource(com.openshift.restclient.model.IResource)

Aggregations

IResource (com.openshift.restclient.model.IResource)101 Test (org.junit.Test)32 Connection (org.jboss.tools.openshift.core.connection.Connection)27 IProject (com.openshift.restclient.model.IProject)14 IStatus (org.eclipse.core.runtime.IStatus)12 Collection (java.util.Collection)10 ServerResourceViewModel (org.jboss.tools.openshift.internal.ui.server.ServerResourceViewModel)9 IReplicationController (com.openshift.restclient.model.IReplicationController)8 IService (com.openshift.restclient.model.IService)8 ArrayList (java.util.ArrayList)8 CoreException (org.eclipse.core.runtime.CoreException)8 IDeploymentConfig (com.openshift.restclient.model.IDeploymentConfig)7 Status (org.eclipse.core.runtime.Status)7 ISelection (org.eclipse.jface.viewers.ISelection)7 OpenShiftException (com.openshift.restclient.OpenShiftException)6 ResourceKind (com.openshift.restclient.ResourceKind)6 IPod (com.openshift.restclient.model.IPod)6 List (java.util.List)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 IBuildConfig (com.openshift.restclient.model.IBuildConfig)5