private void OnSave() {
    VmInterfaceModel model = (VmInterfaceModel) getWindow();
    VmNetworkInterface nic =
        model.getIsNew()
            ? new VmNetworkInterface()
            : (VmNetworkInterface) Cloner.clone((VmNetworkInterface) getSelectedItem());

    if (!model.Validate()) {
      return;
    }

    // Save changes.
    nic.setName((String) model.getName().getEntity());
    nic.setNetworkName(((network) model.getNetwork().getSelectedItem()).getname());
    if (model.getNicType().getSelectedItem() == null) {
      nic.setType(null);
    } else {
      nic.setType(((VmInterfaceType) model.getNicType().getSelectedItem()).getValue());
    }
    nic.setMacAddress(
        model.getMAC().getIsChangable()
            ? (model.getMAC().getEntity() == null
                ? null
                : ((String) (model.getMAC().getEntity())).toLowerCase())
            : model.getIsNew() ? "" : nic.getMacAddress());

    if (model.getIsNew()) {
      Frontend.RunMultipleAction(
          VdcActionType.AddVmTemplateInterface,
          new java.util.ArrayList<VdcActionParametersBase>(
              java.util.Arrays.asList(
                  new VdcActionParametersBase[] {
                    new AddVmTemplateInterfaceParameters(getEntityStronglyTyped().getId(), nic)
                  })),
          new IFrontendMultipleActionAsyncCallback() {
            @Override
            public void Executed(FrontendMultipleActionAsyncResult result) {

              Cancel();
            }
          },
          null);
    } else {
      Frontend.RunMultipleAction(
          VdcActionType.UpdateVmTemplateInterface,
          new java.util.ArrayList<VdcActionParametersBase>(
              java.util.Arrays.asList(
                  new VdcActionParametersBase[] {
                    new AddVmTemplateInterfaceParameters(getEntityStronglyTyped().getId(), nic)
                  })),
          new IFrontendMultipleActionAsyncCallback() {
            @Override
            public void Executed(FrontendMultipleActionAsyncResult result) {

              Cancel();
            }
          },
          null);
    }
  }
Ejemplo n.º 2
0
 @Before
 public void setUp() throws Exception {
   mockService =
       mock(
           GenericApiGWTServiceAsync.class,
           withSettings().extraInterfaces(ServiceDefTarget.class));
   fakeScheduler = new FakeGWTScheduler();
   CommunicationProvider communicationsProvider =
       new GWTRPCCommunicationProvider(mockService, mockXsrfService, mockXsrfRpcRequestBuilder);
   when(mockXsrfRpcRequestBuilder.getXsrfToken())
       .thenReturn(new XsrfToken("Something")); // $NON-NLS-1$
   OperationProcessor operationProcessor = new OperationProcessor(communicationsProvider);
   operationProcessor.setScheduler(fakeScheduler);
   VdcOperationManager operationsManager = new VdcOperationManager(operationProcessor);
   operationsManager.setLoggedIn(true);
   frontend =
       new Frontend(
           operationsManager,
           mockCanDoActionErrorsTranslator,
           mockVdsmErrorsTranslator,
           mockEventBus);
   frontend.setEventsHandler(mockEventsHandler);
   frontend.setConstants(mockConstants);
   frontend.frontendFailureEvent = mockFrontendFailureEvent;
   frontend.setLoginHandler(mockLoginHandler);
   when(mockAsyncQuery.getDel()).thenReturn(mockAsyncCallback);
   when(mockConstants.noCanDoActionMessage()).thenReturn(NO_MESSAGE);
 }
  public void OnManage() {
    ListModel model = (ListModel) getWindow();

    java.util.ArrayList<EntityModel> items = Linq.<EntityModel>Cast(model.getItems());
    java.util.ArrayList<network> networks = Linq.<network>Cast(getItems());

    if (getEntity() == null) {
      Cancel();
      return;
    }

    java.util.ArrayList<VdcActionParametersBase> prms1 =
        new java.util.ArrayList<VdcActionParametersBase>();
    for (EntityModel a : items) {
      boolean value = false;
      for (network b : networks) {
        if (b.getId().equals(((network) a.getEntity()).getId())) {
          value = true;
          break;
        }
      }
      if (a.getIsSelected() && !value) {
        prms1.add(new AttachNetworkToVdsGroupParameter(getEntity(), (network) a.getEntity()));
      }
    }

    // Call the command only if necessary (i.e. only if there are paramters):
    if (prms1.size() > 0) {
      Frontend.RunMultipleAction(VdcActionType.AttachNetworkToVdsGroup, prms1);
    }

    java.util.ArrayList<VdcActionParametersBase> prms2 =
        new java.util.ArrayList<VdcActionParametersBase>();
    for (EntityModel a : items) {
      boolean value = true;
      for (network b : networks) {
        if (b.getId().equals(((network) a.getEntity()).getId())) {
          value = false;
          break;
        }
      }
      if (!a.getIsSelected() && !value) {
        prms2.add(new AttachNetworkToVdsGroupParameter(getEntity(), (network) a.getEntity()));
      }
    }

    // Call the command only if necessary (i.e. only if there are paramters):
    if (prms2.size() > 0) {
      Frontend.RunMultipleAction(VdcActionType.DetachNetworkToVdsGroup, prms2);
    }

    Cancel();
  }
  public void SetAsDisplay() {
    network network = (network) getSelectedItem();

    Frontend.RunAction(
        VdcActionType.UpdateDisplayToVdsGroup,
        new DisplayNetworkToVdsGroupParameters(getEntity(), network, true));
  }
  private void OnRemove() {
    ConfirmationModel model = (ConfirmationModel) getWindow();

    if (model.getProgress() != null) {
      return;
    }

    java.util.ArrayList<VdcActionParametersBase> list =
        new java.util.ArrayList<VdcActionParametersBase>();
    for (Object item : getSelectedItems()) {
      VmNetworkInterface a = (VmNetworkInterface) item;
      list.add(
          new RemoveVmTemplateInterfaceParameters(getEntityStronglyTyped().getId(), a.getId()));
    }

    model.StartProgress(null);

    Frontend.RunMultipleAction(
        VdcActionType.RemoveVmTemplateInterface,
        list,
        new IFrontendMultipleActionAsyncCallback() {
          @Override
          public void Executed(FrontendMultipleActionAsyncResult result) {

            ConfirmationModel localModel = (ConfirmationModel) result.getState();
            localModel.StopProgress();
            Cancel();
          }
        },
        model);
  }
