Search in sources :

Example 1 with Connection

use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.

the class DockerImageLabels method getInstance.

/**
 * Returns an instance for a given server behaviour and resource. The server
 * behaviour shared data is looked up for a matching instance. If it doesn't
 * exists a new one is created. The docker image metadata is lazyly loaded when
 * data is requested via {@link #getPodPath()}, {@link #getDevmodePortKey()}
 * etc.
 *
 * @param resource
 * @param behaviour
 * @return
 *
 * @see IControllableServerBehavior
 * @see IResource
 */
public static DockerImageLabels getInstance(IResource resource, IControllableServerBehavior behaviour) {
    DockerImageLabels metadata = (DockerImageLabels) behaviour.getSharedData(SHARED_DATA_KEY);
    if (metadata == null || !Objects.equals(resource, metadata.resource)) {
        Connection connection = OpenShiftServerUtils.getConnection(behaviour.getServer());
        metadata = new DockerImageLabels(resource, connection);
        behaviour.putSharedData(SHARED_DATA_KEY, metadata);
    }
    return metadata;
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection)

Example 2 with Connection

use of org.jboss.tools.openshift.core.connection.Connection 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 Connection

use of org.jboss.tools.openshift.core.connection.Connection 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 Connection

use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.

the class ManageEnvironmentVariablesWizard method performFinish.

@Override
public boolean performFinish() {
    new Job("Updating environment variables for deployment config " + dc.getName()) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                List<EnvironmentVariable> vars = model.getEnvironmentVariables();
                boolean modified = false;
                for (EnvironmentVariable var : vars) {
                    if (model.isEnvironmentVariableModified(var)) {
                        modified = true;
                        String value = var.getValue();
                        if (IEnvironmentVariablesPageModel.DELETED.equals(value)) {
                            dc.removeEnvironmentVariable(var.getKey());
                        } else {
                            dc.setEnvironmentVariable(var.getKey(), var.getValue());
                        }
                    }
                }
                if (modified) {
                    Connection conn = ConnectionsRegistryUtil.getConnectionFor(dc);
                    conn.updateResource(dc);
                }
            } catch (Exception e) {
                String message = "Unable to update environment variables for deployment config " + dc.getName();
                OpenShiftUIActivator.getDefault().getLogger().logError(message, e);
                return new Status(Status.ERROR, OpenShiftUIActivator.PLUGIN_ID, message, e);
            }
            return Status.OK_STATUS;
        }
    }.schedule();
    return true;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) Connection(org.jboss.tools.openshift.core.connection.Connection) EnvironmentVariable(org.jboss.tools.openshift.internal.ui.wizard.common.EnvironmentVariable) List(java.util.List) Job(org.eclipse.core.runtime.jobs.Job) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 5 with Connection

use of org.jboss.tools.openshift.core.connection.Connection 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

Connection (org.jboss.tools.openshift.core.connection.Connection)110 Test (org.junit.Test)48 IConnection (org.jboss.tools.openshift.common.core.connection.IConnection)30 IResource (com.openshift.restclient.model.IResource)27 IProject (com.openshift.restclient.model.IProject)18 IService (com.openshift.restclient.model.IService)11 IStatus (org.eclipse.core.runtime.IStatus)11 IDeploymentConfig (com.openshift.restclient.model.IDeploymentConfig)9 Collection (java.util.Collection)8 List (java.util.List)8 ISelection (org.eclipse.jface.viewers.ISelection)8 IPod (com.openshift.restclient.model.IPod)7 ArrayList (java.util.ArrayList)7 CoreException (org.eclipse.core.runtime.CoreException)7 OpenShiftException (com.openshift.restclient.OpenShiftException)6 ResourceKind (com.openshift.restclient.ResourceKind)6 IRoute (com.openshift.restclient.model.route.IRoute)6 MultiValidator (org.eclipse.core.databinding.validation.MultiValidator)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 Status (org.eclipse.core.runtime.Status)6