Search in sources :

Example 1 with IResource

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

the class DockerImageLabels method getImageStreamTag.

private String getImageStreamTag(String imageDigest, String imageRef, String namespace, Connection connection) {
    List<IResource> imageStreamTags = connection.getResources(ResourceKind.IMAGE_STREAM_TAG, namespace);
    IResource imageStreamTag = ResourceUtils.getImageStreamTagForDigest(imageDigest, imageStreamTags);
    if (imageStreamTag == null) {
        return null;
    }
    // load image stream tag individually to get full ContainerConfig metadata
    imageStreamTag = connection.getResource(ResourceKind.IMAGE_STREAM_TAG, namespace, imageStreamTag.getName());
    return imageStreamTag.toJson();
}
Also used : IResource(com.openshift.restclient.model.IResource)

Example 2 with IResource

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

the class OpenShiftServerUtils method getAllPods.

/**
 * Returns all pods for the given server. Returns an empty list otherwise.
 *
 * @param server
 * @return
 */
public static Collection<IPod> getAllPods(IServer server, IProgressMonitor monitor) {
    Connection connection = getConnection(server);
    if (connection == null) {
        return Collections.emptyList();
    }
    IResource resource = getResource(server, connection, monitor);
    if (resource == null) {
        return Collections.emptyList();
    }
    List<IPod> collection = new ArrayList<>();
    List<IPod> pods = connection.getResources(ResourceKind.POD, resource.getNamespaceName());
    List<IPod> servicePods = ResourceUtils.getPodsFor(resource, pods);
    collection.addAll(pods);
    collection.addAll(servicePods);
    return collection;
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) ArrayList(java.util.ArrayList) IResource(com.openshift.restclient.model.IResource) IPod(com.openshift.restclient.model.IPod)

Example 3 with IResource

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

the class ImportApplicationHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    ISelection currentSelection = UIUtils.getCurrentSelection(event);
    IBuildConfig buildConfig = UIUtils.getFirstElement(currentSelection, IBuildConfig.class);
    Map<IProject, Collection<IBuildConfig>> projectsAndBuildConfigs = null;
    IProject project = null;
    Collection<IBuildConfig> buildConfigs = null;
    if (buildConfig == null) {
        IResource resource = UIUtils.getFirstElement(currentSelection, IResource.class);
        if (resource != null) {
            project = resource.getProject();
        }
        if (project != null) {
            buildConfigs = project.getResources(ResourceKind.BUILD_CONFIG);
        }
    } else {
        project = buildConfig.getProject();
        buildConfigs = Collections.singleton(buildConfig);
    }
    if (project != null) {
        if (buildConfigs == null || buildConfigs.isEmpty()) {
            MessageDialog.openWarning(HandlerUtil.getActiveShell(event), NO_BUILD_CONFIG_MSG, NO_BUILD_CONFIG_MSG);
            return OpenShiftUIActivator.statusFactory().cancelStatus(NO_BUILD_CONFIG_MSG);
        }
        projectsAndBuildConfigs = Collections.singletonMap(project, buildConfigs);
    }
    if (projectsAndBuildConfigs == null) {
        ImportApplicationWizard wizard = new ImportApplicationWizard();
        Connection connection = UIUtils.getFirstElement(currentSelection, Connection.class);
        wizard.setConnection(connection);
        WizardUtils.openWizardDialog(wizard, HandlerUtil.getActiveShell(event));
    } else {
        WizardUtils.openWizardDialog(new ImportApplicationWizard(projectsAndBuildConfigs), HandlerUtil.getActiveShell(event));
    }
    return Status.OK_STATUS;
}
Also used : IBuildConfig(com.openshift.restclient.model.IBuildConfig) ISelection(org.eclipse.jface.viewers.ISelection) Connection(org.jboss.tools.openshift.core.connection.Connection) Collection(java.util.Collection) ImportApplicationWizard(org.jboss.tools.openshift.internal.ui.wizard.importapp.ImportApplicationWizard) IProject(com.openshift.restclient.model.IProject) IResource(com.openshift.restclient.model.IResource)

Example 4 with IResource

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

the class ScaleDeploymentHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IDeploymentConfig dc = getDeploymentConfig(getSelectedElement(event, IResourceWrapper.class));
    if (dc == null) {
        IResource resource = ResourceWrapperUtils.getResource(UIUtils.getFirstElement(HandlerUtil.getCurrentSelection(event)));
        return OpenShiftUIActivator.statusFactory().errorStatus(NLS.bind("Could not scale {0}: Could not find deployment config", resource == null ? "" : resource.getName()));
    }
    scaleUsing(event, dc, dc.getName());
    return null;
}
Also used : IResourceWrapper(org.jboss.tools.openshift.internal.ui.models.IResourceWrapper) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IResource(com.openshift.restclient.model.IResource)

Example 5 with IResource

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

the class OpenInWebConsoleHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    ISelection currentSelection = UIUtils.getCurrentSelection(event);
    IResource resource = UIUtils.getFirstElement(currentSelection, IResource.class);
    Connection connection = null;
    if (resource == null) {
        connection = UIUtils.getFirstElement(currentSelection, Connection.class);
    } else {
        connection = ConnectionsRegistryUtil.safeGetConnectionFor(resource);
    }
    String msg;
    if (connection == null) {
        msg = "Could not find an OpenShift connection to open a console for";
    } else {
        String url = getWebConsoleUrl(connection, resource);
        if (!StringUtils.isEmpty(url)) {
            new BrowserUtility().checkedCreateExternalBrowser(url, OpenShiftUIActivator.PLUGIN_ID, OpenShiftUIActivator.getDefault().getLog());
            return Status.OK_STATUS;
        }
        msg = NLS.bind("Could not determine the url for the web console on {0}", connection.getHost());
    }
    MessageDialog.openWarning(HandlerUtil.getActiveShell(event), "No Web Console Url", msg);
    return new Status(IStatus.WARNING, OpenShiftUIActivator.PLUGIN_ID, msg);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ISelection(org.eclipse.jface.viewers.ISelection) Connection(org.jboss.tools.openshift.core.connection.Connection) BrowserUtility(org.jboss.tools.foundation.ui.util.BrowserUtility) 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