Ejemplo n.º 6
0
 public void dropTable(byte[] thriftDropTableParams)
     throws ImpalaException, MetaException, NoSuchObjectException, org.apache.thrift.TException,
         AlreadyExistsException, InvalidOperationException, InvalidObjectException {
   TDropTableParams params = new TDropTableParams();
   deserializeThrift(params, thriftDropTableParams);
   frontend.dropTable(params.getDb(), params.getTable_name(), params.isIf_exists());
 }
  public void OnSelectHost() {
    MoveHost model = (MoveHost) getWindow();

    if (model.getProgress() != null) {
      return;
    }

    if (!model.Validate()) {
      return;
    }

    model.setSelectedHosts(new java.util.ArrayList<VDS>());
    for (EntityModel a : Linq.<EntityModel>Cast(model.getItems())) {
      if (a.getIsSelected()) {
        model.getSelectedHosts().add((VDS) a.getEntity());
      }
    }

    VDSGroup cluster = (VDSGroup) model.getCluster().getSelectedItem();

    java.util.ArrayList<VdcActionParametersBase> paramerterList =
        new java.util.ArrayList<VdcActionParametersBase>();
    for (VDS host : model.getSelectedHosts()) {
      // Try to change host's cluster as neccessary.
      if (host.getvds_group_id() != null && !host.getvds_group_id().equals(cluster.getId())) {
        paramerterList.add(new ChangeVDSClusterParameters(cluster.getId(), host.getId()));
      }
    }
    model.StartProgress(null);
    Frontend.RunMultipleAction(
        VdcActionType.ChangeVDSCluster,
        paramerterList,
        new IFrontendMultipleActionAsyncCallback() {
          @Override
          public void Executed(FrontendMultipleActionAsyncResult result) {

            ClusterGuideModel clusterGuideModel = (ClusterGuideModel) result.getState();
            java.util.ArrayList<VDS> hosts =
                ((MoveHost) clusterGuideModel.getWindow()).getSelectedHosts();
            java.util.ArrayList<VdcReturnValueBase> retVals =
                (java.util.ArrayList<VdcReturnValueBase>) result.getReturnValue();
            if (retVals != null && hosts.size() == retVals.size()) {
              int i = 0;
              for (VDS selectedHost : hosts) {
                if (selectedHost.getstatus() == VDSStatus.PendingApproval
                    && retVals.get(i) != null
                    && retVals.get(i).getSucceeded()) {
                  Frontend.RunAction(
                      VdcActionType.ApproveVds, new ApproveVdsParameters(selectedHost.getId()));
                }
              }
              i++;
            }
            clusterGuideModel.getWindow().StopProgress();
            clusterGuideModel.Cancel();
            clusterGuideModel.PostAction();
          }
        },
        this);
  }
Ejemplo n.º 8
0
 /**
  * Return an explain plan based on thriftQueryRequest, a serialized TQueryRequest. This call is
  * thread-safe.
  */
 public String getExplainPlan(byte[] thriftQueryRequest) throws ImpalaException {
   TClientRequest request = new TClientRequest();
   deserializeThrift(request, thriftQueryRequest);
   String plan = frontend.getExplainString(request);
   LOG.info("Explain plan: " + plan);
   return plan;
 }
