Search in sources :

Example 66 with IResource

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

the class OpenShiftServerExtendedProperties method getWelcomePageUrl.

@Override
public String getWelcomePageUrl() throws GetWelcomePageURLException {
    String welcomePageUrl = null;
    try {
        // Get connection explicitly to report failure. Try and connect right now to know if it fails.
        // Do not catch OpenShiftException, let it be reported. We are more concerned of NPE.
        Connection connection = OpenShiftServerUtils.getConnection(server);
        if (connection == null || !connection.connect()) {
            throw new GetWelcomePageURLException("Connection is not established.");
        }
        IResource resource = OpenShiftServerUtils.getResource(server, connection, new NullProgressMonitor());
        if (resource == null) {
            throw new GetWelcomePageURLException("Resource is missing.");
        }
        IProject project = resource.getProject();
        if ((project != null) && (resource instanceof IService)) {
            List<IRoute> routes = ResourceUtils.getRoutesFor((IService) resource, project.getResources(ResourceKind.ROUTE));
            IRoute route = getRoute(OpenShiftServerUtils.getRouteURL(server), routes);
            if (route == null) {
                route = getRoute(routes);
            }
            // Reporting route == null is implemented in getRoute.
            if (route != null) {
                welcomePageUrl = route.getURL();
            }
        }
    } catch (OpenShiftException e) {
        throw new GetWelcomePageURLException(e.getMessage(), e);
    }
    return welcomePageUrl;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) OpenShiftException(com.openshift.restclient.OpenShiftException) Connection(org.jboss.tools.openshift.core.connection.Connection) IRoute(com.openshift.restclient.model.route.IRoute) IResource(com.openshift.restclient.model.IResource) IProject(com.openshift.restclient.model.IProject) IService(com.openshift.restclient.model.IService)

Example 67 with IResource

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

the class DeleteResourcesHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IResourceWrapper<?, ?>[] wrappers = UIUtils.getElements(UIUtils.getCurrentSelection(event), IResourceWrapper.class);
    if (ArrayUtils.isEmpty(wrappers) || wrappers[0].getWrapped() == null) {
        return OpenShiftUIActivator.statusFactory().cancelStatus("Could not delete resources: " + "No resource selected that we can get the connection and namespace from.");
    }
    IResource selectedResource = wrappers[0].getWrapped();
    Connection connection = ConnectionsRegistryUtil.getConnectionFor(selectedResource);
    if (connection == null) {
        return OpenShiftUIActivator.statusFactory().cancelStatus(NLS.bind("Could not delete resources: No connection found for selected resource {0}", selectedResource.getName()));
    }
    String namespace = selectedResource.getNamespaceName();
    openDialog(connection, namespace, HandlerUtil.getActiveShell(event));
    return null;
}
Also used : IResourceWrapper(org.jboss.tools.openshift.internal.ui.models.IResourceWrapper) Connection(org.jboss.tools.openshift.core.connection.Connection) IResource(com.openshift.restclient.model.IResource)

Example 68 with IResource

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

the class OpenShiftExplorerLabelProvider method getAdaptedElement.

private Object getAdaptedElement(Object element) {
    if (element instanceof IAdaptable) {
        IAdaptable adaptable = (IAdaptable) element;
        IResource resource = adaptable.getAdapter(IResource.class);
        if (resource != null) {
            element = resource;
        }
        Connection connection = adaptable.getAdapter(Connection.class);
        if (connection != null) {
            element = connection;
        }
    }
    return element;
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) Connection(org.jboss.tools.openshift.core.connection.Connection) IResource(com.openshift.restclient.model.IResource)

Example 69 with IResource

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

the class ResourceSummaryLabelProvider method getStyledText.

@Override
public StyledString getStyledText(Object arg) {
    if (arg instanceof IResource) {
        IResource resource = (IResource) arg;
        StyledString text = new StyledString();
        if (isFailedStatus(resource)) {
            text.append(((IStatus) resource).getMessage());
        } else {
            text.append(StringUtils.humanize(resource.getKind().toString()));
            text.append(resource.getName(), StyledString.QUALIFIER_STYLER);
        }
        return text;
    }
    return null;
}
Also used : StyledString(org.eclipse.jface.viewers.StyledString) IResource(com.openshift.restclient.model.IResource)

Example 70 with IResource

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

the class OpenShiftServerEditorModel method setResource.

public void setResource(IResource resource, boolean executeCommand) {
    IResource previous = getResource();
    super.setResource(resource);
    // fire server command
    if (executeCommand)
        section.execute(new SetResourceCommand(getServer(), previous, resource));
}
Also used : 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