Exemplo n.º 1
0
 /** Generate list with actions. */
 public static final HashSet<Action> generateActionSet() {
   if (actionSet.isEmpty()) {
     for (int i = 0; i < beanFactory.getBeanDefinitionNames().length; i++) {
       if (beanFactory
           .getBean(beanFactory.getBeanDefinitionNames()[i])
           .toString()
           .contains("compute")) {
         actionSet.add((Action) beanFactory.getBean(beanFactory.getBeanDefinitionNames()[i]));
       }
     }
   }
   return actionSet;
 }
Exemplo n.º 2
0
  public void testTwitterInstantiation() throws Exception {
    Twitter twitter = (Twitter) beanFactory.getBean("twitter");
    assertTrue(twitter instanceof Twitter);

    AsyncTwitter asyncTwitter = (AsyncTwitter) beanFactory.getBean("asyncTwitter");
    assertTrue(asyncTwitter instanceof AsyncTwitter);

    try {
      TwitterStream twitterStream = (TwitterStream) beanFactory.getBean("twitterStream");
      assertTrue(twitterStream instanceof TwitterStream);
    } catch (org.springframework.beans.factory.BeanCreationException ignore) {
    }
  }
Exemplo n.º 3
0
  public void testFactoryInstantiation() throws Exception {
    TwitterFactory twitterFactory = (TwitterFactory) beanFactory.getBean("twitterFactory");
    Twitter twitter = twitterFactory.getInstance();
    assertTrue(twitter instanceof Twitter);

    AsyncTwitterFactory asyncTwitterFactory =
        (AsyncTwitterFactory) beanFactory.getBean("asyncTwitterFactory");
    AsyncTwitter asyncTwitter = asyncTwitterFactory.getInstance();
    assertTrue(asyncTwitter instanceof AsyncTwitter);

    TwitterStreamFactory twitterStreamFactory =
        (TwitterStreamFactory) beanFactory.getBean("twitterStreamFactory");
    TwitterStream twitterStream = twitterStreamFactory.getInstance("test", "test");
    assertTrue(twitterStream instanceof TwitterStream);
  }
Exemplo n.º 4
0
 private Object getBean(String bean) {
   if (context != null) {
     return context.getBean(bean);
   } else {
     return null;
   }
 }
Exemplo n.º 5
0
 protected void setUp() {
   Resource res = new FileSystemResource("build/classes/beans.xml");
   XmlBeanFactory factory = new XmlBeanFactory(res);
   DataSource vfbDS = (DataSource) factory.getBean("vfbDataSource");
   this.setDataSource(vfbDS);
   LOG.debug("data source : " + vfbDS);
 }
  private void loadService(Field field) {
    ClassPathResource classPathResource = null;
    String serviceName = field.getName();
    try {
      classPathResource = new ClassPathResource(AppServiceFacade.CONFIGURATION_FILE_NAME);
      XmlBeanFactory beanFactory = new XmlBeanFactory(classPathResource);
      field.set(this, beanFactory.getBean(serviceName));
    } catch (NoSuchBeanDefinitionException e) {
      this.processLoadServiceException(e, serviceName);
    } catch (CannotLoadBeanClassException e) {
      this.processLoadServiceException(e, serviceName);
    } catch (Exception e) {

      String fileName = "";
      if (classPathResource != null) {
        try {
          fileName = "[" + classPathResource.getFile().getAbsolutePath() + "]";
        } catch (IOException e1) {
          fileName = "[" + AppServiceFacade.CONFIGURATION_FILE_NAME + " not found" + "]";
        }
        throw new ServiceFacadeInitializationException(
            "loadService(" + serviceName + ") from file " + fileName + " failed", e);
      }
    }
  }
Exemplo n.º 7
0
  public static XmlProviderManager buildXmlProvider() {

    ClassPathResource res = new ClassPathResource("rayo-providers.xml");
    XmlBeanFactory factory = new XmlBeanFactory(res);
    XmlProviderManager manager = (XmlProviderManager) factory.getBean("xmlProviderManager");
    Validator validator = (Validator) factory.getBean("validator");

    RayoClientProvider rayoClientProvider = new RayoClientProvider();
    rayoClientProvider.setNamespaces(new ArrayList<String>());
    rayoClientProvider.getNamespaces().add("urn:xmpp:rayo:1");
    rayoClientProvider.getNamespaces().add("jabber:client");
    rayoClientProvider.setValidator(validator);
    rayoClientProvider.setClasses(new ArrayList<Class<?>>());
    manager.register(rayoClientProvider);

    return manager;
  }