Ejemplo n.º 9
0
 /**
  * Run the following test case.
  *
  * <ol>
  *   <li>Run MultipleActions with multiple actions, first failure, and second success.
  *   <li>Check to make sure the failure callback is called for the first action
  *   <li>Make sure the success callback is never called for the second action
  * </ol>
  */
 @Test
 public void testrunMultipleActions_multipleaction_success_first_failure_second_success() {
   List<VdcActionType> actionTypes = new ArrayList<VdcActionType>();
   actionTypes.add(VdcActionType.AddDisk);
   actionTypes.add(VdcActionType.AddBricksToGlusterVolume);
   List<VdcActionParametersBase> testParameters = new ArrayList<VdcActionParametersBase>();
   testParameters.add(new VdcActionParametersBase());
   testParameters.add(new VdcActionParametersBase());
   List<IFrontendActionAsyncCallback> callbacks = new ArrayList<IFrontendActionAsyncCallback>();
   callbacks.add(mockActionCallback);
   callbacks.add(mockActionCallback);
   Object testState = new Object();
   frontend.runMultipleActions(
       actionTypes, testParameters, callbacks, mockActionFailureCallback, testState);
   verify(mockService)
       .runAction(eq(VdcActionType.AddDisk), eq(testParameters.get(0)), callbackAction.capture());
   VdcReturnValueBase returnValue = new VdcReturnValueBase();
   returnValue.setCanDoAction(false);
   returnValue.setSucceeded(false);
   callbackAction.getValue().onSuccess(returnValue);
   verify(mockActionFailureCallback).executed(callbackParam.capture());
   assertEquals(callbackParam.getValue().getReturnValue(), returnValue);
   // Second call to runAction, the size of the parameters should have decreased
   verify(mockService, never())
       .runAction(
           eq(VdcActionType.AddBricksToGlusterVolume),
           eq(testParameters.get(0)),
           callbackAction.capture());
 }
Ejemplo n.º 10
0
 /**
  * Run the following test case.
  *
  * <ol>
  *   <li>Run a single action
  *   <li>Return logical failure, canDoAction=true.
  *   <li>Get succeeded is false.
  *   <li>IsSyncronious is true.
  *   <li>showDialog is true.
  *   <li>Check to make sure the failure event is fired
  *   <li>Check to make sure the callback is called
  * </ol>
  *
  * Test just the handler method.
  */
 @Test
 public void testHandleActionResult_SucceededFalse() {
   Object testState = new Object();
   VdcActionParametersBase testParameters = new VdcActionParametersBase();
   VdcReturnValueBase returnValue = new VdcReturnValueBase();
   returnValue.setCanDoAction(true);
   returnValue.setIsSyncronious(true);
   returnValue.setSucceeded(false); // Yes this is the default, but to make sure.
   VdcFault testFault = new VdcFault();
   returnValue.setFault(testFault);
   frontend.handleActionResult(
       VdcActionType.AddDisk, testParameters, returnValue, mockActionCallback, testState, true);
   verify(mockActionCallback).executed(callbackParam.capture());
   assertEquals(
       "Parameters should match",
       testParameters,
       callbackParam.getValue().getParameters()); // $NON-NLS-1$
   assertEquals(
       "Result should match",
       returnValue,
       callbackParam.getValue().getReturnValue()); // $NON-NLS-1$
   assertEquals(
       "States should match", testState, callbackParam.getValue().getState()); // $NON-NLS-1$
   assertEquals(
       "Action type should match",
       VdcActionType.AddDisk, // $NON-NLS-1$
       callbackParam.getValue().getActionType());
   verify(mockEventsHandler).runActionExecutionFailed(VdcActionType.AddDisk, testFault);
 }
Ejemplo n.º 11
0
 /**
  * Run the following test case.
  *
  * <ol>
  *   <li>Run a single action
  *   <li>Return success.
  *   <li>Check to make sure the callback is called
  * </ol>
  */
 @Test
 public void testrunActionImpl_success() {
   Object testState = new Object();
   VdcActionParametersBase testParameters = new VdcActionParametersBase();
   frontend.runAction(VdcActionType.AddDisk, testParameters, mockActionCallback, testState, false);
   verify(mockService)
       .runAction(eq(VdcActionType.AddDisk), eq(testParameters), callbackAction.capture());
   VdcReturnValueBase returnValue = new VdcReturnValueBase();
   callbackAction.getValue().onSuccess(returnValue);
   verify(mockActionCallback).executed(callbackParam.capture());
   assertEquals(
       "Parameters should match",
       testParameters,
       callbackParam.getValue().getParameters()); // $NON-NLS-1$
   assertEquals(
       "Result should match",
       returnValue,
       callbackParam.getValue().getReturnValue()); // $NON-NLS-1$
   assertEquals(
       "States should match", testState, callbackParam.getValue().getState()); // $NON-NLS-1$
   assertEquals(
       "Action type should match",
       VdcActionType.AddDisk, // $NON-NLS-1$
       callbackParam.getValue().getActionType());
 }
