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);
  }
 /**
  * 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;
 }
 public static IApplication createApplication(IStandaloneCartridge cartridge, IDomain domain) {
   IApplication application = domain.createApplication(createRandomApplicationName(), cartridge);
   assertTrue(application.waitForAccessible(WAIT_FOR_APPLICATION));
   return application;
 }