use of com.openshift.restclient.model.IResource in project jbosstools-openshift by jbosstools.
the class ServiceResourceMapper method getRelatedBuilds.
private static Collection<IBuild> getRelatedBuilds(Collection<IResource> resources, Collection<String> dcImageRefs, Collection<IBuildConfig> buildConfigs) {
Collection<IBuild> result = new HashSet<>();
Collection<String> bcNames = buildConfigs.stream().map(bc -> bc.getName()).collect(Collectors.toSet());
resources.forEach(r -> {
if (r instanceof IBuild) {
IBuild build = (IBuild) r;
if (bcNames.contains(r.getLabels().get(OpenShiftAPIAnnotations.BUILD_CONFIG_NAME)) || dcImageRefs.contains(imageRef(build))) {
result.add((IBuild) r);
}
}
});
return result;
}
use of com.openshift.restclient.model.IResource in project jbosstools-openshift by jbosstools.
the class DeployImageJob method generateResources.
private Map<String, IResource> generateResources(final Connection connection, final String name) {
final IResourceFactory factory = connection.getResourceFactory();
final IProject project = parameters.getProject();
DockerImageURI sourceImage = getSourceImage();
Map<String, IResource> resources = new HashMap<>(4);
IImageStream is = stubImageStream(factory, name, project, sourceImage);
if (is != null && StringUtils.isBlank(is.getResourceVersion())) {
resources.put(ResourceKind.IMAGE_STREAM, is);
}
resources.put(ResourceKind.SERVICE, stubService(factory, name, SELECTOR_KEY, name));
if (parameters.isAddRoute()) {
resources.put(ResourceKind.ROUTE, stubRoute(factory, name, resources.get(ResourceKind.SERVICE).getName()));
}
resources.put(ResourceKind.DEPLOYMENT_CONFIG, stubDeploymentConfig(factory, name, sourceImage, is));
addToGeneratedResources(resources, connection, name, project);
for (IResource resource : resources.values()) {
addLabelsToResource(resource);
resource.setAnnotation(OpenShiftAPIAnnotations.GENERATED_BY, JBOSSTOOLS_OPENSHIFT);
}
return resources;
}
use of com.openshift.restclient.model.IResource in project jbosstools-openshift by jbosstools.
the class ConnectionWrapper method startLoadJob.
void startLoadJob(ProjectWrapper projectWrapper, IExceptionHandler handler) {
new Job(NLS.bind("Loading OpenShift project {0}...", projectWrapper.getWrapped().getName())) {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
IProject project = projectWrapper.getWrapped();
IOpenShiftConnection connection = projectWrapper.getParent().getWrapped();
WatchManager.getInstance().startWatch(project, connection);
Collection<IResource> resources = new HashSet<>();
for (String kind : RESOURCE_KINDS) {
resources.addAll(getWrapped().getResources(kind, project.getNamespaceName()));
}
resources.forEach(r -> resourceCache.add(r));
projectWrapper.initWithResources(resources);
projectWrapper.fireChanged();
} catch (OperationCanceledException e) {
projectWrapper.setLoadingState(LoadingState.LOAD_STOPPED);
} catch (Throwable e) {
projectWrapper.setLoadingState(LoadingState.LOAD_STOPPED);
handler.handleException(e);
}
return Status.OK_STATUS;
}
}.schedule();
}
use of com.openshift.restclient.model.IResource in project jbosstools-openshift by jbosstools.
the class ResourceCreationJobUtils method createErrorStatusForExistingResources.
@SuppressWarnings("serial")
public static IStatus createErrorStatusForExistingResources(Collection<IResource> resources) {
final StringBuilder b = new StringBuilder("\nThe following resource names already exist:\n");
for (IResource r : resources) {
b.append("\n\"").append(r.getName()).append("\" ").append(r.getKind());
}
b.append("\n\nYou need to use different names or create this application in a different OpenShift project.");
String message = String.valueOf(resources.size()) + " resource name collisions found. ";
return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID, message, new Throwable() {
@Override
public String getMessage() {
return b.toString();
}
});
}
use of com.openshift.restclient.model.IResource in project jbosstools-openshift by jbosstools.
the class StartBuildHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = UIUtils.getCurrentSelection(event);
IResource buildAble = UIUtils.getFirstElement(selection, IResource.class);
if (buildAble == null || buildAble.getCapability(IBuildTriggerable.class) == null) {
MessageDialog.openInformation(HandlerUtil.getActiveShell(event), "Trigger Build", "A build or build config must be selected in order to trigger a build.");
return null;
}
new StartBuildJob(buildAble).schedule();
return null;
}
Aggregations