Ejemplo n.º 12
0
 /**
  * Run the following test case.
  *
  * <ol>
  *   <li>Run a multiple search query, with multiple requests, with *win* or *lin* as the
  *       parameter, searching for VMs
  *   <li>Force a special failure with an HTTP status code = 0, this is an ignored failure (escape
  *       key pressed)
  *   <li>Check to make sure the appropriate query start and query complete events are fired
  * </ol>
  */
 @Test
 public void testRunMultipleQueries_ignored_failure_multiple() {
   // Don't immediately call process until both queries are in the queue.
   fakeScheduler.setThreshold(2);
   ArrayList<VdcQueryType> queryTypeList = new ArrayList<VdcQueryType>();
   queryTypeList.add(VdcQueryType.Search);
   queryTypeList.add(VdcQueryType.Search);
   ArrayList<VdcQueryParametersBase> queryParamsList = new ArrayList<VdcQueryParametersBase>();
   queryParamsList.add(new SearchParameters("*win*", SearchType.VM)); // $NON-NLS-1$
   queryParamsList.add(new SearchParameters("*lin*", SearchType.VM)); // $NON-NLS-1$
   frontend.runMultipleQueries(
       queryTypeList, queryParamsList, mockMultipleQueryCallback, "test"); // $NON-NLS-1$
   StatusCodeException exception = new StatusCodeException(0, "0 status code"); // $NON-NLS-1$
   // Repeat 4 times, because of retries.
   for (int i = 1; i < RETRY_COUNT; i++) {
     // Reset the count so we can re-add both entries again.
     fakeScheduler.resetCount();
     verify(mockService, times(i))
         .RunMultipleQueries(
             eq(queryTypeList), eq(queryParamsList), callbackMultipleQueries.capture());
     // Call the failure handler.
     callbackMultipleQueries.getValue().onFailure(exception);
   }
   verify(mockFrontendFailureEvent, never())
       .raise(eq(Frontend.class), any(FrontendFailureEventArgs.class));
 }
Ejemplo n.º 13
0
 /**
  * Run the following test case.
  *
  * <ol>
  *   <li>Run a multiple search query, with only multiple requests, with *win* / *lin* as the
  *       parameter, searching for VMs
  *   <li>Force a failure with an HTTP status code = 404
  *   <li>Check to make sure the appropriate query start and query complete events are fired
  * </ol>
  */
 @Test
 public void testRunMultipleQueries_404_failure() {
   // Don't immediately call process until both queries are in the queue.
   fakeScheduler.setThreshold(2);
   when(mockConstants.requestToServerFailedWithCode())
       .thenReturn("A Request to the Server failed with the following Status Code"); // $NON-NLS-1$
   ArrayList<VdcQueryType> queryTypeList = new ArrayList<VdcQueryType>();
   queryTypeList.add(VdcQueryType.Search);
   queryTypeList.add(VdcQueryType.Search);
   ArrayList<VdcQueryParametersBase> queryParamsList = new ArrayList<VdcQueryParametersBase>();
   queryParamsList.add(new SearchParameters("*win*", SearchType.VM)); // $NON-NLS-1$
   queryParamsList.add(new SearchParameters("*lin*", SearchType.VM)); // $NON-NLS-1$
   frontend.runMultipleQueries(
       queryTypeList, queryParamsList, mockMultipleQueryCallback, "test"); // $NON-NLS-1$
   StatusCodeException exception =
       new StatusCodeException(HttpServletResponse.SC_NOT_FOUND, "404 status code"); // $NON-NLS-1$
   // Repeat 4 times, because of retries.
   for (int i = 1; i < RETRY_COUNT; i++) {
     // Reset the count so we can re-add both entries again.
     fakeScheduler.resetCount();
     verify(mockService, times(i))
         .RunMultipleQueries(
             eq(queryTypeList), eq(queryParamsList), callbackMultipleQueries.capture());
     // Call the failure handler.
     callbackMultipleQueries.getValue().onFailure(exception);
   }
   ArgumentCaptor<FrontendFailureEventArgs> eventArgs =
       ArgumentCaptor.forClass(FrontendFailureEventArgs.class);
   verify(mockFrontendFailureEvent).raise(eq(Frontend.class), eventArgs.capture());
   assertEquals(
       "Message text didn't match", //$NON-NLS-1$
       "A Request to the Server failed with the following Status Code: 404", //$NON-NLS-1$
       eventArgs.getValue().getMessage().getText());
 }
