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);
}
}
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());
}
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);
}
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;
}
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);
}
Aggregations