示例#1
0
 protected Profile getProfile(Version ver, String name) {
   Profile p = ver.getProfile(name);
   if (p == null) {
     throw new IllegalArgumentException("Profile " + name + " does not exist.");
   }
   return p;
 }
示例#2
0
  @Override
  protected Object doExecute() throws Exception {
    checkFabricAvailable();
    if (delete) {
      set = false;
    }
    Version version =
        versionName != null
            ? fabricService.getVersion(versionName)
            : fabricService.getDefaultVersion();

    for (Profile profile : version.getProfiles()) {
      if (profileName.equals(profile.getId())) {
        editProfile(profile);
      }
    }
    return null;
  }
示例#3
0
  @Override
  public int complete(String buffer, int cursor, List<String> candidates) {
    StringsCompleter delegate = new StringsCompleter();
    String versionName = null;
    try {
      Version defaultVersion = fabricService.getDefaultVersion();
      if (defaultVersion != null) {
        versionName = defaultVersion.getName();
      }
      if (versionName == null) {
        versionName = ZkDefs.DEFAULT_VERSION;
      }

      Profile[] profiles = fabricService.getProfiles(versionName);
      for (Profile profile : profiles) {
        delegate.getStrings().add(profile.getId());
      }
    } catch (Exception ex) {
      // Ignore Exceptions
    }
    return delegate.complete(buffer, cursor, candidates);
  }
示例#4
0
  /**
   * Gets the profiles for upgrade/rollback
   *
   * @param existingProfiles the existing profiles
   * @param targetVersion the target version
   * @return the new profiles to be used
   */
  protected Profile[] getProfilesForUpgradeOrRollback(
      Profile[] existingProfiles, Version targetVersion) {
    List<Profile> list = new ArrayList<Profile>(existingProfiles.length);
    for (Profile old : existingProfiles) {
      // get new profile
      Profile newProfile = targetVersion.getProfile(old.getId());
      if (newProfile != null) {
        list.add(newProfile);
      } else {
        // we expect a profile with the new version to exist
        throw new IllegalArgumentException(
            "Profile " + old.getId() + " with version " + targetVersion + " does not exists");
      }
    }

    return list.toArray(new Profile[0]);
  }
示例#5
0
 protected Profile[] getProfiles(Version version, List<String> names) {
   Profile[] allProfiles = version.getProfiles();
   List<Profile> profiles = new ArrayList<Profile>();
   if (names == null) {
     return new Profile[0];
   }
   for (String name : names) {
     Profile profile = null;
     for (Profile p : allProfiles) {
       if (name.equals(p.getId())) {
         profile = p;
         break;
       }
     }
     if (profile == null) {
       throw new IllegalArgumentException("Profile " + name + " not found.");
     }
     profiles.add(profile);
   }
   return profiles.toArray(new Profile[profiles.size()]);
 }
示例#6
0
  /**
   * Adds a feature to the profile and tests it on the container.
   *
   * <p>Note: Before and after the test the container moves to default profile.
   *
   * @param featureNames
   * @param profileName
   * @param expectedSymbolicNames
   */
  public void assertProvisionedFeature(
      Set<Container> containers,
      String featureNames,
      String profileName,
      String expectedSymbolicNames)
      throws Exception {
    IZKClient zooKeeper = getZookeeper();
    StringBuilder sb = new StringBuilder();
    sb.append("[ ");
    for (Container container : containers) {
      sb.append(container.getId()).append(" ");
    }
    sb.append("]");

    System.out.println(
        "Testing profile:"
            + profileName
            + " on container:"
            + sb.toString()
            + " by adding feature:"
            + featureNames);
    FabricService fabricService = getFabricService();
    Version version = fabricService.getDefaultVersion();

    Profile defaultProfile = fabricService.getProfile(version.getName(), "default");
    Profile targetProfile = fabricService.getProfile(version.getName(), profileName);

    for (Container container : containers) {
      // We set container to default to clean the container up.
      container.setProfiles(new Profile[] {defaultProfile});
    }
    Provision.waitForContainerStatus(containers, PROVISION_TIMEOUT);

    for (String featureName : featureNames.split(" ")) {
      System.out.println(
          executeCommand(
              "fabric:profile-edit --features " + featureName + " " + targetProfile.getId()));
    }

    for (Container container : containers) {
      // Test the modified profile.
      if (!defaultProfile.configurationEquals(targetProfile)) {
        ZooKeeperUtils.set(
            getZookeeper(),
            ZkPath.CONTAINER_PROVISION_RESULT.getPath(container.getId()),
            "switching profile");
      }
      container.setProfiles(new Profile[] {targetProfile});
      // containerSetProfile(container.getId(), profileName, false);
    }

    Provision.waitForContainerStatus(containers, PROVISION_TIMEOUT);
    System.out.println(executeCommand("fabric:profile-display " + profileName));
    System.out.println(executeCommand("fabric:container-list"));

    for (Container container : containers) {
      for (String symbolicName : expectedSymbolicNames.split(" ")) {
        System.out.println(
            executeCommand(
                "container-connect -u admin -p admin " + container.getId() + " osgi:list -s -t 0"));
        String bundles =
            executeCommand(
                "container-connect -u admin -p admin "
                    + container.getId()
                    + " osgi:list -s -t 0 | grep "
                    + symbolicName);
        System.out.flush();
        Assert.assertNotNull(bundles);
        Assert.assertTrue(
            "Expected to find symbolic name:" + symbolicName, bundles.contains(symbolicName));
        System.out.println(bundles);
      }
    }

    for (Container container : containers) {
      // We set the container to default to clean up the profile.
      if (!defaultProfile.configurationEquals(targetProfile)) {
        ZooKeeperUtils.set(
            getZookeeper(),
            ZkPath.CONTAINER_PROVISION_RESULT.getPath(container.getId()),
            "switching profile");
      }
      container.setProfiles(new Profile[] {defaultProfile});
    }

    Provision.waitForContainerStatus(containers, PROVISION_TIMEOUT);
    for (String featureName : featureNames.split(" ")) {
      System.out.println(
          executeCommand(
              "fabric:profile-edit --delete --features "
                  + featureName
                  + " "
                  + targetProfile.getId()));
    }
  }
示例#7
0
 /**
  * Compare the version with the container
  *
  * @param version the version to rollback to
  * @param container the container
  * @return <tt>-1</tt> if cannot rollback, <tt>0</tt> if same version, or <tt>1</tt> if can
  *     rollback
  */
 protected int canUpgrade(Version version, Container container) {
   Version current = container.getVersion();
   return version.compareTo(current);
 }
示例#8
0
 public VersionDTO(Version version) {
   this.id = version.getName();
   this.attributes = version.getAttributes();
 }