Package com.openshift.client

Examples of com.openshift.client.IDomain


    }
  }

  @Test
  public void shouldContainErrorMessageAndContainErrorCode128() throws OpenShiftException {
    IDomain domain = null;
    try {
      // pre-condition
      domain = DomainTestUtils.ensureHasDomain(user);
      ApplicationTestUtils.getOrCreateApplication(domain);
      assertThat(domain.getApplications()).isNotEmpty();
     
      // operation
      domain.destroy();
      fail("OpenShiftEndpointException did not occurr");
    } catch (OpenShiftEndpointException e) {
      // verification
      assertThat(e.getRestResponseMessages().size()).isEqualTo(1);
      List<Message> messages = e.getRestResponseMessage(IField.DEFAULT);
View Full Code Here


  }

  @Test
  public void shouldDeleteDomainWithApplications() throws OpenShiftException, SocketTimeoutException {
    // pre-condition
    IDomain domain = DomainTestUtils.ensureHasDomain(user);
    ApplicationTestUtils.getOrCreateApplication(domain);
    assertThat(domain.getApplications()).isNotEmpty();
   
    // operation
    domain.destroy(true);

    // verification
    assertThat(domain).isNotIn(user.getDomains());
    domain = null;
  }
View Full Code Here

  }

  @Test
  public void shouldSeeNewApplicationAfterRefresh() throws OpenShiftException, FileNotFoundException, IOException {
    // pre-condition
    IDomain domain = DomainTestUtils.ensureHasDomain(user);
    int numOfApplications = domain.getApplications().size();

    IUser otherUser = new TestConnectionBuilder().defaultCredentials().disableSSLCertificateChecks().create().getUser();
    IDomain otherDomain = otherUser.getDomain(domain.getId());
    assertNotNull(otherDomain);

    // operation
    String applicationName = "app" + StringUtils.createRandomString();
    otherDomain.createApplication(applicationName, LatestVersionOf.php().get(otherUser));
    assertThat(domain.getApplications().size()).isEqualTo(numOfApplications);
    domain.refresh();

    // verification
    assertThat(domain.getApplications().size()).isEqualTo(numOfApplications + 1);
View Full Code Here

  }

  @Test
  public void shouldMissApplicationAfterRefresh() throws OpenShiftException, FileNotFoundException, IOException {
    // pre-condition
    IDomain domain = DomainTestUtils.ensureHasDomain(user);
    IApplication application = ApplicationTestUtils.getOrCreateApplication(domain);
    assertThat(application).isNotNull();
    IUser otherUser = new TestConnectionBuilder().defaultCredentials().disableSSLCertificateChecks().create().getUser();
    IDomain otherDomain = otherUser.getDomain(domain.getId());
    assertNotNull(otherDomain);
    IApplication otherDomainApplication = otherDomain.getApplicationByName(application.getName());
    assertThat(otherDomainApplication).isNotNull();
   
    // operation
    otherDomainApplication.destroy();
    assertThat(otherDomain.getApplicationByName(application.getName())).isNull();
    domain.refresh();

    // verification
    assertThat(domain.getApplicationByName(application.getName())).isNull();
  }
View Full Code Here

  }
 
  @Test
  public void shouldGetApplicationByNameCaseInsensitive() throws OpenShiftException, FileNotFoundException, IOException {
    // pre-condition
    IDomain domain = DomainTestUtils.ensureHasDomain(user);
    IApplication application = ApplicationTestUtils.ensureHasExactly1Application(domain);
    assertThat(application).isNotNull();
    String name = application.getName();
    assertThat(name).isNotNull();
   
    // operation
    IApplication exactNameQueryResult = domain.getApplicationByName(name);
    IApplication upperCaseNameQueryResult = domain.getApplicationByName(name.toUpperCase());
   
    // verification
    assertThat(exactNameQueryResult).isNotNull();
    assertThat(exactNameQueryResult.getName()).isEqualTo(name);
    assertThat(upperCaseNameQueryResult).isNotNull();
View Full Code Here

    if (hasDomain(id)) {
      throw new OpenShiftException("Domain {0} already exists", id);
    }

    final DomainResourceDTO domainDTO = new AddDomainRequest().execute(id);
    final IDomain domain = new DomainResource(domainDTO, this);
    this.domains.add(domain);
    return domain;
  }
View Full Code Here

  public IDomain showDomain(String id) throws OpenShiftException {
    Assert.notNull(id);

    final DomainResourceDTO domainDTO = new ShowDomainRequest().execute(id);
    final IDomain domain = new DomainResource(domainDTO, this);
    // TODO: implement caching
    return domain;
  }
View Full Code Here

            return null;
        }
        CreateOpenshiftContainerOptions options = metadata.getCreateOptions();
        IOpenShiftConnection connection = OpenShiftUtils.createConnection(options);
        String containerName = container.getId();
        IDomain domain = connection.getUser().getDomain(metadata.getDomainId());
        return domain.getApplicationByName(containerName);
    }