Exemplo n.º 8
0
 /** Generate list with action names. */
 public static final HashSet<String> generateActionNames() {
   if (actionNames.isEmpty()) {
     for (int i = 0; i < beanFactory.getBeanDefinitionNames().length; i++) {
       if (beanFactory
           .getBean(beanFactory.getBeanDefinitionNames()[i])
           .toString()
           .contains("compute")) {
         actionNames.add(
             OcciConfig.getInstance().config.getString("occi.scheme")
                 + "/infrastructure/compute/action#"
                 + beanFactory.getBeanDefinitionNames()[i]);
       }
     }
   }
   return actionNames;
 }
  public void testLocalSessionFactoryBeanWithTypeDefinitions() throws Exception {
    XmlBeanFactory xbf =
        new XmlBeanFactory(new ClassPathResource("typeDefinitions.xml", getClass()));
    TypeTestLocalSessionFactoryBean sf =
        (TypeTestLocalSessionFactoryBean) xbf.getBean("&sessionFactory");
    TypeDef type1 = (TypeDef) sf.mappings.getTypeDef("type1");
    TypeDef type2 = (TypeDef) sf.mappings.getTypeDef("type2");

    assertEquals("mypackage.MyTypeClass", type1.getTypeClass());
    assertEquals(2, type1.getParameters().size());
    assertEquals("value1", type1.getParameters().getProperty("param1"));
    assertEquals("othervalue", type1.getParameters().getProperty("otherParam"));

    assertEquals("mypackage.MyOtherTypeClass", type2.getTypeClass());
    assertEquals(1, type2.getParameters().size());
    assertEquals("myvalue", type2.getParameters().getProperty("myParam"));
  }
  public void testLocalSessionFactoryBeanWithFilterDefinitions() throws Exception {
    XmlBeanFactory xbf =
        new XmlBeanFactory(new ClassPathResource("filterDefinitions.xml", getClass()));
    FilterTestLocalSessionFactoryBean sf =
        (FilterTestLocalSessionFactoryBean) xbf.getBean("&sessionFactory");
    assertEquals(2, sf.registeredFilterDefinitions.size());
    FilterDefinition filter1 = (FilterDefinition) sf.registeredFilterDefinitions.get(0);
    FilterDefinition filter2 = (FilterDefinition) sf.registeredFilterDefinitions.get(1);

    assertEquals("filter1", filter1.getFilterName());
    assertEquals(2, filter1.getParameterNames().size());
    assertEquals(Hibernate.STRING, filter1.getParameterType("param1"));
    assertEquals(Hibernate.LONG, filter1.getParameterType("otherParam"));
    assertEquals("someCondition", filter1.getDefaultFilterCondition());

    assertEquals("filter2", filter2.getFilterName());
    assertEquals(1, filter2.getParameterNames().size());
    assertEquals(Hibernate.INTEGER, filter2.getParameterType("myParam"));
  }
  @Test
  public void testArgumentsQueue() throws Exception {

    Queue queue = beanFactory.getBean("arguments", Queue.class);
    assertNotNull(queue);

    RabbitTemplate template =
        new RabbitTemplate(new CachingConnectionFactory(BrokerTestUtils.getPort()));
    RabbitAdmin rabbitAdmin = new RabbitAdmin(template.getConnectionFactory());
    rabbitAdmin.deleteQueue(queue.getName());
    rabbitAdmin.declareQueue(queue);

    assertEquals(100L, queue.getArguments().get("x-message-ttl"));
    template.convertAndSend(queue.getName(), "message");

    Thread.sleep(200);
    String result = (String) template.receiveAndConvert(queue.getName());
    assertEquals(null, result);
  }
Exemplo n.º 12
0
/**
 * The Compute type represents a generic Information resource. For example a virtual machine. This
 * Compute type Inherits the Resource base type defined in OCCI Core Specification. Compute is
 * assigned to the Kind instance. [T. Metsch, A. Edmonds - Open Cloud Computing Interface -
 * Infrastructure, http://ogf.org/documents/GFD.184.pdf, Apr. 2011]
 *
 * @author Sebastian Heckmann
 * @author Sebastian Laag
 */