Ejemplo n.º 14
0
 /**
  * Run the following test case.
  *
  * <ol>
  *   <li>Run a multiple search query, with multiple requests, with *win* or *lin* as the
  *       parameter, searching for VMs
  *   <li>Return success, the success status is succeeded, with a failure in the result set
  *   <li>Check to make sure the appropriate query start and query complete events are fired
  * </ol>
  */
 @Test
 public void testRunMultipleQueries_multiple_success_and_failure() {
   // Don't immediately call process until both queries are in the queue.
   fakeScheduler.setThreshold(2);
   ArrayList<VdcQueryType> queryTypeList = new ArrayList<VdcQueryType>();
   queryTypeList.add(VdcQueryType.Search);
   queryTypeList.add(VdcQueryType.Search);
   ArrayList<VdcQueryParametersBase> queryParamsList = new ArrayList<VdcQueryParametersBase>();
   queryParamsList.add(new SearchParameters("*win*", SearchType.VM)); // $NON-NLS-1$
   queryParamsList.add(new SearchParameters("*lin*", SearchType.VM)); // $NON-NLS-1$
   frontend.runMultipleQueries(
       queryTypeList, queryParamsList, mockMultipleQueryCallback, "test"); // $NON-NLS-1$
   verify(mockService)
       .RunMultipleQueries(
           eq(queryTypeList), eq(queryParamsList), callbackMultipleQueries.capture());
   // Call the failure handler.
   List<VdcQueryReturnValue> result = new ArrayList<VdcQueryReturnValue>();
   result.add(new VdcQueryReturnValue());
   result.get(0).setSucceeded(false);
   result.add(new VdcQueryReturnValue());
   result.get(1).setSucceeded(true);
   ArgumentCaptor<FrontendMultipleQueryAsyncResult> multipleResultCaptor =
       ArgumentCaptor.forClass(FrontendMultipleQueryAsyncResult.class);
   callbackMultipleQueries.getValue().onSuccess((ArrayList<VdcQueryReturnValue>) result);
   verify(mockMultipleQueryCallback).executed(multipleResultCaptor.capture());
   assertEquals(
       "callback result much match",
       result, //$NON-NLS-1$
       multipleResultCaptor.getValue().getReturnValues());
 }
Ejemplo n.º 15
0
 public void createDatabase(byte[] thriftCreateDbParams)
     throws ImpalaException, MetaException, org.apache.thrift.TException, AlreadyExistsException,
         InvalidObjectException {
   TCreateDbParams params = new TCreateDbParams();
   deserializeThrift(params, thriftCreateDbParams);
   frontend.createDatabase(
       params.getDb(), params.getComment(), params.getLocation(), params.isIf_not_exists());
 }
  @Override
  protected void AsyncSearch() {
    super.AsyncSearch();

    setAsyncResult(
        Frontend.RegisterQuery(
            VdcQueryType.GetTemplateInterfacesByTemplateId,
            new GetVmTemplateParameters(getEntityStronglyTyped().getId())));
    setItems(getAsyncResult().getData());
  }
  @Override
  protected void AsyncSearch() {
    super.AsyncSearch();

    setAsyncResult(
        Frontend.RegisterQuery(
            VdcQueryType.GetAllNetworksByClusterId,
            new VdsGroupQueryParamenters(getEntity().getID())));
    setItems(getAsyncResult().getData());
  }
Ejemplo n.º 18
0
 /**
  * Run the following test case.
  *
  * <ol>
  *   <li>Run a search query, with *win* as the parameter, searching for VMs
  *   <li>Immediately, before returning a failure result, call the same run query again, total 3
  *       times
  *   <li>The callback is NOT marked to handle failures
  *   <li>Force a failure with an HTTP status code = 404 (file not found)
  *   <li>Check to make sure only one query is called. Due to the second and third being a
  *       duplicate
  *   <li>Check to make sure the appropriate query start and query complete events are fired
  * </ol>
  */
 @Test
 public void testRunQuery_failure_404_with_pending_3times() {
   VdcQueryParametersBase testParameters =
       new SearchParameters("*win*", SearchType.VM); // $NON-NLS-1$
   frontend.runQuery(VdcQueryType.Search, testParameters, mockAsyncQuery, false);
   frontend.runQuery(VdcQueryType.Search, testParameters, mockAsyncQuery, false);
   frontend.runQuery(VdcQueryType.Search, testParameters, mockAsyncQuery, false);
   StatusCodeException exception =
       new StatusCodeException(HttpServletResponse.SC_NOT_FOUND, "404 status code"); // $NON-NLS-1$
   // Repeat 4 times, because of retries.
   for (int i = 1; i < RETRY_COUNT; i++) {
     // Verify that only one request is executed, until the first one is complete.
     verify(mockService, times(i))
         .RunQuery(eq(VdcQueryType.Search), eq(testParameters), callback.capture());
     // Call the failure handler.
     callback.getValue().onFailure(exception);
   }
   verify(mockEventsHandler, atLeastOnce()).runQueryFailed(null);
 }
