use of com.openshift.restclient.IResourceFactory 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.IResourceFactory in project jbosstools-openshift by jbosstools.
the class OpenShiftServiceRequirement method fulfill.
@Override
public void fulfill() {
this.connection = ConnectionUtils.getConnectionOrDefault(serviceSpec.connectionURL());
assertNotNull(NLS.bind("No connection for {0} exists", serviceSpec.connectionURL()), connection);
final String projectName = TestUtils.getValueOrDefault(serviceSpec.project(), DatastoreOS3.TEST_PROJECT);
assertTrue(NLS.bind("No project {0} exists on server {1}", projectName, connection.getHost()), OpenShift3NativeResourceUtils.hasProject(projectName, connection));
final String serviceName = serviceSpec.service();
final String templateName = serviceSpec.template();
IResourceFactory factory = new ClientBuilder(connection.getHost()).build().getResourceFactory();
try {
// try if template comes from a URL
URL url = new URL(templateName);
template = factory.create(url.openStream());
} catch (MalformedURLException ex) {
// template is not a URL, try a path to local file instead
if (new File(templateName).exists()) {
try {
template = factory.create(new FileInputStream(templateName));
} catch (FileNotFoundException e) {
throw new RedDeerException("Unable to read local template", e);
}
} else {
// it is not an external template
template = connection.getResource(ResourceKind.TEMPLATE, OpenShiftResources.OPENSHIFT_PROJECT, templateName);
}
} catch (IOException ex) {
throw new RedDeerException("Unable to read template from URL", ex);
}
assertNotNull(template);
this.service = getOrCreateService(projectName, serviceName, template);
if (serviceSpec.waitForBuild()) {
waitForResources(serviceName, projectName, service);
waitForUI(serviceName, projectName);
}
}
Aggregations