View Full Code Here

    }

    public static IApplication getApplication(Container container, CreateOpenshiftContainerMetadata metadata,
                                              IOpenShiftConnection connection) {
        String containerName = container.getId();
        IDomain domain = connection.getUser().getDomain(metadata.getDomainId());
        return domain.getApplicationByName(containerName);
    }
View Full Code Here

    @Override
    public CreateOpenshiftContainerMetadata create(CreateOpenshiftContainerOptions options, CreationStateListener listener) throws Exception {
        assertValid();
        IUser user = getOrCreateConnection(options).getUser();
        IDomain domain =  getOrCreateDomain(user, options);
        String cartridgeUrl = null;
        Set<String> profiles = options.getProfiles();
        String versionId = options.getVersion();
        Map<String, String> openshiftConfigOverlay = new HashMap<String, String>();
        if (profiles != null && versionId != null) {
            ProfileService profileService = fabricService.get().adapt(ProfileService.class);
            Version version = profileService.getVersion(versionId);
            if (version != null) {
                for (String profileId : profiles) {
                    Profile profile = version.getRequiredProfile(profileId);
                    if (profile != null) {
                        Profile overlay = profileService.getOverlayProfile(profile);
                        Map<String, String> openshiftConfig = overlay.getConfiguration(OpenShiftConstants.OPENSHIFT_PID);
                        if (openshiftConfig != null)  {
                            openshiftConfigOverlay.putAll(openshiftConfig);
                        }
                    }
                }
            }
            cartridgeUrl = openshiftConfigOverlay.get("cartridge");
        }
        if (cartridgeUrl == null) {
            cartridgeUrl = defaultCartridgeUrl;
        }
        String[] cartridgeUrls = cartridgeUrl.split(" ");
        LOG.info("Creating cartridges: " + cartridgeUrl);
        String standAloneCartridgeUrl = cartridgeUrls[0];
        StandaloneCartridge cartridge;
        if (standAloneCartridgeUrl.startsWith(PREFIX_CARTRIDGE_ID)) {
            cartridge = new StandaloneCartridge(standAloneCartridgeUrl.substring(PREFIX_CARTRIDGE_ID.length()));
        } else {
            cartridge = new StandaloneCartridge(new URL(standAloneCartridgeUrl));
        }

        String zookeeperUrl = fabricService.get().getZookeeperUrl();
        String zookeeperPassword = fabricService.get().getZookeeperPassword();

        Map<String,String> userEnvVars = null;
        if (!options.isEnsembleServer()) {
            userEnvVars = new HashMap<String, String>();
            userEnvVars.put("OPENSHIFT_FUSE_ZOOKEEPER_URL", zookeeperUrl);
            userEnvVars.put("OPENSHIFT_FUSE_ZOOKEEPER_PASSWORD", zookeeperPassword);
            String zkPasswordEncode = System.getProperty("zookeeper.password.encode", "true");
            userEnvVars.put("OPENSHIFT_FUSE_ZOOKEEPER_PASSWORD_ENCODE", zkPasswordEncode);
        }

        String initGitUrl = null;
        int timeout = IHttpClient.NO_TIMEOUT;
        ApplicationScale scale = null;

        String containerName = options.getName();

        long t0 = System.currentTimeMillis();
        IApplication application;
        try {
            application = domain.createApplication(containerName, cartridge, scale, new GearProfile(options.getGearProfile()), initGitUrl, timeout, userEnvVars);
        } catch (OpenShiftTimeoutException e) {
            long t1;
            do {
                Thread.sleep(5000);
                domain.refresh();
                application = domain.getApplicationByName(containerName);
                if (application != null) {
                    break;
                }
                t1 = System.currentTimeMillis();
            } while (t1  - t0 < TimeUnit.MILLISECONDS.convert(15, TimeUnit.MINUTES));
        }
        LOG.info("Created application " + containerName);

        // now lets add all the embedded cartridges
        List<IEmbeddableCartridge> list = new ArrayList<IEmbeddableCartridge>();
        for (int idx = 1,  size = cartridgeUrls.length; idx < size; idx++) {
            String embeddedUrl = cartridgeUrls[idx];
            LOG.info("Adding embedded cartridge: " + embeddedUrl);
            if (embeddedUrl.startsWith(PREFIX_CARTRIDGE_ID)) {
                list.add(new EmbeddableCartridge(embeddedUrl.substring(PREFIX_CARTRIDGE_ID.length())));
            } else {
                list.add(new EmbeddableCartridge(new URL(embeddedUrl)));
            }
        }
        if (!list.isEmpty()) {
            application.addEmbeddableCartridges(list);
        }

        String gitUrl = application.getGitUrl();
        // in case of OpenShiftTimeoutException, application resource doesn't contain getCreationLog().
        // actually this method throws NPE
        CreateOpenshiftContainerMetadata metadata = new CreateOpenshiftContainerMetadata(domain.getId(), application.getUUID(), application.getMessages() == null ? "" : application.getCreationLog(), gitUrl);
        metadata.setContainerName(containerName);
        metadata.setCreateOptions(options);
        return metadata;
    }
View Full Code Here

TOP

Related Classes of com.openshift.client.IDomain

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.