Search in sources :

Example 1 with IResourceFactory

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;
}
Also used : DockerImageURI(com.openshift.restclient.images.DockerImageURI) HashMap(java.util.HashMap) IImageStream(com.openshift.restclient.model.IImageStream) IResourceFactory(com.openshift.restclient.IResourceFactory) IProject(com.openshift.restclient.model.IProject) IResource(com.openshift.restclient.model.IResource)

Example 2 with IResourceFactory

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);
    }
}
Also used : RedDeerException(org.eclipse.reddeer.common.exception.RedDeerException) MalformedURLException(java.net.MalformedURLException) FileNotFoundException(java.io.FileNotFoundException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) IOException(java.io.IOException) IResourceFactory(com.openshift.restclient.IResourceFactory) File(java.io.File) URL(java.net.URL) ConnectionURL(org.jboss.tools.openshift.common.core.connection.ConnectionURL) FileInputStream(java.io.FileInputStream) ClientBuilder(com.openshift.restclient.ClientBuilder)

Aggregations

IResourceFactory (com.openshift.restclient.IResourceFactory)2 ClientBuilder (com.openshift.restclient.ClientBuilder)1 DockerImageURI (com.openshift.restclient.images.DockerImageURI)1 IImageStream (com.openshift.restclient.model.IImageStream)1 IProject (com.openshift.restclient.model.IProject)1 IResource (com.openshift.restclient.model.IResource)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 RedDeerException (org.eclipse.reddeer.common.exception.RedDeerException)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 ConnectionURL (org.jboss.tools.openshift.common.core.connection.ConnectionURL)1