Search in sources :

Example 6 with IService

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

the class ResourceUtils method getDeploymentConfigFor.

private static IDeploymentConfig getDeploymentConfigFor(IService service, Connection connection) {
    if (service == null) {
        return null;
    }
    String dcName = getDeploymentConfigNameFor(service);
    if (dcName != null) {
        return getDeploymentConfigByName(dcName, service, connection);
    } else {
        String namespace = service.getNamespaceName();
        IReplicationController rc = getReplicationControllerFor(service, connection.getResources(ResourceKind.REPLICATION_CONTROLLER, namespace));
        if (rc == null) {
            return null;
        }
        List<IPod> allPods = connection.getResources(ResourceKind.POD, namespace);
        List<IPod> pods = allPods.stream().filter(pod -> areRelated((IPod) pod, rc)).collect(Collectors.toList());
        if (CollectionUtils.isEmpty(pods)) {
            return null;
        }
        List<IDeploymentConfig> dcs = connection.getResources(ResourceKind.DEPLOYMENT_CONFIG, namespace);
        return dcs.stream().filter(dc -> areRelated((IService) service, (IDeploymentConfig) dc, pods)).findFirst().orElse(null);
    }
}
Also used : Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) IBuildConfig(com.openshift.restclient.model.IBuildConfig) KeyValueFilterFactory(org.jboss.tools.openshift.internal.common.core.util.KeyValueFilterFactory) URISyntaxException(java.net.URISyntaxException) CoreException(org.eclipse.core.runtime.CoreException) IDeploymentImageChangeTrigger(com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger) IProject(com.openshift.restclient.model.IProject) HashSet(java.util.HashSet) IPod(com.openshift.restclient.model.IPod) IClientCapability(com.openshift.restclient.capability.resources.IClientCapability) CollectionUtils(org.apache.commons.collections.CollectionUtils) EGitUtils(org.jboss.tools.openshift.egit.core.EGitUtils) Map(java.util.Map) KeyValueFilter(org.jboss.tools.openshift.internal.common.core.util.KeyValueFilterFactory.KeyValueFilter) URIish(org.eclipse.jgit.transport.URIish) OpenShiftResourceSelectors(org.jboss.tools.openshift.core.OpenShiftResourceSelectors) ITags(com.openshift.restclient.capability.resources.ITags) IImageStreamImport(com.openshift.restclient.model.image.IImageStreamImport) StatusFactory(org.jboss.tools.foundation.core.plugin.log.StatusFactory) IService(com.openshift.restclient.model.IService) IResource(com.openshift.restclient.model.IResource) ResourceKind(com.openshift.restclient.ResourceKind) MapUtils(org.apache.commons.collections.MapUtils) NLS(org.eclipse.osgi.util.NLS) Collection(java.util.Collection) IBuild(com.openshift.restclient.model.IBuild) Set(java.util.Set) OpenShiftCoreActivator(org.jboss.tools.openshift.internal.core.OpenShiftCoreActivator) Collectors(java.util.stream.Collectors) IObjectReference(com.openshift.restclient.model.IObjectReference) Connection(org.jboss.tools.openshift.core.connection.Connection) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) OpenShiftAPIAnnotations(org.jboss.tools.openshift.core.OpenShiftAPIAnnotations) IClient(com.openshift.restclient.IClient) CapabilityVisitor(com.openshift.restclient.capability.CapabilityVisitor) IRoute(com.openshift.restclient.model.route.IRoute) Optional(java.util.Optional) ModelNode(org.jboss.dmr.ModelNode) Comparator(java.util.Comparator) Collections(java.util.Collections) IReplicationController(com.openshift.restclient.model.IReplicationController) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IReplicationController(com.openshift.restclient.model.IReplicationController) IPod(com.openshift.restclient.model.IPod) IService(com.openshift.restclient.model.IService)

Example 7 with IService

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

the class DeployImageJob method stubService.

private IService stubService(IResourceFactory factory, String name, String selectorKey, String selectorValue) {
    IService service = factory.stub(ResourceKind.SERVICE, name, parameters.getProject().getName());
    service.setPorts(parameters.getServicePorts());
    service.setSelector(selectorKey, selectorValue);
    return service;
}
Also used : IService(com.openshift.restclient.model.IService)

