@Override
  public void doExecute(final IOpenShiftConnection connection) {
    final List<IDomain> domains = connection.getDomains();
    final Map<IDomain, List<IApplication>> applicationByDomains =
        new HashMap<IDomain, List<IApplication>>();
    final Map<IApplication, List<IEmbeddedCartridge>> embeddedCartridgesByApp =
        new HashMap<IApplication, List<IEmbeddedCartridge>>();

    for (final IDomain domain : domains) {
      final List<IApplication> applications = domain.getApplications();
      applicationByDomains.put(domain, applications);
      for (final IApplication app : applications) {
        embeddedCartridgesByApp.put(app, app.getEmbeddedCartridges());
      }
    }

    emptyLine();
    getLog().info("Standalone domains:");
    emptyLine();
    for (final IDomain domain : domains) {
      getLog().info("Id: " + domain.getId());
      getLog().info("Suffix: " + domain.getSuffix());
      for (final IApplication application : applicationByDomains.get(domain)) {
        dumpApplication(SPACE + SPACE, application, embeddedCartridgesByApp.get(application));
        emptyLine();
      }
      emptyLine();
    }
  }
 @Test
 public void shouldReturnThatHasNamedDomain() throws OpenShiftException {
   // precondition
   IDomain domain = DomainTestUtils.ensureHasDomain(user);
   // operation
   Boolean hasDomain = user.hasDomain(domain.getId());
   // verification
   assertTrue(hasDomain);
 }
Ejemplo n.º 3
0
 @Override
 protected Object doExecute() throws Exception {
   IOpenShiftConnection connection = getOrCreateConnection();
   System.out.println("[id]");
   for (IDomain domain : connection.getDomains()) {
     System.out.println(domain.getId());
   }
   return null;
 }
  public IDomain getDomain(String id) throws OpenShiftException {
    Assert.notNull(id);

    for (IDomain domain : getDomains()) {
      if (domain.getId().equals(id)) {
        return domain;
      }
    }
    return null;
  }