Ejemplo n.º 19
0
 /**
  * Run the following test case.
  *
  * <ol>
  *   <li>Run a multiple actions, with multiple actions
  *   <li>Have one of them fail. The rest is successful
  *   <li>Check to make sure the failure event is never fired
  * </ol>
  */
 @SuppressWarnings("unchecked")
 @Test
 public void testrunMultipleActionsMultipleSuccess_oneFailure() {
   // Don't immediately call process until both queries are in the queue.
   fakeScheduler.setThreshold(2);
   ArrayList<VdcActionParametersBase> parameters = new ArrayList<VdcActionParametersBase>();
   parameters.add(new VdcActionParametersBase());
   parameters.add(new VdcActionParametersBase());
   parameters.get(0).setCommandId(Guid.Empty);
   Object testState = new Object();
   frontend.runMultipleAction(
       VdcActionType.AddLocalStorageDomain,
       parameters,
       false,
       mockMultipleActionCallback,
       testState);
   verify(mockService)
       .runMultipleActions(
           eq(VdcActionType.AddLocalStorageDomain),
           eq(parameters),
           eq(false),
           eq(false),
           callbackMultipleActions.capture());
   ArrayList<VdcReturnValueBase> returnValues = new ArrayList<VdcReturnValueBase>();
   returnValues.add(new VdcReturnValueBase());
   returnValues.add(new VdcReturnValueBase());
   returnValues.get(0).setCanDoAction(true);
   returnValues.get(1).setCanDoAction(false);
   callbackMultipleActions.getValue().onSuccess(returnValues);
   verify(mockFrontendFailureEvent, never())
       .raise(eq(Frontend.class), (FrontendFailureEventArgs) any());
   @SuppressWarnings("rawtypes")
   ArgumentCaptor<ArrayList> failedCaptor = ArgumentCaptor.forClass(ArrayList.class);
   verify(mockEventsHandler)
       .runMultipleActionFailed(eq(VdcActionType.AddLocalStorageDomain), failedCaptor.capture());
   assertEquals("There is one failure", 1, failedCaptor.getValue().size()); // $NON-NLS-1$
   assertEquals(
       "Failures should match",
       returnValues.get(1),
       failedCaptor.getValue().get(0)); // $NON-NLS-1$
   verify(mockMultipleActionCallback).executed(callbackMultipleParam.capture());
   assertEquals(
       "Parameters should match",
       parameters, //$NON-NLS-1$
       callbackMultipleParam.getValue().getParameters());
   assertEquals(
       "Result should match",
       returnValues, //$NON-NLS-1$
       callbackMultipleParam.getValue().getReturnValue());
   assertEquals(
       "States should match",
       testState,
       callbackMultipleParam.getValue().getState()); // $NON-NLS-1$
 }
  public void OnAddHost() {
    CancelConfirm();

    HostModel model = (HostModel) getWindow();

    if (model.getProgress() != null) {
      return;
    }

    if (!model.Validate()) {
      return;
    }

    // Save changes.
    VDS host = new VDS();
    host.setvds_name((String) model.getName().getEntity());
    host.sethost_name((String) model.getHost().getEntity());
    host.setManagmentIp((String) model.getManagementIp().getEntity());
    host.setport((Integer) model.getPort().getEntity());
    host.setvds_group_id(((VDSGroup) model.getCluster().getSelectedItem()).getId());
    host.setpm_enabled((Boolean) model.getIsPm().getEntity());
    host.setpm_user(
        (Boolean) model.getIsPm().getEntity() ? (String) model.getPmUserName().getEntity() : null);
    host.setpm_password(
        (Boolean) model.getIsPm().getEntity() ? (String) model.getPmPassword().getEntity() : null);
    host.setpm_type(
        (Boolean) model.getIsPm().getEntity()
            ? (String) model.getPmType().getSelectedItem()
            : null);
    host.setPmOptionsMap(
        (Boolean) model.getIsPm().getEntity()
            ? new ValueObjectMap(model.getPmOptionsMap(), false)
            : null);

    AddVdsActionParameters vdsActionParams = new AddVdsActionParameters();
    vdsActionParams.setvds(host);
    vdsActionParams.setVdsId(host.getId());
    vdsActionParams.setRootPassword((String) model.getRootPassword().getEntity());

    model.StartProgress(null);

    Frontend.RunAction(
        VdcActionType.AddVds,
        vdsActionParams,
        new IFrontendActionAsyncCallback() {
          @Override
          public void Executed(FrontendActionAsyncResult result) {

            ClusterGuideModel localModel = (ClusterGuideModel) result.getState();
            localModel.PostOnAddHost(result.getReturnValue());
          }
        },
        this);
  }
