use of com.openshift.restclient.model.IResource in project jbosstools-openshift by jbosstools.
the class ServerAdapterHandler method execute.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
final IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
ISelection selection = UIUtils.getCurrentSelection(event);
IResource selectedResource = UIUtils.getFirstElement(selection, IResource.class);
final IServer openShiftServer = getOpenShiftServer(selectedResource);
if (openShiftServer != null) {
openServersView(openShiftServer, workbenchWindow);
}
return null;
}
use of com.openshift.restclient.model.IResource in project jbosstools-openshift by jbosstools.
the class OpenShiftServiceRequirement method cleanUp.
@Override
public void cleanUp() {
if (serviceSpec.cleanup()) {
String projectName = TestUtils.getValueOrDefault(serviceSpec.project(), DatastoreOS3.TEST_PROJECT);
final IProject project = OpenShift3NativeResourceUtils.getProject(projectName, connection);
IProjectTemplateProcessing capability = project.getCapability(IProjectTemplateProcessing.class);
ITemplate processed = capability.process(template);
for (IResource resource : processed.getObjects()) {
IResource res = connection.getResource(resource.getKind(), projectName, resource.getName());
try {
connection.deleteResource(res);
} catch (OpenShiftException ex) {
LOGGER.error("Unable to remove " + res.getKind() + " named " + res.getName());
LOGGER.error(StackTraceUtils.stackTraceToString(ex));
}
}
cleanResources(connection, ResourceKind.BUILD, project, template);
cleanResources(connection, ResourceKind.REPLICATION_CONTROLLER, project, template);
cleanResources(connection, ResourceKind.POD, project, template);
new WaitWhile(new AbstractWaitCondition() {
@Override
public boolean test() {
for (IResource resource : project.getResources(ResourceKind.POD)) {
if (resource.getName().startsWith(template.getName())) {
return true;
}
}
return false;
}
@Override
public String description() {
return "at least one application pod is running";
}
}, TimePeriod.LONG);
new OpenShiftExplorerView().getOpenShift3Connection(connection).refresh();
}
}
use of com.openshift.restclient.model.IResource in project jbosstools-openshift by jbosstools.
the class OpenShiftServiceRequirement method waitForResources.
private void waitForResources(final String serviceName, final String projectName, final IService service) {
new WaitUntil(new ServicePodsExist(serviceName, projectName, connection), TimePeriod.VERY_LONG);
new WaitUntil(new ResourceExists(ResourceKind.REPLICATION_CONTROLLER, new BaseMatcher<List<IResource>>() {
@Override
public boolean matches(Object item) {
if (!(item instanceof List)) {
return false;
}
@SuppressWarnings("unchecked") List<IReplicationController> resources = (List<IReplicationController>) item;
if (resources.isEmpty()) {
return false;
}
return ResourceUtils.getReplicationControllerFor(service, resources) != null;
}
@Override
public void describeTo(Description description) {
}
}, projectName, connection), TIMEPERIOD_WAIT_FOR_BUILD);
}
use of com.openshift.restclient.model.IResource in project jbosstools-openshift by jbosstools.
the class ServerResourceViewModelWithReplicationControllerTest method shouldReturnNewSelectedDeploymentConfigIfLoadResourcesWithConnection.
@Test
public void shouldReturnNewSelectedDeploymentConfigIfLoadResourcesWithConnection() {
// given
IResource selectedDeploymentConfig = model.getResource();
Connection connection = ResourceMocks.createConnection("https://localhost:8181", "ops@42.org");
ConnectionsRegistrySingleton.getInstance().add(connection);
try {
IProject project = ResourceMocks.createResource(IProject.class, ResourceKind.PROJECT);
when(connection.getResources(ResourceKind.PROJECT)).thenReturn(Collections.singletonList(project));
IReplicationController replicationController = ResourceMocks.createResource(IReplicationController.class, ResourceKind.REPLICATION_CONTROLLER);
when(project.getResources(ResourceKind.REPLICATION_CONTROLLER)).thenReturn(Collections.singletonList(replicationController));
// when
model.loadResources(connection);
// then
IResource newSelectedDeploymentConfig = model.getResource();
assertThat(selectedDeploymentConfig).isNotEqualTo(newSelectedDeploymentConfig);
} finally {
ConnectionsRegistrySingleton.getInstance().remove(connection);
}
}
use of com.openshift.restclient.model.IResource in project jbosstools-openshift by jbosstools.
the class ServerResourceViewModelWithReplicationControllerTest method shouldReturnNullServiceIfNoConnectionIsSet.
@Test
public void shouldReturnNullServiceIfNoConnectionIsSet() {
// given
ServerResourceViewModel model = new ServerResourceViewModel(null);
model.loadResources();
// when
IResource resource = model.getResource();
// then
assertThat(resource).isNull();
}
Aggregations