Search in sources :

Example 81 with IResource

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

the class ConnectionWrapper method refresh.

void refresh(ProjectWrapper projectWrapper) {
    resourceCache.flush(projectWrapper.getWrapped().getNamespaceName());
    IProject project = projectWrapper.getWrapped();
    IOpenShiftConnection connection = projectWrapper.getParent().getWrapped();
    WatchManager.getInstance().stopWatch(project, connection);
    WatchManager.getInstance().startWatch(project, connection);
    Collection<IResource> resources = new HashSet<>();
    for (String kind : RESOURCE_KINDS) {
        resources.addAll(getWrapped().getResources(kind, project.getNamespaceName()));
    }
    resources.forEach(r -> resourceCache.add(r));
    projectWrapper.updateWithResources(resources);
}
Also used : IOpenShiftConnection(org.jboss.tools.openshift.core.connection.IOpenShiftConnection) IProject(com.openshift.restclient.model.IProject) IResource(com.openshift.restclient.model.IResource) HashSet(java.util.HashSet)

Example 82 with IResource

use of com.openshift.restclient.model.IResource 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 83 with IResource

use of com.openshift.restclient.model.IResource 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 84 with IResource

use of com.openshift.restclient.model.IResource 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 85 with IResource

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

the class ResourceCreationJobUtils method findExistingResources.

/*
	 * MAYBE this should be part of Connection in an exists method?
	 */
public static Collection<IResource> findExistingResources(Connection connection, Collection<IResource> resources) {
    List<IResource> existing = new ArrayList<>(resources.size());
    for (IResource resource : resources) {
        try {
            IResource found = connection.refresh(resource);
            existing.add(found);
        } catch (OpenShiftException e) {
        // this is expected if the resource is not found
        // @TODO change to NotFoundException of some kind
        }
    }
    return existing;
}
Also used : OpenShiftException(com.openshift.restclient.OpenShiftException) ArrayList(java.util.ArrayList) 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