Search in sources :

Example 91 with Connection

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

the class ServerAdapterHandler method getOpenShiftServer.

/**
 * Finds the OpenShift server corresponding to the selection or prompts the
 * user to create one.
 *
 * @param resource
 *            the selected OpenShift {@link IResource}
 *
 * @return the matching OpenShift {@link IServer} or <code>null</code> if
 *         none was found or user cancelled the creation operation.
 */
private IServer getOpenShiftServer(final IResource resource) {
    if (resource == null) {
        return null;
    }
    IResource source = null;
    IRoute route = null;
    if (resource instanceof IService) {
        source = (IService) resource;
    } else if (resource instanceof IRoute) {
        route = (IRoute) resource;
        final IRoute localRoute = route;
        source = (IService) route.getProject().getResources(ResourceKind.SERVICE).stream().filter(s -> ResourceUtils.areRelated(localRoute, (IService) s)).findFirst().orElseGet(() -> null);
    } else if (resource instanceof IReplicationController) {
        source = resource;
    } else if (resource instanceof IPod) {
        final Collection<IService> services = ResourceUtils.getServicesFor((IPod) resource, resource.getProject().getResources(ResourceKind.SERVICE));
        if (!services.isEmpty()) {
            source = services.iterator().next();
        } else {
            source = ResourceUtils.getDeploymentConfigOrReplicationControllerFor((IPod) resource);
        }
    }
    if (source != null) {
        final Connection connection = ConnectionsRegistryUtil.safeGetConnectionFor(source);
        return openOrCreateServerAdapter(source, route, connection);
    }
    return null;
}
Also used : ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) ServerSettingsWizard(org.jboss.tools.openshift.internal.ui.server.ServerSettingsWizard) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ResourceUtils(org.jboss.tools.openshift.internal.core.util.ResourceUtils) OpenShiftResourceUniqueId(org.jboss.tools.openshift.core.util.OpenShiftResourceUniqueId) CoreException(org.eclipse.core.runtime.CoreException) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) HandlerUtil(org.eclipse.ui.handlers.HandlerUtil) IPod(com.openshift.restclient.model.IPod) UIUtils(org.jboss.tools.openshift.internal.common.ui.utils.UIUtils) PartInitException(org.eclipse.ui.PartInitException) CommonNavigator(org.eclipse.ui.navigator.CommonNavigator) OpenShiftUIActivator(org.jboss.tools.openshift.internal.ui.OpenShiftUIActivator) IService(com.openshift.restclient.model.IService) IResource(com.openshift.restclient.model.IResource) ResourceKind(com.openshift.restclient.ResourceKind) NLS(org.eclipse.osgi.util.NLS) Collection(java.util.Collection) IServer(org.eclipse.wst.server.core.IServer) OpenShiftServerUtils(org.jboss.tools.openshift.core.server.OpenShiftServerUtils) ExecutionException(org.eclipse.core.commands.ExecutionException) Display(org.eclipse.swt.widgets.Display) Connection(org.jboss.tools.openshift.core.connection.Connection) WizardUtils(org.jboss.tools.common.ui.WizardUtils) IRoute(com.openshift.restclient.model.route.IRoute) ConnectionsRegistryUtil(org.jboss.tools.openshift.core.connection.ConnectionsRegistryUtil) ISelection(org.eclipse.jface.viewers.ISelection) AbstractHandler(org.eclipse.core.commands.AbstractHandler) IServerWorkingCopy(org.eclipse.wst.server.core.IServerWorkingCopy) IReplicationController(com.openshift.restclient.model.IReplicationController) Connection(org.jboss.tools.openshift.core.connection.Connection) IRoute(com.openshift.restclient.model.route.IRoute) Collection(java.util.Collection) IResource(com.openshift.restclient.model.IResource) IService(com.openshift.restclient.model.IService) IReplicationController(com.openshift.restclient.model.IReplicationController) IPod(com.openshift.restclient.model.IPod)

Example 92 with Connection

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

the class DeployImageJob method doRun.

@Override
protected IStatus doRun(IProgressMonitor monitor) {
    try {
        final Connection connection = parameters.getConnection();
        final String name = parameters.getResourceName();
        if (updateTriggerIfUpdate(connection, parameters.getProject().getName(), name)) {
            return Status.OK_STATUS;
        }
        Map<String, IResource> resources = generateResources(connection, name);
        // validate
        Collection<IResource> existing = findExistingResources(connection, resources.values());
        // TODO may need to disregard if only error is the imagestream - TBD
        if (!existing.isEmpty()) {
            return createErrorStatusForExistingResources(existing);
        }
        // create
        created = createResources(connection, resources.values());
    } catch (Exception e) {
        String message = NLS.bind("Unable to create resources to deploy image {0}", parameters.getImageName());
        OpenShiftUIActivator.getDefault().getLogger().logError(message, e);
        return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID, message, e);
    }
    return Status.OK_STATUS;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Connection(org.jboss.tools.openshift.core.connection.Connection) IResource(com.openshift.restclient.model.IResource) OpenShiftException(com.openshift.restclient.OpenShiftException) NotFoundException(com.openshift.restclient.NotFoundException)