public class Compute extends Resource {
  /** Enumeration for CPU Architecture of the instance */
  public enum Architecture {
    x86,
    x64
  }

  /** Number of CPU Cores assigned to the Instance */
  private int cores;

  /** String DNS hostname for the Instance */
  private String hostname;

  /** Float CPU Clock frequency in gigahertz */
  private float speed;

  /** Float RAM in gigabytes allocated to the instance */
  private float memory;

  /** State of the compute resource */
  private State state;

  /** Architecture of the compute resource */
  private Architecture architecture;

  /** Current State of the instance */
  public enum State {
    active,
    inactive,
    suspended
  }

  /** Static Hashmap of all Compute Resources. The Key is a UUID, the Value a Compute Object. */
  private static Map<UUID, Compute> computeList = new HashMap<UUID, Compute>();

  /** Static HashSet of all compute attributes. */
  private static HashSet<String> attributes = new HashSet<String>();

  /** Random UUID of the compute resource. */
  private final UUID uuid;

  /*
   * All possible compute actions.
   */
  private static XmlBeanFactory beanFactory =
      new XmlBeanFactory(new ClassPathResource("occiConfig.xml"));
  private Action start = (Action) beanFactory.getBean("start");
  private Action stop = (Action) beanFactory.getBean("stop");
  private Action suspend = (Action) beanFactory.getBean("suspend");
  private Action restart = (Action) beanFactory.getBean("restart");

  private static final HashSet<Action> actionSet = new HashSet<Action>();
  private static final HashSet<String> actionNames = new HashSet<String>();

  public Compute(
      Architecture architecture,
      int cores,
      String hostname,
      float speed,
      float memory,
      State state,
      Set<String> attributes)
      throws URISyntaxException, NumberFormatException, IllegalArgumentException, NamingException {
    super("Compute", links, attributes);
    this.architecture = architecture;
    this.cores = cores;
    this.hostname = hostname;
    this.speed = speed;
    this.memory = memory;
    this.state = state;

    generateActionNames();

    // check if all attributes are correct
    if ((cores < 1)) {
      throw new NumberFormatException("Number of cores is negative!");
    } else if (speed <= 1) {
      throw new NumberFormatException("Number of speed is negative!");
    } else if (memory <= 1) {
      throw new NumberFormatException("Number of memory is negative!");
    }
    // check if there is a hostname
    if (hostname.length() == 0) {
      throw new NamingException("Name of the Compute resource can not be null");
    }
    /*
     * set Category
     */
    setKind(
        new Kind(
            actionSet,
            null,
            null,
            null,
            "compute",
            "Compute",
            OcciConfig.getInstance().config.getString("occi.scheme") + "/infrastructure#",
            attributes));
    getKind().setActionNames(actionNames);
    // set uuid for the resource
    uuid = UUID.randomUUID();
    setId(new URI(uuid.toString()));
    // put resource into compute list
    computeList.put(uuid, this);

    // Generate attribute list
    generateAttributeList();
  }

  /**
   * Return the full computeList
   *
   * @return all compute resources
   */
  public static final Map<UUID, Compute> getComputeList() {
    return computeList;
  }

  /**
   * Set compute list
   *
   * @param computeList
   */
  public static final void setComputeList(Map<UUID, Compute> computeList) {
    Compute.computeList = computeList;
  }

  /**
   * Returns the current UUID as a UUID Value
   *
   * @return current UUID assigned to the Instance
   */
  public final UUID getUuid() {
    return uuid;
  }

  /**
   * Returns the current Cores as a int Value
   *
   * @return current Cores assigned to the Instance
   */
  public final int getCores() {
    return cores;
  }

  /**
   * Sets the cores of the current Instance
   *
   * @param cores of the current Instance as an int
   */
  public final void setCores(int cores) {
    this.cores = cores;
  }

  /**
   * Returns the Hostname represented as a String of the current Instance
   *
   * @return Hostname as a String
   */
  public final String getHostname() {
    return hostname;
  }

  /**
   * Sets the hostname of the current Instance
   *
   * @param hostname of the current Instance as a String
   */
  public final void setHostname(String hostname) {
    this.hostname = hostname;
  }

  /**
   * Returns the speed of the current Instance as a float
   *
   * @return speed of the current Instance
   */
  public final float getSpeed() {
    return speed;
  }

  /**
   * Sets the speed of the current Instance
   *
   * @param speed of the current Instance as a float
   */
  public final void setSpeed(float speed) {
    this.speed = speed;
  }

