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