Example 93 with Connection

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

the class RefreshResourcesJob method doRun.

@Override
protected IStatus doRun(IProgressMonitor monitor) {
    try {
        monitor.beginTask("Refreshing OpenShift resources...", IProgressMonitor.UNKNOWN);
        refreshedResources.clear();
        Collection<IResource> resources = model.getResources();
        if (resources == null || resources.isEmpty())
            return Status.OK_STATUS;
        for (IResource resource : resources) {
            if (ResourceKind.STATUS.equals(resource.getKind())) {
                continue;
            }
            Connection connection = ConnectionsRegistryUtil.safeGetConnectionFor(resource);
            if (connection != null) {
                IResource newValue = ((Connection) connection).refresh(resource);
                IResource oldValue = resourcesAdded ? null : resource;
                refreshedResources.add(newValue);
                ConnectionsRegistrySingleton.getInstance().fireConnectionChanged(connection, ConnectionProperties.PROPERTY_RESOURCE, oldValue, newValue);
            }
        }
    } catch (Exception e) {
        return new Status(Status.ERROR, OpenShiftUIActivator.PLUGIN_ID, "Exception refreshing resources", e);
    } finally {
        monitor.done();
    }
    return Status.OK_STATUS;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) Connection(org.jboss.tools.openshift.core.connection.Connection) IResource(com.openshift.restclient.model.IResource)

Example 94 with Connection

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

the class AbstractProjectPage method getLoadResourcesJobBuilder.

/**
 * Create and configure the list of jobs that need to be performed during
 * resource loading. The base behavior is to load the projects and force project
 * creation if no project exists.
 *
 * @param closeAfter
 *            return parameter if wizard needs to be closed (may be updated)
 * @param closeOnCancel
 *            true if the wizard need to be closed
 * @return the job builder
 */
protected JobChainBuilder getLoadResourcesJobBuilder(final boolean[] closeAfter, final boolean closeOnCancel) {
    JobChainBuilder builder = new JobChainBuilder(new AbstractDelegatingMonitorJob("Loading projects...") {

        @Override
        protected IStatus doRun(IProgressMonitor monitor) {
            try {
                model.loadResources();
            } catch (OpenShiftException e) {
                closeAfter[0] = closeOnCancel;
                String problem = e.getStatus() == null ? e.getMessage() : e.getStatus().getMessage();
                return OpenShiftUIActivator.statusFactory().errorStatus(problem, e);
            }
            return Status.OK_STATUS;
        }
    });
    builder.runWhenSuccessfullyDone(new UIJob("Verifying required project...") {

        @Override
        public IStatus runInUIThread(IProgressMonitor monitor) {
            if (!model.hasProjects()) {
                List<IProject> projects = new ObservableTreeItem2ModelConverter().convert(model.getProjectItems());
                Connection connection = model.getConnection();
                NewProjectWizard newProjectWizard = new NewProjectWizard(connection, projects);
                if (Dialog.CANCEL == WizardUtils.openWizardDialog(newProjectWizard, getShell())) {
                    closeAfter[0] = closeOnCancel;
                    return Status.CANCEL_STATUS;
                } else {
                    model.loadResources();
                    model.setProject(newProjectWizard.getProject());
                }
            }
            return Status.OK_STATUS;
        }
    });
    return builder;
}
Also used : AbstractDelegatingMonitorJob(org.jboss.tools.openshift.internal.common.core.job.AbstractDelegatingMonitorJob) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) OpenShiftException(com.openshift.restclient.OpenShiftException) Connection(org.jboss.tools.openshift.core.connection.Connection) UIJob(org.eclipse.ui.progress.UIJob) ObservableTreeItem2ModelConverter(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter) List(java.util.List) NewProjectWizard(org.jboss.tools.openshift.internal.ui.wizard.project.NewProjectWizard) JobChainBuilder(org.jboss.tools.openshift.internal.common.core.job.JobChainBuilder)

Example 95 with Connection

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

the class NewApplicationWizard method init.

@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
    fromImageModel.setContainer(getContainer());
    if (selection == null || selection.isEmpty()) {
        return;
    }
    org.eclipse.core.resources.IProject selectedProject = UIUtils.getFirstElement(selection, org.eclipse.core.resources.IProject.class);
    model.setEclipseProject(selectedProject);
    Connection connection = UIUtils.getFirstElement(selection, Connection.class);
    if (connection != null) {
        setConnection(connection);
    } else {
        IResource resource = UIUtils.getFirstElement(selection, IResource.class);
        if (resource != null) {
            connection = ConnectionsRegistryUtil.safeGetConnectionFor(resource);
            setConnection(connection);
            model.setProject(resource.getProject());
        }
    }
    if (connection != null) {
        ConnectionsRegistrySingleton.getInstance().setRecent(connection);
    }
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection) 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