Esempio n. 1
0
  @Test
  public void testUpload() throws Exception {
    String featureLocation = System.getProperty("feature.location");
    System.out.println("Testing with feature from:" + featureLocation);
    System.err.println(executeCommand("fabric:create -n"));
    Set<Container> containers =
        ContainerBuilder.create(2)
            .withName("maven")
            .withProfiles("fabric")
            .assertProvisioningResult()
            .build();

    FabricService fabricService = getFabricService();
    IZKClient zookeeper = getZookeeper();
    List<String> children = zookeeper.getChildren(ZkPath.MAVEN_PROXY.getPath("upload"));
    List<String> uploadUrls = new ArrayList<String>();
    for (String child : children) {
      String uploadeUrl =
          ZooKeeperUtils.getSubstitutedPath(
              zookeeper, ZkPath.MAVEN_PROXY.getPath("upload") + "/" + child);
      uploadUrls.add(uploadeUrl);
    }
    // Pick a random maven proxy from the list.
    Random random = new Random();
    int index = random.nextInt(uploadUrls.size());
    String targetUrl = uploadUrls.get(index);

    String uploadUrl = targetUrl + "itest/itest/1.0/itest-1.0-features.xml";
    System.out.println("Using URI: " + uploadUrl);
    DefaultHttpClient client = new DefaultHttpClient();
    HttpPut put = new HttpPut(uploadUrl);
    client
        .getCredentialsProvider()
        .setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("admin", "admin"));

    FileNIOEntity entity = new FileNIOEntity(new File(featureLocation), "text/xml");
    put.setEntity(entity);
    HttpResponse response = client.execute(put);
    System.err.println("Response:" + response.getStatusLine());
    Assert.assertTrue(
        response.getStatusLine().getStatusCode() == 200
            || response.getStatusLine().getStatusCode() == 202);

    System.err.println(
        executeCommand(
            "fabric:profile-edit --repositories mvn:itest/itest/1.0/xml/features default"));
    System.err.println(executeCommand("fabric:profile-edit --features example-cbr default"));
    Provision.waitForContainerStatus(containers, PROVISION_TIMEOUT);
  }
Esempio n. 2
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()));
    }
  }