Ejemplo n.º 5
0
 @Override
 protected Object doExecute() throws Exception {
   IOpenShiftConnection connection = getOrCreateConnection();
   for (IDomain domain : connection.getDomains()) {
     if (domainId == null || domainId.equals(domain.getId())) {
       IApplication application = domain.getApplicationByName(applicationName);
       application.start();
     }
   }
   return null;
 }
 /**
  * Returns the given application if it is not scalable, destroys it and creates a new one with the
  * same cartridge and name otherwise.
  *
  * @param application
  * @return
  */
 public static IApplication destroyAndRecreateIfScalable(IApplication application) {
   if (!ApplicationScale.NO_SCALE.equals(application.getGearProfile())) {
     IStandaloneCartridge cartridge = application.getCartridge();
     IDomain domain = application.getDomain();
     application.destroy();
     application =
         domain.createApplication(
             createRandomApplicationName(), cartridge, ApplicationScale.NO_SCALE);
   }
   return application;
 }
  @Test
  public void shouldReturnDomainByName() throws OpenShiftException {
    // pre-condition
    IDomain domain = DomainTestUtils.ensureHasDomain(user);

    // operation
    IDomain domainByNamespace = user.getDomain(domain.getId());

    // verification
    assertThat(domainByNamespace.getId()).isEqualTo(domain.getId());
  }
  public static IApplication getOrCreateApplication(IDomain domain, IStandaloneCartridge cartridge)
      throws OpenShiftException {
    for (Iterator<IApplication> it = domain.getApplications().iterator(); it.hasNext(); ) {
      IApplication application = it.next();
      if (cartridge.equals(application.getCartridge())) {
        return application;
      }
    }

    return domain.createApplication("app" + StringUtils.createRandomString(), cartridge);
  }
  /**
   * Deletes applications that are above the given maximum number of applications.
   *
   * @param maxApplications
   * @param domain
   */
  public static void destroyIfMoreThan(int maxApplications, IDomain domain) {
    if (domain == null) {
      return;
    }

    int toDestroy = domain.getApplications().size() - maxApplications;

    for (Iterator<IApplication> it = domain.getApplications().iterator();
        it.hasNext() && toDestroy > 0;
        toDestroy--) {
      it.next().destroy();
    }
  }
  @Test
  public void shouldCreateDomain() throws OpenShiftException {
    // pre-condition
    // cannot create domain if there's already one
    DomainTestUtils.destroyAllDomains(user);

    // operation
    String id = DomainTestUtils.createRandomName();
    IDomain domain = user.createDomain(id);

    // verification
    assertThat(domain.getId()).isEqualTo(id);
  }
 @Test
 public void shouldGetDefaultDomain() throws OpenShiftException {
   // precondition
   DomainTestUtils.ensureHasDomain(user);
   // operation
   IDomain domain = user.getDefaultDomain();
   // verification
   assertNotNull(domain);
   assertNotNull(domain.getId());
   assertTrue(domain.getId().length() > 0);
   assertNotNull(domain.getSuffix());
   assertTrue(domain.getSuffix().length() > 0);
 }
 public static void destroyAllByCartridge(ICartridge cartridge, IDomain domain) {
   for (Iterator<IApplication> it = domain.getApplications().iterator(); it.hasNext(); ) {
     IApplication application = it.next();
     if (!application.getCartridge().equals(cartridge)) {
       application.destroy();
     }
   }
 }
 private void addRequiredApplication(
     EmbeddableCartridgeDiff diff, EmbeddableCartridgeRelations relation)
     throws OpenShiftException {
   if (relation.getRequiredApplication() != null
       && !domain.hasApplicationByCartridge(relation.getRequiredApplication())) {
     diff.addApplicationAddition(relation.getRequiredApplication());
   }
 }
  public static void destroyAllApplications(IDomain domain) {
    if (domain == null) {
      return;
    }

    for (IApplication application : domain.getApplications()) {
      application.destroy();
    }
  }
  public static void silentlyDestroyAllApplications(IDomain domain) {
    if (domain == null) {
      return;
    }

    for (IApplication application : domain.getApplications()) {
      silentlyDestroy(application);
    }
  }
  public static void silentlyDestroyAllApplicationsByCartridge(
      IStandaloneCartridge cartridge, IDomain domain) {
    if (domain == null) {
      return;
    }

    for (Iterator<IApplication> it = domain.getApplicationsByCartridge(cartridge).iterator();
        it.hasNext(); ) {
      silentlyDestroy(it.next());
    }
  }
  public static void silentlyDestroyApplications(int appsToDestroy, IDomain domain) {
    if (domain == null) {
      return;
    }

    for (Iterator<IApplication> it = domain.getApplications().iterator();
        it.hasNext() && appsToDestroy >= 0;
        appsToDestroy--) {
      silentlyDestroy(it.next());
    }
  }
  /**
   * Makes sure the given domain has exactly the given number of applications with the given type.
   * Either the excessive applications are destroyed or new ones (with the given cartridge) are
   * created to match the given number.
   *
   * @param numOfApplications
   * @param cartridge the required cartridge
   * @param domain
   */
  public static void ensureHasExactly(
      int numOfApplications, IStandaloneCartridge cartridge, IDomain domain) {
    assertNotNull(cartridge);
    if (domain == null) {
      return;
    }

    destroyAllNotOfType(cartridge, domain.getApplications());
    int delta = numOfApplications - domain.getApplications().size();
    if (delta < 0) {
      for (Iterator<IApplication> it = domain.getApplications().iterator();
          it.hasNext() && delta < 0;
          delta++) {
        it.next().destroy();
      }
    } else {
      for (; delta > 0; delta--) {
        createApplication(cartridge, domain);
      }
    }
  }
 public static IApplication getOrCreateApplication(IDomain domain) throws OpenShiftException {
   return getOrCreateApplication(domain, LatestVersionOf.jbossAs().get(domain.getUser()));
 }
 public static IApplication createApplication(IStandaloneCartridge cartridge, IDomain domain) {
   IApplication application = domain.createApplication(createRandomApplicationName(), cartridge);
   assertTrue(application.waitForAccessible(WAIT_FOR_APPLICATION));
   return application;
 }
 public static IOpenShiftConnection getConnection(IDomain domain) {
   if (domain == null) {
     return null;
   }
   return domain.getUser().getConnection();
 }
 public static IApplication ensureHasExactly1Application(
     LatestStandaloneCartridge selector, IDomain domain) {
   IStandaloneCartridge cartridge = selector.get(domain.getUser());
   ensureHasExactly(1, cartridge, domain);
   return domain.getApplications().get(0);
 }
 public static IApplication ensureHasExactly1Application(
     IStandaloneCartridge cartridge, IDomain domain) {
   ensureHasExactly(1, cartridge, domain);
   return domain.getApplications().get(0);
 }