  /**
   * Returns the memory of the current Instace as a float
   *
   * @return
   */
  public final float getMemory() {
    return memory;
  }

  /**
   * Sets the memory of the current Instance
   *
   * @param memory of the current Instance as a float
   */
  public final void setMemory(float memory) {
    this.memory = memory;
  }

  /**
   * Returns the State of the current Instance
   *
   * @return State of the current Instance
   */
  public final State getState() {
    return state;
  }

  /**
   * Sets the State of the current Instance
   *
   * @param State state of the current Instance
   */
  public final void setState(State state) {
    this.state = state;
  }

  /**
   * Returns the Architecture of the current Instance
   *
   * @return architecture of the current Instance of enum-type Architectures
   */
  public final Architecture getArchitecture() {
    return architecture;
  }

  /**
   * Sets the Architecture of the current Instance
   *
   * @param architecture of the current Instance
   */
  public final void setArchitecture(Architecture architecture) {
    this.architecture = architecture;
  }

  /**
   * Return list of all action names.
   *
   * @return action names
   */
  public static final HashSet<String> getActionNames() {
    return actionNames;
  }

  /** Generate list with action names. */
  public static final HashSet<String> generateActionNames() {
    if (actionNames.isEmpty()) {
      for (int i = 0; i < beanFactory.getBeanDefinitionNames().length; i++) {
        if (beanFactory
            .getBean(beanFactory.getBeanDefinitionNames()[i])
            .toString()
            .contains("compute")) {
          actionNames.add(
              OcciConfig.getInstance().config.getString("occi.scheme")
                  + "/infrastructure/compute/action#"
                  + beanFactory.getBeanDefinitionNames()[i]);
        }
      }
    }
    return actionNames;
  }

  /** Generate list with actions. */
  public static final HashSet<Action> generateActionSet() {
    if (actionSet.isEmpty()) {
      for (int i = 0; i < beanFactory.getBeanDefinitionNames().length; i++) {
        if (beanFactory
            .getBean(beanFactory.getBeanDefinitionNames()[i])
            .toString()
            .contains("compute")) {
          actionSet.add((Action) beanFactory.getBean(beanFactory.getBeanDefinitionNames()[i]));
        }
      }
    }
    return actionSet;
  }

  /** Generate attribute List. */
  public static final void generateAttributeList() {
    if (attributes.isEmpty()) {
      // add all attributes to attribute list
      attributes.add("occi.compute.architecture");
      attributes.add("occi.compute.cores");
      attributes.add("occi.compute.hostname");
      attributes.add("occi.compute.memory");
      attributes.add("occi.compute.speed");
      attributes.add("occi.compute.state");
    }
  }

  /**
   * Return the compute attributes.
   *
   * @return attributes
   */
  public static final HashSet<String> getAttributes() {
    return attributes;
  }

  /** @param start the start to set */
  public final void setStart(Action start) {
    this.start = start;
  }

  /** @return the start */
  public final Action getStart() {
    return start;
  }

  /** @param stop the stop to set */
  public final void setStop(Action stop) {
    this.stop = stop;
  }

  /** @return the stop */
  public final Action getStop() {
    return stop;
  }

  /** @param restart the restart to set */
  public final void setRestart(Action restart) {
    this.restart = restart;
  }

  /** @return the restart */
  public final Action getRestart() {
    return restart;
  }

  /** @param suspend the suspend to set */
  public final void setSuspend(Action suspend) {
    this.suspend = suspend;
  }

  /** @return the suspend */
  public final Action getSuspend() {
    return suspend;
  }
}
Exemplo n.º 13
0
 public static void main(String[] args) {
   XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource("Beans.xml"));
   HelloWorld obj = (HelloWorld) factory.getBean("helloWorld");
   System.out.println("message:" + obj.getMessage());
 }
Exemplo n.º 14
0
 @SuppressWarnings("unchecked")
 public static XmlToMapParser<String, Object> makeParser(Resource resource) {
   XmlBeanFactory beanFactory = new XmlBeanFactory(resource);
   return beanFactory.getBean(XmlToMapParser.class);
 }
Exemplo n.º 15
0
  /**
   * 根据bean的 name获得对象
   *
   * @param beanName
   * @return Object
   */
  public static Object getInstance(String beanName) {

    return xmlBeanFactory.getBean(beanName);
  }