Ejemplo n.º 21
0
  /** Executes a HiveServer2 metadata operation and returns a TMetadataOpResponse */
  public byte[] execHiveServer2MetadataOp(byte[] metadataOpsParams) throws ImpalaException {
    TMetadataOpRequest params = new TMetadataOpRequest();
    deserializeThrift(params, metadataOpsParams);
    TMetadataOpResponse result = frontend.execHiveServer2MetadataOp(params);

    TSerializer serializer = new TSerializer(protocolFactory);
    try {
      return serializer.serialize(result);
    } catch (TException e) {
      throw new InternalException(e.getMessage());
    }
  }
Ejemplo n.º 22
0
  @After
  public void tearDown() throws Exception {
    // Make sure that the query start and end have been called at least once.
    // Some of the tests might call it more than once.
    verify(queryStartEvent, atLeastOnce()).raise(Frontend.class, EventArgs.EMPTY);
    verify(queryCompleteEvent, atLeastOnce()).raise(Frontend.class, EventArgs.EMPTY);

    // Make sure the context is correct
    assertEquals(
        "Context should be 'test'",
        frontend.getCurrentContext(),
        "test"); //$NON-NLS-1$ //$NON-NLS-2$
  }
Ejemplo n.º 23
0
 /**
  * Run the following test case.
  *
  * <ol>
  *   <li>Attempt to log-off
  *   <li>Have the log-off succeed
  *   <li>Make sure the onSuccess handler is called
  *   <li>Make sure the onLogout handler is called
  * </ol>
  */
 @Test
 public void testLogoffAsync_success() {
   Object model = new Object();
   when(mockAsyncQuery.getModel()).thenReturn(model);
   DbUser testUser = new DbUser();
   testUser.setLoginName("testUser"); // $NON-NLS-1$
   frontend.logoffAsync(testUser, mockAsyncQuery);
   verify(mockService).logOff(eq(testUser), callbackAction.capture());
   VdcReturnValueBase returnValue = new VdcReturnValueBase();
   callbackAction.getValue().onSuccess(returnValue);
   verify(mockAsyncCallback).onSuccess(model, returnValue);
   verify(mockLoginHandler).onLogout();
 }
Ejemplo n.º 24
0
 /**
  * Run the following test case.
  *
  * <ol>
  *   <li>Run a single action
  *   <li>Force a special failure with an HTTP status code = 0, this is an ignored failure
  *   <li>Check to make sure the failure event is never fired
  *   <li>Check to make sure the callback is never called
  * </ol>
  */
 @Test
 public void testrunActionImpl_ignored_failure() {
   Object testState = new Object();
   VdcActionParametersBase testParameters = new VdcActionParametersBase();
   frontend.runAction(VdcActionType.AddDisk, testParameters, mockActionCallback, testState, false);
   verify(mockService)
       .runAction(eq(VdcActionType.AddDisk), eq(testParameters), callbackAction.capture());
   StatusCodeException exception = new StatusCodeException(0, "0 status code"); // $NON-NLS-1$
   callbackAction.getValue().onFailure(exception);
   verify(mockFrontendFailureEvent, never())
       .raise(eq(Frontend.class), (FrontendFailureEventArgs) any());
   verify(mockActionCallback, never()).executed(any(FrontendActionAsyncResult.class));
 }
Ejemplo n.º 25
0
  /**
   * Returns a list of the columns making up a table. The argument is a serialized
   * TDescribeTableParams object. The return type is a serialised TDescribeTableResult object.
   *
   * @see Frontend#describeTable
   */
  public byte[] describeTable(byte[] thriftDescribeTableParams) throws ImpalaException {
    TDescribeTableParams params = new TDescribeTableParams();
    deserializeThrift(params, thriftDescribeTableParams);
    TDescribeTableResult result = new TDescribeTableResult();
    result.setColumns(frontend.describeTable(params.getDb(), params.getTable_name()));

    TSerializer serializer = new TSerializer(protocolFactory);
    try {
      return serializer.serialize(result);
    } catch (TException e) {
      throw new InternalException(e.getMessage());
    }
  }
  private void ChangePassword() {
    VdcReturnValueBase returnValue =
        Frontend.RunAction(
            VdcActionType.ChangeUserPassword,
            new ChangeUserPasswordParameters(
                (String) getUserName().getEntity(),
                (String) getPassword().getEntity(),
                (String) getNewPassword().getEntity(),
                (String) getDomain().getSelectedItem()));

    if (returnValue != null && returnValue.getSucceeded()) {
      // TODO:
    }
  }
