Exemplo n.º 1
0
  /**
   * Finds the right IaaS interface for a given instance.
   *
   * @param ma the managed application
   * @param instance the (root) instance associated with a IaaS
   * @return a IaaS interface
   * @throws IaasException if no IaaS interface was found
   */
  public IaasInterface findIaasInterface(ManagedApplication ma, Instance instance)
      throws IaasException {

    // FIXME: Not very "plug-in-like"
    IaasInterface iaasInterface;
    try {
      String installerName = instance.getComponent().getInstallerName();
      if (!"iaas".equalsIgnoreCase(installerName))
        throw new IaasException("Unsupported installer name: " + installerName);

      Map<String, String> props =
          IaasHelpers.loadIaasProperties(ma.getApplicationFilesDirectory(), instance);
      iaasInterface = findIaasHandler(props);
      if (iaasInterface == null)
        throw new IaasException("No IaaS handler was found for " + instance.getName() + ".");

      iaasInterface.setIaasProperties(props);

    } catch (IOException e) {
      throw new IaasException(e);

    } catch (InvalidIaasPropertiesException e) {
      throw new IaasException(e);
    }

    return iaasInterface;
  }
  @Test
  public void testMsgNotifHeartbeat_mustSendStoredMessages() throws Exception {

    this.managerWrapper.configureMessagingForTest();
    this.manager.reconfigure();
    TestClient msgClient = (TestClient) this.managerWrapper.getInternalMessagingClient();

    ManagedApplication ma =
        this.manager.applicationMngr().findManagedApplicationByName(this.app.getName());
    Assert.assertNotNull(ma);
    Assert.assertEquals(InstanceStatus.NOT_DEPLOYED, this.app.getMySqlVm().getStatus());
    Assert.assertNull(ma.getScopedInstanceToAwaitingMessages().get(this.app.getMySqlVm()));
    Assert.assertEquals(0, msgClient.allSentMessages.size());

    // Store messages
    this.manager
        .messagingMngr()
        .sendMessageSafely(ma, this.app.getMySqlVm(), new MsgCmdChangeBinding("tpl", "app-1"));
    this.manager
        .messagingMngr()
        .sendMessageSafely(ma, this.app.getMySqlVm(), new MsgCmdChangeBinding("tpl", "app-2"));
    this.manager
        .messagingMngr()
        .sendMessageSafely(ma, this.app.getMySqlVm(), new MsgCmdChangeBinding("tpl", "app-3"));
    Assert.assertEquals(
        3, ma.getScopedInstanceToAwaitingMessages().get(this.app.getMySqlVm()).size());
    Assert.assertEquals(0, msgClient.allSentMessages.size());

    // The ACK should send them
    MsgNotifHeartbeat msg =
        new MsgNotifHeartbeat(this.app.getName(), this.app.getMySqlVm(), "192.168.1.45");
    this.processor.processMessage(msg);

    Assert.assertEquals(InstanceStatus.DEPLOYED_STARTED, this.app.getMySqlVm().getStatus());
    Assert.assertNull(ma.getScopedInstanceToAwaitingMessages().get(this.app.getMySqlVm()));
    Assert.assertEquals(3, msgClient.allSentMessages.size());
  }