Example 8 with IService

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

the class ResourcesViewLabelProvider method update.

@Override
public void update(ViewerCell cell) {
    Object element = cell.getElement();
    if (!(element instanceof ObservableTreeItem)) {
        return;
    }
    if (!(((ObservableTreeItem) element).getModel() instanceof IResource)) {
        return;
    }
    IResource resource = (IResource) ((ObservableTreeItem) element).getModel();
    StyledString text = new StyledString();
    if (resource instanceof com.openshift.restclient.model.IProject) {
        createProjectLabel(text, (com.openshift.restclient.model.IProject) resource);
    } else if (resource instanceof IService) {
        createServiceLabel(text, (IService) resource);
    } else if (resource instanceof IReplicationController) {
        createReplicationControllerLabel(text, (IReplicationController) resource);
    }
    cell.setText(text.toString());
    cell.setStyleRanges(text.getStyleRanges());
    super.update(cell);
}
Also used : StyledString(org.eclipse.jface.viewers.StyledString) ObservableTreeItem(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem) IResource(com.openshift.restclient.model.IResource) IService(com.openshift.restclient.model.IService) IReplicationController(com.openshift.restclient.model.IReplicationController)

Example 9 with IService

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

the class ProjectTreeSorterTest method mockService.

private IService mockService(String name, String toString) {
    IService service = Mockito.mock(IService.class);
    when(service.getKind()).thenReturn(ResourceKind.SERVICE);
    when(service.getName()).thenReturn(name);
    when(service.toString()).thenReturn(toString);
    return service;
}
Also used : IService(com.openshift.restclient.model.IService)

Example 10 with IService

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

the class ResourceUtilsTest method testGetReplicationControllerForService.

@Test
public void testGetReplicationControllerForService() {
    // given
    IReplicationController rc1 = ResourceMocks.createResource(IReplicationController.class, ResourceKind.REPLICATION_CONTROLLER, r -> doReturn(new HashMap<String, String>() {

        {
            put("name", "42");
            put("bookaroobanzai", "84");
        }
    }).when(r).getTemplateLabels());
    IReplicationController rc2 = ResourceMocks.createResource(IReplicationController.class, ResourceKind.REPLICATION_CONTROLLER, r -> {
        doReturn(new HashMap<String, String>() {

            {
                put("name", "42");
                put("deploymentConfig", "84");
                put("foo", "bar");
            }
        }).when(r).getTemplateLabels();
    });
    IService srv1 = ResourceMocks.createResource(IService.class, ResourceKind.SERVICE, r -> doReturn(new HashMap<String, String>() {

        {
            put("name", "42");
            put("deploymentConfig", "84");
        }
    }).when(r).getSelector());
    // when
    IReplicationController matching = ResourceUtils.getReplicationControllerFor(srv1, Arrays.asList(rc1, rc2));
    // then
    assertThat(matching).isEqualTo(rc2);
}
Also used : HashMap(java.util.HashMap) IReplicationController(com.openshift.restclient.model.IReplicationController) IService(com.openshift.restclient.model.IService) Test(org.junit.Test)

Aggregations

IService (com.openshift.restclient.model.IService)32 Test (org.junit.Test)15 Connection (org.jboss.tools.openshift.core.connection.Connection)10 IResource (com.openshift.restclient.model.IResource)9 IRoute (com.openshift.restclient.model.route.IRoute)8 IDeploymentConfig (com.openshift.restclient.model.IDeploymentConfig)6 IProject (com.openshift.restclient.model.IProject)5 ResourceKind (com.openshift.restclient.ResourceKind)4 IBuildConfig (com.openshift.restclient.model.IBuildConfig)4 IPod (com.openshift.restclient.model.IPod)4 IReplicationController (com.openshift.restclient.model.IReplicationController)4 Collection (java.util.Collection)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)3 CoreException (org.eclipse.core.runtime.CoreException)3 ResourceUtils (org.jboss.tools.openshift.internal.core.util.ResourceUtils)3 IClient (com.openshift.restclient.IClient)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2