Ejemplo n.º 27
0
 /**
  * Run the following test case.
  *
  * <ol>
  *   <li>Run a search query, with *win* as the parameter, searching for VMs
  *   <li>Return success, the success status is succeeded
  *   <li>No success converter defined
  *   <li>Check to make sure the appropriate query start and query complete events are fired
  * </ol>
  */
 @Test
 public void testRunQuery_success_succeeded_eventshandler_noconverter() {
   Object mockModel = new Object();
   when(mockAsyncQuery.getModel()).thenReturn(mockModel);
   VdcQueryParametersBase testParameters =
       new SearchParameters("*win*", SearchType.VM); // $NON-NLS-1$
   frontend.runQuery(VdcQueryType.Search, testParameters, mockAsyncQuery, false);
   verify(mockService).RunQuery(eq(VdcQueryType.Search), eq(testParameters), callback.capture());
   VdcQueryReturnValue mockReturnValue = new VdcQueryReturnValue();
   mockReturnValue.setSucceeded(true);
   callback.getValue().onSuccess(mockReturnValue);
   verify(mockAsyncQuery).setOriginalReturnValue(mockReturnValue);
   verify(mockAsyncCallback).onSuccess(mockModel, mockReturnValue);
 }
Ejemplo n.º 28
0
 /**
  * Run the following test case.
  *
  * <ol>
  *   <li>Run a search query, with *win* as the parameter, searching for VMs
  *   <li>The callback is NOT marked to handle failures
  *   <li>The failure is a not logged in failure
  *   <li>Return success, but the success status is !succeeded (business logic failure/not logged
  *       in)
  *   <li>Check to make sure the appropriate query start and query complete events are fired
  * </ol>
  */
 @Test
 public void testRunQuery_success_not_succeeded_eventshandler_nocallbackhandler() {
   VdcQueryParametersBase testParameters =
       new SearchParameters("*win*", SearchType.VM); // $NON-NLS-1$
   frontend.runQuery(VdcQueryType.Search, testParameters, mockAsyncQuery, false);
   verify(mockService).RunQuery(eq(VdcQueryType.Search), eq(testParameters), callback.capture());
   VdcQueryReturnValue mockReturnValue = new VdcQueryReturnValue();
   mockReturnValue.setExceptionString("USER_IS_NOT_LOGGED_IN"); // $NON-NLS-1$
   // Return value set to failure
   mockReturnValue.setSucceeded(false);
   callback.getValue().onSuccess(mockReturnValue);
   // Make sure the not logged in event is called
   verify(mockFrontendNotLoggedInEvent).raise(Frontend.class, EventArgs.EMPTY);
 }
Ejemplo n.º 29
0
 /**
  * Run the following test case.
  *
  * <ol>
  *   <li>Run a search query, with *win* as the parameter, searching for VMs
  *   <li>The callback is NOT marked to handle failures
  *   <li>Force a special failure with an HTTP status code = 0, this is an ignored failure
  *   <li>Check to make sure the appropriate query start and query complete events are fired
  * </ol>
  */
 @Test
 public void testRunQuery_ignored_failure() {
   VdcQueryParametersBase testParameters =
       new SearchParameters("*win*", SearchType.VM); // $NON-NLS-1$
   StatusCodeException exception = new StatusCodeException(0, "0 status code"); // $NON-NLS-1$
   frontend.runQuery(VdcQueryType.Search, testParameters, mockAsyncQuery, false);
   // Repeat 4 times, because of retries.
   for (int i = 1; i < RETRY_COUNT; i++) {
     verify(mockService, times(i))
         .RunQuery(eq(VdcQueryType.Search), eq(testParameters), callback.capture());
     // Call the failure handler.
     callback.getValue().onFailure(exception);
   }
 }
Ejemplo n.º 30
0
 /**
  * Run the following test case.
  *
  * <ol>
  *   <li>Attempt to login
  *   <li>Have the login fail with a status code of 404
  *   <li>Check to make sure the callback is called
  *   <li>Check to make sure the events handler is called
  *   <li>Make sure the frontend failure handler is called
  * </ol>
  */
 @Test
 public void testLoginAsync_404_failure() {
   String testUser = "******"; // $NON-NLS-1$
   String testPassword = "******"; // $NON-NLS-1$
   String testProfile = "testprofile"; // $NON-NLS-1$
   frontend.initLoggedInUser(new DbUser(), testPassword);
   when(mockAsyncQuery.isHandleFailure()).thenReturn(Boolean.TRUE);
   frontend.loginAsync(testUser, testPassword, testProfile, false, mockAsyncQuery);
   verify(mockService)
       .login(
           eq(testUser),
           eq(testPassword),
           eq(testProfile),
           eq(VdcActionType.LoginUser),
           callbackAction.capture());
   StatusCodeException exception =
       new StatusCodeException(HttpServletResponse.SC_NOT_FOUND, "404 status code"); // $NON-NLS-1$
   callbackAction.getValue().onFailure(exception);
   verify(mockEventsHandler).runQueryFailed(null);
   verify(mockFrontendFailureEvent).raise(eq(Frontend.class), (EventArgs) any());
   assertNull("Logged in user should be null", frontend.getLoggedInUser()); // $NON-NLS-1$
   verify(mockAsyncCallback).onSuccess(any(), any());
 }