public void test() throws Exception {
    ConfigurationFactory config = new ConfigurationFactory();
    Assembler assembler = new Assembler();

    // System services
    assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));

    // JMS persistence datasource
    ResourceInfo dataSourceInfo =
        config.configureService("Default Unmanaged JDBC Database", ResourceInfo.class);
    dataSourceInfo.properties.setProperty("JdbcUrl", "jdbc:hsqldb:mem:MdbConfigTest");
    assembler.createResource(dataSourceInfo);

    // JMS
    assembler.createResource(
        config.configureService("Default JMS Resource Adapter", ResourceInfo.class));

    // JMS Container
    MdbContainerInfo mdbContainerInfo = config.configureService(MdbContainerInfo.class);
    assembler.createContainer(mdbContainerInfo);

    // FakeRA
    ResourceInfo resourceInfo = new ResourceInfo();
    resourceInfo.service = "Resource";
    resourceInfo.className = FakeRA.class.getName();
    resourceInfo.id = "FakeRA";
    resourceInfo.properties = new Properties();
    assembler.createResource(resourceInfo);

    // FakeRA container
    ContainerInfo containerInfo = config.configureService(MdbContainerInfo.class);
    containerInfo.id = "FakeContainer";
    containerInfo.displayName = "Fake Container";
    containerInfo.properties.setProperty("ResourceAdapter", "FakeRA");
    containerInfo.properties.setProperty(
        "MessageListenerInterface", FakeMessageListener.class.getName());
    containerInfo.properties.setProperty("ActivationSpecClass", FakeActivationSpec.class.getName());
    assembler.createContainer(containerInfo);

    // generate ejb jar application
    EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(
        createJaxbMdb("JmsMdb", BasicMdbBean.class.getName(), MessageListener.class.getName()));
    ejbJar.addEnterpriseBean(
        createJaxbMdb("FakeMdb", FakeMdb.class.getName(), FakeMessageListener.class.getName()));
    EjbModule ejbModule =
        new EjbModule(getClass().getClassLoader(), "FakeEjbJar", "fake.jar", ejbJar, null);

    // configure and deploy it
    EjbJarInfo info = config.configureApplication(ejbModule);
    assembler.createEjbJar(info);
  }
  public MesosSlaveInfo getMesosSlaveInfoForLabel(Label label) {
    if (!matchesLabel(label)) {
      return null;
    }

    if (label == null) {
      if (getLabelString() == null) {
        return this;
      } else {
        return null;
      }
    }

    if (label.matches(Label.parse(getLabelString()))) {
      return this;
    }

    if (!containerInfo.getDockerImageCustomizable()) {
      return null;
    }

    String customImage = getCustomImage(label);
    if (customImage == null) {
      return null;
    }

    return copyWithDockerImage(label.toString(), customImage);
  }
  public MesosSlaveInfo copyWithDockerImage(String label, String dockerImage) {
    LOGGER.fine(
        String.format(
            "Customize mesos slave %s using docker image %s", this.getLabelString(), dockerImage));

    try {
      return new MesosSlaveInfo(
          label,
          mode,
          slaveCpus,
          slaveMem,
          minExecutors,
          maxExecutors,
          executorCpus,
          executorMem,
          remoteFSRoot,
          idleTerminationMinutes,
          slaveAttributes,
          jvmArgs,
          jnlpArgs,
          defaultSlave,
          containerInfo.copyWithDockerImage(dockerImage),
          additionalURIs,
          nodeProperties);
    } catch (Descriptor.FormException e) {
      LOGGER.log(Level.WARNING, "Failed to create customized mesos container info", e);
      return null;
    } catch (IOException e) {
      LOGGER.log(Level.WARNING, "Failed to create customized mesos slave info", e);
      return null;
    }
  }
  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    MesosSlaveInfo that = (MesosSlaveInfo) o;

    if (Double.compare(that.slaveCpus, slaveCpus) != 0) return false;
    if (slaveMem != that.slaveMem) return false;
    if (Double.compare(that.executorCpus, executorCpus) != 0) return false;
    if (minExecutors != that.minExecutors) return false;
    if (maxExecutors != that.maxExecutors) return false;
    if (executorMem != that.executorMem) return false;
    if (idleTerminationMinutes != that.idleTerminationMinutes) return false;
    if (remoteFSRoot != null ? !remoteFSRoot.equals(that.remoteFSRoot) : that.remoteFSRoot != null)
      return false;
    if (jvmArgs != null ? !jvmArgs.equals(that.jvmArgs) : that.jvmArgs != null) return false;
    if (jnlpArgs != null ? !jnlpArgs.equals(that.jnlpArgs) : that.jnlpArgs != null) return false;
    if (slaveAttributes != null
        ? !slaveAttributes.equals(that.slaveAttributes)
        : that.slaveAttributes != null) return false;
    if (containerInfo != null
        ? !containerInfo.equals(that.containerInfo)
        : that.containerInfo != null) return false;
    if (additionalURIs != null
        ? !additionalURIs.equals(that.additionalURIs)
        : that.additionalURIs != null) return false;
    if (mode != that.mode) return false;
    if (nodeProperties != null
        ? !nodeProperties.equals(that.nodeProperties)
        : that.nodeProperties != null) return false;
    return labelString != null ? labelString.equals(that.labelString) : that.labelString == null;
  }
 public void updateTestContextWithAppServerInfo(@Observes(precedence = 1) BeforeClass event) {
   testContext = testContextProducer.get();
   String appServerQualifier = getAppServerQualifier(testContext.getTestClass());
   for (ContainerInfo container : testContext.getSuiteContext().getContainers()) {
     if (container.getQualifier().equals(appServerQualifier)) {
       testContext.setAppServerInfo(updateWithAppServerInfo(container));
     }
   }
   // validate app server
   if (appServerQualifier != null && testContext.getAppServerInfo() == null) {
     throw new RuntimeException(
         String.format(
             "No app server container matching '%s' was activated. Check if defined and enabled in arquillian.xml.",
             appServerQualifier));
   }
   log.info("\n\n" + testContext);
 }
  private void installAdapterLibsUsingJBossCLIClient(ContainerInfo appServerInfo)
      throws InterruptedException, IOException {
    if (!appServerInfo.isAdapterLibsInstalled()) {

      if (!appServerInfo.isJBossBased()) {
        throw new IllegalArgumentException(
            "App server must be JBoss-based to run jboss-cli-client.");
      }

      String jbossHomePath = appServerInfo.getProperties().get("jbossHome");

      File bin = new File(jbossHomePath + "/bin");

      File clientJar = new File(jbossHomePath + "/bin/client/jboss-cli-client.jar");
      if (!clientJar.exists()) {
        clientJar = new File(jbossHomePath + "/bin/client/jboss-client.jar"); // AS7
      }
      if (!clientJar.exists()) {
        throw new IOException("JBoss CLI client JAR not found.");
      }

      String command = "java -jar " + clientJar.getAbsolutePath();
      String adapterScript = "adapter-install.cli";
      String samlAdapterScript = "adapter-install-saml.cli";
      String managementPort = appServerInfo.getProperties().get("managementPort");

      String controllerArg = " --controller=localhost:" + managementPort;
      if (new File(bin, adapterScript).exists()) {
        log.info("Installing adapter to app server via cli script");
        execCommand(command + " --connect --file=" + adapterScript + controllerArg, bin);
      }
      if (new File(bin, samlAdapterScript).exists()) {
        log.info("Installing saml adapter to app server via cli script");
        execCommand(command + " --connect --file=" + samlAdapterScript + controllerArg, bin);
      }
      if (new File(bin, adapterScript).exists() || new File(bin, samlAdapterScript).exists()) {
        log.info("Restarting container");
        execCommand(command + " --connect --command=reload" + controllerArg, bin);
        log.info("Container restarted");
        pause(5000);
        LogChecker.checkJBossServerLog(jbossHomePath);
      }

      appServerInfo.setAdapterLibsInstalled(true);
    }
  }
  private ContainerInfo updateWithAppServerInfo(
      ContainerInfo appServerInfo, int clusterPortOffset) {
    try {

      String appServerContextRootStr =
          isRelative(testContext.getTestClass())
              ? getAuthServerContextRoot(clusterPortOffset)
              : getAppServerContextRoot(clusterPortOffset);

      appServerInfo.setContextRoot(new URL(appServerContextRootStr));

    } catch (MalformedURLException ex) {
      throw new IllegalArgumentException(ex);
    }
    return appServerInfo;
  }
  /**
   * Check if the label in the slave matches the provided label, either both are null or are the
   * same.
   *
   * @param label
   * @return Whether the slave label matches.
   */
  public boolean matchesLabel(@CheckForNull Label label) {

    if (label == null || getLabelString() == null) {
      return label == null && getLabelString() == null;
    }

    if (label.matches(Label.parse(getLabelString()))) {
      return true;
    }

    if (containerInfo == null || !containerInfo.getDockerImageCustomizable()) {
      return false;
    }

    String customImage = getCustomImage(label);
    return customImage != null
        && getLabelWithoutCustomImage(label, customImage).matches(Label.parse(getLabelString()));
  }
 @Override
 public int hashCode() {
   int result;
   long temp;
   temp = Double.doubleToLongBits(slaveCpus);
   result = (int) (temp ^ (temp >>> 32));
   result = 31 * result + slaveMem;
   temp = Double.doubleToLongBits(executorCpus);
   result = 31 * result + (int) (temp ^ (temp >>> 32));
   result = 31 * result + minExecutors;
   result = 31 * result + maxExecutors;
   result = 31 * result + executorMem;
   result = 31 * result + (remoteFSRoot != null ? remoteFSRoot.hashCode() : 0);
   result = 31 * result + idleTerminationMinutes;
   result = 31 * result + (jvmArgs != null ? jvmArgs.hashCode() : 0);
   result = 31 * result + (jnlpArgs != null ? jnlpArgs.hashCode() : 0);
   result = 31 * result + (slaveAttributes != null ? slaveAttributes.hashCode() : 0);
   result = 31 * result + (containerInfo != null ? containerInfo.hashCode() : 0);
   result = 31 * result + (additionalURIs != null ? additionalURIs.hashCode() : 0);
   result = 31 * result + (mode != null ? mode.hashCode() : 0);
   result = 31 * result + (nodeProperties != null ? nodeProperties.hashCode() : 0);
   result = 31 * result + (labelString != null ? labelString.hashCode() : 0);
   return result;
 }
