Search in sources :

Example 6 with IReplicationController

use of com.openshift.restclient.model.IReplicationController 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 IReplicationController

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

the class OpenShiftExplorerLabelProviderTest method getStyledTextForAReplicationController.

@Test
public void getStyledTextForAReplicationController() {
    IReplicationController rc = givenAResource(IReplicationController.class, ResourceKind.REPLICATION_CONTROLLER);
    Map<String, String> selector = new HashMap<>();
    selector.put("foo", "bar");
    when(rc.getReplicaSelector()).thenReturn(selector);
    assertEquals(String.format("%s selector: foo=bar", rc.getName()), provider.getStyledText(rc).getString());
}
Also used : HashMap(java.util.HashMap) StyledString(org.eclipse.jface.viewers.StyledString) IReplicationController(com.openshift.restclient.model.IReplicationController) Test(org.junit.Test)

Example 8 with IReplicationController

use of com.openshift.restclient.model.IReplicationController 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 IReplicationController

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

the class OpenshiftJMXConnectionProvider method getJolokiaPort.

protected String getJolokiaPort(IPod pod) {
    String port = "8778";
    IReplicationController rc = ResourceUtils.getDeploymentConfigOrReplicationControllerFor(pod);
    if (rc != null) {
        Optional<IEnvironmentVariable> envPort = rc.getEnvironmentVariables().stream().filter(env -> env.getName().equals("AB_JOLOKIA_PORT")).findFirst();
        if (envPort.isPresent()) {
            port = envPort.get().getValue();
        }
    }
    return port;
}
Also used : IResource(com.openshift.restclient.model.IResource) ResourceKind(com.openshift.restclient.ResourceKind) MalformedURLException(java.net.MalformedURLException) URL(java.net.URL) IServer(org.eclipse.wst.server.core.IServer) IConnectionProvider(org.jboss.tools.jmx.core.IConnectionProvider) JolokiaConnectionWrapper(org.jboss.tools.jmx.jolokia.JolokiaConnectionWrapper) ResourceUtils(org.jboss.tools.openshift.internal.core.util.ResourceUtils) HashMap(java.util.HashMap) AbstractJBossJMXConnectionProvider(org.jboss.ide.eclipse.as.jmx.integration.AbstractJBossJMXConnectionProvider) OpenShiftCoreActivator(org.jboss.tools.openshift.internal.core.OpenShiftCoreActivator) Connection(org.jboss.tools.openshift.core.connection.Connection) ExtensionManager(org.jboss.tools.jmx.core.ExtensionManager) IPod(com.openshift.restclient.model.IPod) List(java.util.List) IEnvironmentVariable(com.openshift.restclient.model.IEnvironmentVariable) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) Map(java.util.Map) IConnectionWrapper(org.jboss.tools.jmx.core.IConnectionWrapper) Optional(java.util.Optional) IReplicationController(com.openshift.restclient.model.IReplicationController) IEnvironmentVariable(com.openshift.restclient.model.IEnvironmentVariable) IReplicationController(com.openshift.restclient.model.IReplicationController)

Example 10 with IReplicationController

use of com.openshift.restclient.model.IReplicationController 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

IReplicationController (com.openshift.restclient.model.IReplicationController)21 IResource (com.openshift.restclient.model.IResource)9 Connection (org.jboss.tools.openshift.core.connection.Connection)7 Test (org.junit.Test)7 IPod (com.openshift.restclient.model.IPod)6 ResourceKind (com.openshift.restclient.ResourceKind)5 IDeploymentConfig (com.openshift.restclient.model.IDeploymentConfig)5 IService (com.openshift.restclient.model.IService)5 List (java.util.List)5 Collection (java.util.Collection)4 HashMap (java.util.HashMap)4 IConnection (org.jboss.tools.openshift.common.core.connection.IConnection)4 IProject (com.openshift.restclient.model.IProject)3 IRoute (com.openshift.restclient.model.route.IRoute)3 Collections (java.util.Collections)3 Map (java.util.Map)3 CoreException (org.eclipse.core.runtime.CoreException)3 CapabilityVisitor (com.openshift.restclient.capability.CapabilityVisitor)2 ITags (com.openshift.restclient.capability.resources.ITags)2 IBuild (com.openshift.restclient.model.IBuild)2