use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.
the class ImportApplicationHandler method execute.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
ISelection currentSelection = UIUtils.getCurrentSelection(event);
IBuildConfig buildConfig = UIUtils.getFirstElement(currentSelection, IBuildConfig.class);
Map<IProject, Collection<IBuildConfig>> projectsAndBuildConfigs = null;
IProject project = null;
Collection<IBuildConfig> buildConfigs = null;
if (buildConfig == null) {
IResource resource = UIUtils.getFirstElement(currentSelection, IResource.class);
if (resource != null) {
project = resource.getProject();
}
if (project != null) {
buildConfigs = project.getResources(ResourceKind.BUILD_CONFIG);
}
} else {
project = buildConfig.getProject();
buildConfigs = Collections.singleton(buildConfig);
}
if (project != null) {
if (buildConfigs == null || buildConfigs.isEmpty()) {
MessageDialog.openWarning(HandlerUtil.getActiveShell(event), NO_BUILD_CONFIG_MSG, NO_BUILD_CONFIG_MSG);
return OpenShiftUIActivator.statusFactory().cancelStatus(NO_BUILD_CONFIG_MSG);
}
projectsAndBuildConfigs = Collections.singletonMap(project, buildConfigs);
}
if (projectsAndBuildConfigs == null) {
ImportApplicationWizard wizard = new ImportApplicationWizard();
Connection connection = UIUtils.getFirstElement(currentSelection, Connection.class);
wizard.setConnection(connection);
WizardUtils.openWizardDialog(wizard, HandlerUtil.getActiveShell(event));
} else {
WizardUtils.openWizardDialog(new ImportApplicationWizard(projectsAndBuildConfigs), HandlerUtil.getActiveShell(event));
}
return Status.OK_STATUS;
}
use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.
the class NewProjectHandler method execute.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
Connection connection = UIUtils.getFirstElement(selection, Connection.class);
if (connection == null) {
IProject project = UIUtils.getFirstElement(selection, IProject.class);
if (project != null) {
connection = ConnectionsRegistryUtil.getConnectionFor(project);
}
}
if (connection == null) {
// $NON-NLS-1$
return OpenShiftUIActivator.statusFactory().cancelStatus("No connection selected");
}
openNewProjectDialog(connection, HandlerUtil.getActiveShell(event));
return null;
}
use of com.openshift.restclient.model.IProject 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.IProject in project jbosstools-openshift by jbosstools.
the class ServerResourceViewModelWithServiceTest method shouldReturnNewServiceItemsIfLoadResourcesWithConnection.
@Test
public void shouldReturnNewServiceItemsIfLoadResourcesWithConnection() {
// given
List<ObservableTreeItem> serviceItems = new ArrayList<>(model.getResourceItems());
Connection connection = ResourceMocks.createConnection("http://localhost:8080", "dev@42.org");
IProject project = ResourceMocks.createResource(IProject.class, ResourceKind.PROJECT);
when(connection.getResources(ResourceKind.PROJECT)).thenReturn(Collections.singletonList(project));
IService service = ResourceMocks.createResource(IService.class, ResourceKind.SERVICE);
when(project.getResources(ResourceKind.SERVICE)).thenReturn(Collections.singletonList(service));
// when
model.loadResources(connection);
// then
List<ObservableTreeItem> newServiceItems = model.getResourceItems();
assertThat(newServiceItems).isNotEqualTo(serviceItems);
}
use of com.openshift.restclient.model.IProject 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);
}
}
Aggregations