Exemplo n.º 10
0
  protected boolean generate(TrackerWebPageRequest request, TrackerWebPageResponse response)
      throws IOException {
    InetSocketAddress local_address = request.getLocalAddress();

    if (local_address == null) {

      return (false);
    }

    String host = local_address.getAddress().getHostAddress();

    String url = request.getURL();

    if (TRACE) {
      System.out.println("url: " + url);
    }

    if (!url.startsWith("/TiVoConnect?")) {

      return (false);
    }

    int pos = url.indexOf('?');

    if (pos == -1) {

      return (false);
    }

    String[] bits = url.substring(pos + 1).split("&");

    Map<String, String> args = new HashMap<String, String>();

    for (String bit : bits) {

      String[] x = bit.split("=");

      args.put(x[0], URLDecoder.decode(x[1], "UTF-8"));
    }

    if (TRACE) {
      System.out.println("args: " + args);
    }

    // root folder /TiVoConnect?Command=QueryContainer&Container=%2F

    String command = args.get("Command");

    if (command == null) {

      return (false);
    }

    String reply = null;

    if (command.equals("QueryContainer")) {

      String container = args.get("Container");

      if (container == null) {

        return (false);
      }

      if (container.equals("/")) {

        reply =
            "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
                + NL
                + "<TiVoContainer>"
                + NL
                + "    <Details>"
                + NL
                + "        <Title>"
                + server_name
                + "</Title>"
                + NL
                + "        <ContentType>x-container/tivo-server</ContentType>"
                + NL
                + "        <SourceFormat>x-container/folder</SourceFormat>"
                + NL
                + "        <TotalItems>1</TotalItems>"
                + NL
                + "    </Details>"
                + NL
                + "    <Item>"
                + NL
                + "        <Details>"
                + NL
                + "            <Title>"
                + server_name
                + "</Title>"
                + NL
                + "            <ContentType>x-container/tivo-videos</ContentType>"
                + NL
                + "            <SourceFormat>x-container/folder</SourceFormat>"
                + NL
                + "        </Details>"
                + NL
                + "        <Links>"
                + NL
                + "            <Content>"
                + NL
                + "                <Url>/TiVoConnect?Command=QueryContainer&amp;Container="
                + urlencode("/Content")
                + "</Url>"
                + NL
                + "                <ContentType>x-container/tivo-videos</ContentType>"
                + NL
                + "            </Content>"
                + NL
                + "        </Links>"
                + NL
                + "    </Item>"
                + NL
                + "    <ItemStart>0</ItemStart>"
                + NL
                + "    <ItemCount>1</ItemCount>"
                + NL
                + "</TiVoContainer>";

      } else if (container.startsWith("/Content")) {

        boolean show_categories = getShowCategories();

        String recurse = args.get("Recurse");

        if (recurse != null && recurse.equals("Yes")) {

          show_categories = false;
        }

        TranscodeFileImpl[] tfs = getFiles();

        String category_or_tag = null;

        Map<String, ContainerInfo> categories_or_tags = null;

        if (show_categories) {

          if (container.startsWith("/Content/")) {

            category_or_tag = container.substring(container.lastIndexOf('/') + 1);

          } else {

            categories_or_tags = new HashMap<String, ContainerInfo>();
          }
        }

        // build list of applicable items

        List<ItemInfo> items = new ArrayList<ItemInfo>(tfs.length);

        for (TranscodeFileImpl file : tfs) {

          if (!file.isComplete()) {

            // see if we can set up a stream xcode for this but only if we
            // know the duration and the transcode is in progress (done in setup)

            if (!setupStreamXCode(file)) {

              continue;
            }
          }

          if (category_or_tag != null) {

            boolean hit = false;

            String[] cats = file.getCategories();
            String[] tags = file.getTags(true);

            for (String[] strs : new String[][] {cats, tags}) {

              for (String c : strs) {

                if (c.equals(category_or_tag)) {

                  hit = true;
                }
              }
            }

            if (!hit) {

              continue;
            }
          }

          FileInfo info = new FileInfo(file, host);

          if (info.isOK()) {

            boolean skip = false;

            if (categories_or_tags != null) {

              String[] cats = file.getCategories();
              String[] tags = file.getTags(true);

              if (cats.length > 0 || tags.length > 0) {

                skip = true;

                for (String[] strs : new String[][] {cats, tags}) {

                  for (String s : strs) {

                    ContainerInfo cont = categories_or_tags.get(s);

                    if (cont == null) {

                      items.add(cont = new ContainerInfo(s));

                      categories_or_tags.put(s, cont);
                    }

                    cont.addChild();
                  }
                }
              }
            }

            if (!skip) {

              items.add(info);
            }
          }
        }

        // sort

        String sort_order = args.get("SortOrder");

        if (sort_order != null) {

          String[] keys = Constants.PAT_SPLIT_COMMA.split(sort_order);

          final List<Comparator<ItemInfo>> comparators = new ArrayList<Comparator<ItemInfo>>();
          final List<Boolean> reverses = new ArrayList<Boolean>();

          for (String key : keys) {

            boolean reverse = false;

            if (key.startsWith("!")) {

              reverse = true;

              key = key.substring(1);
            }

            Comparator<ItemInfo> comp = sort_comparators.get(key);

            if (comp != null) {

              comparators.add(comp);
              reverses.add(reverse);
            }
          }

          if (comparators.size() > 0) {

            Collections.sort(
                items,
                new Comparator<ItemInfo>() {
                  public int compare(ItemInfo i1, ItemInfo i2) {
                    for (int i = 0; i < comparators.size(); i++) {

                      Comparator<ItemInfo> comp = comparators.get(i);

                      int res = comp.compare(i1, i2);

                      if (res != 0) {

                        if (reverses.get(i)) {

                          if (res < 0) {

                            res = 1;

                          } else {

                            res = -1;
                          }
                        }

                        return (res);
                      }
                    }

                    return (0);
                  }
                });
          }
        }

        // select items to return

        String item_count = args.get("ItemCount");
        String anchor_offset = args.get("AnchorOffset");
        String anchor = args.get("AnchorItem");

        int num_items;

        if (item_count == null) {

          num_items = items.size();

        } else {

          // can be negative if X items from end

          num_items = Integer.parseInt(item_count);
        }

        int
            anchor_index; // either one before or one after item to be returned depending on count
                          // +ve/-ve

        if (num_items < 0) {

          anchor_index = items.size();

        } else {

          anchor_index = -1;
        }

        if (anchor != null) {

          for (int i = 0; i < items.size(); i++) {

            ItemInfo info = items.get(i);

            if (anchor.equals(info.getLinkURL())) {

              anchor_index = i;
            }
          }
        }

        if (anchor_offset != null) {

          anchor_index += Integer.parseInt(anchor_offset);

          if (anchor_index < -1) {

            anchor_index = -1;

          } else if (anchor_index > items.size()) {

            anchor_index = items.size();
          }
        }

        int start_index;
        int end_index;

        if (num_items > 0) {

          start_index = anchor_index + 1;

          end_index = anchor_index + num_items;

        } else {

          start_index = anchor_index + num_items;

          end_index = anchor_index - 1;
        }

        if (start_index < 0) {

          start_index = 0;
        }

        if (end_index >= items.size()) {

          end_index = items.size() - 1;
        }

        int num_to_return = end_index - start_index + 1;

        if (num_to_return < 0) {

          num_to_return = 0;
        }

        String machine = getMachineName();

        if (machine == null) {

          // default until we find out what it is - can't see any way to get it apart from wait for
          // broadcast

          machine = "TivoHDDVR";
        }

        String header =
            "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
                + NL
                + "<TiVoContainer>"
                + NL
                + "    <Tivos>"
                + NL
                + "      <Tivo>"
                + machine
                + "</Tivo>"
                + NL
                + "    </Tivos>"
                + NL
                + "    <ItemStart>"
                + start_index
                + "</ItemStart>"
                + NL
                + "    <ItemCount>"
                + num_to_return
                + "</ItemCount>"
                + NL
                + "    <Details>"
                + NL
                + "        <Title>"
                + escape(container)
                + "</Title>"
                + NL
                + "        <ContentType>x-container/tivo-videos</ContentType>"
                + NL
                + "        <SourceFormat>x-container/folder</SourceFormat>"
                + NL
                + "        <TotalItems>"
                + items.size()
                + "</TotalItems>"
                + NL
                + "    </Details>"
                + NL;

        reply = header;

        for (int i = start_index; i <= end_index; i++) {

          ItemInfo item = items.get(i);

          if (item instanceof FileInfo) {

            FileInfo file = (FileInfo) item;

            long file_size = file.getTargetSize();

            String title = escape(file.getName());
            String desc = title;

            int MAX_TITLE_LENGTH = 30;

            if (title.length() > MAX_TITLE_LENGTH) {

              // TiVo has problems displaying a truncated title if it has
              // no spaces in it

              String temp = "";

              for (int j = 0; j < title.length(); j++) {

                char c = title.charAt(j);

                if (Character.isLetterOrDigit(c)) {

                  temp += c;
                } else {

                  temp += ' ';
                }
              }

              int space_pos = temp.indexOf(' ');

              if (space_pos == -1 || space_pos > MAX_TITLE_LENGTH) {

                temp = temp.substring(0, 30) + "...";
              }

              title = temp;
            }

            reply +=
                "    <Item>"
                    + NL
                    + "        <Details>"
                    + NL
                    + "            <Title>"
                    + title
                    + "</Title>"
                    + NL
                    + "            <ContentType>video/x-tivo-mpeg</ContentType>"
                    + NL
                    + "            <SourceFormat>video/x-ms-wmv</SourceFormat>"
                    + NL;

            if (file_size > 0) {
              reply += "            <SourceSize>" + file_size + "</SourceSize>" + NL;
            } else {
              long est_size = file.getEstimatedTargetSize();

              if (est_size > 0) {
                reply += "            <SourceSize>" + est_size + "</SourceSize>" + NL;
              }
            }

            reply +=
                "            <Duration>"
                    + file.getDurationMillis()
                    + "</Duration>"
                    + NL
                    + "            <Description>"
                    + desc
                    + "</Description>"
                    + NL
                    + "            <SourceChannel>0</SourceChannel>"
                    + NL
                    + "            <SourceStation></SourceStation>"
                    + NL
                    + "            <SeriesId></SeriesId>"
                    + NL
                    + "            <CaptureDate>"
                    + file.getCaptureDate()
                    + "</CaptureDate>"
                    + NL
                    + "        </Details>"
                    + NL
                    + "        <Links>"
                    + NL
                    + "            <Content>"
                    + NL
                    + "                <ContentType>video/x-tivo-mpeg</ContentType>"
                    + NL
                    + "                    <AcceptsParams>No</AcceptsParams>"
                    + NL
                    + "                    <Url>"
                    + file.getLinkURL()
                    + "</Url>"
                    + NL
                    + "                </Content>"
                    + NL
                    + "                <CustomIcon>"
                    + NL
                    + "                    <ContentType>video/*</ContentType>"
                    + NL
                    + "                    <AcceptsParams>No</AcceptsParams>"
                    + NL
                    + "                    <Url>urn:tivo:image:save-until-i-delete-recording</Url>"
                    + NL
                    + "                </CustomIcon>"
                    + NL
                    + "        </Links>"
                    + NL
                    + "    </Item>"
                    + NL;

          } else {

            ContainerInfo cont = (ContainerInfo) item;

            reply +=
                "    <Item>"
                    + NL
                    + "        <Details>"
                    + NL
                    + "            <Title>"
                    + cont.getName()
                    + "</Title>"
                    + NL
                    + "            <ContentType>x-container/tivo-videos</ContentType>"
                    + NL
                    + "            <SourceFormat>x-container/folder</SourceFormat>"
                    + NL
                    + "            <TotalItems>"
                    + cont.getChildCount()
                    + "</TotalItems>"
                    + NL
                    + "        </Details>"
                    + NL
                    + "        <Links>"
                    + NL
                    + "            <Content>"
                    + NL
                    + "                <Url>"
                    + cont.getLinkURL()
                    + "</Url>"
                    + NL
                    + "                <ContentType>x-container/tivo-videos</ContentType>"
                    + NL
                    + "            </Content>"
                    + NL
                    + "        </Links>"
                    + NL
                    + "    </Item>"
                    + NL;
          }
        }

        String footer = "</TiVoContainer>";

        reply += footer;
      }

    } else if (command.equals("QueryFormats")) {

      String source_format = args.get("SourceFormat");

      if (source_format != null && source_format.startsWith("video")) {

        // /TiVoConnect?Command=QueryFormats&SourceFormat=video%2Fx-tivo-mpeg

        reply =
            "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                + NL
                + "<TiVoFormats><Format>"
                + NL
                + "<ContentType>video/x-tivo-mpeg</ContentType><Description/>"
                + NL
                + "</Format></TiVoFormats>";
      }
    }

    if (reply == null) {

      return (false);
    }

    if (TRACE) {
      System.out.println("->" + reply);
    }

    response.setContentType("text/xml");

    response.getOutputStream().write(reply.getBytes("UTF-8"));

    return (true);
  }