Search in sources :

Example 16 with IResource

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

the class ServiceResourceMapper method getRelatedBuilds.

private static Collection<IBuild> getRelatedBuilds(Collection<IResource> resources, Collection<String> dcImageRefs, Collection<IBuildConfig> buildConfigs) {
    Collection<IBuild> result = new HashSet<>();
    Collection<String> bcNames = buildConfigs.stream().map(bc -> bc.getName()).collect(Collectors.toSet());
    resources.forEach(r -> {
        if (r instanceof IBuild) {
            IBuild build = (IBuild) r;
            if (bcNames.contains(r.getLabels().get(OpenShiftAPIAnnotations.BUILD_CONFIG_NAME)) || dcImageRefs.contains(imageRef(build))) {
                result.add((IBuild) r);
            }
        }
    });
    return result;
}
Also used : IResource(com.openshift.restclient.model.IResource) ResourceKind(com.openshift.restclient.ResourceKind) IBuildConfig(com.openshift.restclient.model.IBuildConfig) Collection(java.util.Collection) IBuild(com.openshift.restclient.model.IBuild) ResourceUtils(org.jboss.tools.openshift.internal.core.util.ResourceUtils) ResourceUtils.imageRef(org.jboss.tools.openshift.internal.core.util.ResourceUtils.imageRef) IDeploymentImageChangeTrigger(com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) HashSet(java.util.HashSet) IPod(com.openshift.restclient.model.IPod) OpenShiftAPIAnnotations(org.jboss.tools.openshift.core.OpenShiftAPIAnnotations) IRoute(com.openshift.restclient.model.route.IRoute) DeploymentTriggerType(com.openshift.restclient.model.deploy.DeploymentTriggerType) Collections(java.util.Collections) IReplicationController(com.openshift.restclient.model.IReplicationController) IService(com.openshift.restclient.model.IService) IBuild(com.openshift.restclient.model.IBuild) HashSet(java.util.HashSet)

Example 17 with IResource

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

the class DeployImageJob method generateResources.

private Map<String, IResource> generateResources(final Connection connection, final String name) {
    final IResourceFactory factory = connection.getResourceFactory();
    final IProject project = parameters.getProject();
    DockerImageURI sourceImage = getSourceImage();
    Map<String, IResource> resources = new HashMap<>(4);
    IImageStream is = stubImageStream(factory, name, project, sourceImage);
    if (is != null && StringUtils.isBlank(is.getResourceVersion())) {
        resources.put(ResourceKind.IMAGE_STREAM, is);
    }
    resources.put(ResourceKind.SERVICE, stubService(factory, name, SELECTOR_KEY, name));
    if (parameters.isAddRoute()) {
        resources.put(ResourceKind.ROUTE, stubRoute(factory, name, resources.get(ResourceKind.SERVICE).getName()));
    }
    resources.put(ResourceKind.DEPLOYMENT_CONFIG, stubDeploymentConfig(factory, name, sourceImage, is));
    addToGeneratedResources(resources, connection, name, project);
    for (IResource resource : resources.values()) {
        addLabelsToResource(resource);
        resource.setAnnotation(OpenShiftAPIAnnotations.GENERATED_BY, JBOSSTOOLS_OPENSHIFT);
    }
    return resources;
}
Also used : DockerImageURI(com.openshift.restclient.images.DockerImageURI) HashMap(java.util.HashMap) IImageStream(com.openshift.restclient.model.IImageStream) IResourceFactory(com.openshift.restclient.IResourceFactory) IProject(com.openshift.restclient.model.IProject) IResource(com.openshift.restclient.model.IResource)

Example 18 with IResource

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

the class ConnectionWrapper method startLoadJob.

void startLoadJob(ProjectWrapper projectWrapper, IExceptionHandler handler) {
    new Job(NLS.bind("Loading OpenShift project {0}...", projectWrapper.getWrapped().getName())) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                IProject project = projectWrapper.getWrapped();
                IOpenShiftConnection connection = projectWrapper.getParent().getWrapped();
                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.initWithResources(resources);
                projectWrapper.fireChanged();
            } catch (OperationCanceledException e) {
                projectWrapper.setLoadingState(LoadingState.LOAD_STOPPED);
            } catch (Throwable e) {
                projectWrapper.setLoadingState(LoadingState.LOAD_STOPPED);
                handler.handleException(e);
            }
            return Status.OK_STATUS;
        }
    }.schedule();
}
Also used : IResource(com.openshift.restclient.model.IResource) ResourceKind(com.openshift.restclient.ResourceKind) Job(org.eclipse.core.runtime.jobs.Job) NLS(org.eclipse.osgi.util.NLS) Collection(java.util.Collection) ConnectionProperties(org.jboss.tools.openshift.core.connection.ConnectionProperties) ResourceUtils(org.jboss.tools.openshift.internal.core.util.ResourceUtils) Status(org.eclipse.core.runtime.Status) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) IProject(com.openshift.restclient.model.IProject) ArrayList(java.util.ArrayList) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IOpenShiftConnection(org.jboss.tools.openshift.core.connection.IOpenShiftConnection) HashSet(java.util.HashSet) List(java.util.List) IStatus(org.eclipse.core.runtime.IStatus) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) WatchManager(org.jboss.tools.openshift.internal.core.WatchManager) Map(java.util.Map) Collections(java.util.Collections) OpenShiftUIActivator(org.jboss.tools.openshift.internal.ui.OpenShiftUIActivator) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) IOpenShiftConnection(org.jboss.tools.openshift.core.connection.IOpenShiftConnection) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) Collection(java.util.Collection) Job(org.eclipse.core.runtime.jobs.Job) IProject(com.openshift.restclient.model.IProject)

Example 19 with IResource

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

the class ResourceCreationJobUtils method createErrorStatusForExistingResources.

@SuppressWarnings("serial")
public static IStatus createErrorStatusForExistingResources(Collection<IResource> resources) {
    final StringBuilder b = new StringBuilder("\nThe following resource names already exist:\n");
    for (IResource r : resources) {
        b.append("\n\"").append(r.getName()).append("\" ").append(r.getKind());
    }
    b.append("\n\nYou need to use different names or create this application in a different OpenShift project.");
    String message = String.valueOf(resources.size()) + " resource name collisions found. ";
    return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID, message, new Throwable() {

        @Override
        public String getMessage() {
            return b.toString();
        }
    });
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IResource(com.openshift.restclient.model.IResource)

Example 20 with IResource

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

the class StartBuildHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = UIUtils.getCurrentSelection(event);
    IResource buildAble = UIUtils.getFirstElement(selection, IResource.class);
    if (buildAble == null || buildAble.getCapability(IBuildTriggerable.class) == null) {
        MessageDialog.openInformation(HandlerUtil.getActiveShell(event), "Trigger Build", "A build or build config must be selected in order to trigger a build.");
        return null;
    }
    new StartBuildJob(buildAble).schedule();
    return null;
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) StartBuildJob(org.jboss.tools.openshift.internal.ui.job.StartBuildJob) 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