protected List<ClusterResponse> getClusterResponses() { Pair<List<? extends Cluster>, Integer> result = _mgr.searchForClusters(this); List<ClusterResponse> clusterResponses = new ArrayList<ClusterResponse>(); for (Cluster cluster : result.first()) { ClusterResponse clusterResponse = _responseGenerator.createClusterResponse(cluster, showCapacities); clusterResponse.setObjectName("cluster"); clusterResponses.add(clusterResponse); } return clusterResponses; }
@Test public void testCreateSuccess() { Configuration cfg = Mockito.mock(Configuration.class); listCfgsByCmd._mgr = mgr; listCfgsByCmd._responseGenerator = responseGenerator; List<Configuration> configList = new ArrayList<Configuration>(); configList.add(cfg); Pair<List<? extends Configuration>, Integer> result = new Pair<List<? extends Configuration>, Integer>(configList, 1); try { Mockito.when(mgr.searchForConfigurations(listCfgsByCmd)).thenReturn(result); } catch (Exception e) { Assert.fail("Received exception when success expected " + e.getMessage()); } ConfigurationResponse cfgResponse = new ConfigurationResponse(); cfgResponse.setName("Test case"); Mockito.when(responseGenerator.createConfigurationResponse(cfg)).thenReturn(cfgResponse); listCfgsByCmd.execute(); Mockito.verify(responseGenerator).createConfigurationResponse(cfg); ListResponse<ConfigurationResponse> actualResponse = (ListResponse<ConfigurationResponse>)listCfgsByCmd.getResponseObject(); Assert.assertEquals(cfgResponse, actualResponse.getResponses().get(0)); }
@Override public void execute() { if (getClusterId() == null) { _mgr.updateHostPassword(this); _resourceService.updateHostPassword(this); } else { _mgr.updateClusterPassword(this); _resourceService.updateClusterPassword(this); } setResponseObject(new SuccessResponse(getCommandName())); } }
public String getPassword() { if (Strings.isNullOrEmpty(password)) { password = _mgr.generateRandomPassword(); } return password; }
@Test public void testCreateSuccess() { updateHostPasswordCmd._mgr = managementServer; updateHostPasswordCmd._resourceService = resourceService; updateHostPasswordCmd._responseGenerator = responseGenerator; try { Mockito.when(managementServer.updateHostPassword(updateHostPasswordCmd)).thenReturn(true); } catch (final Exception e) { fail("Received exception when success expected " + e.getMessage()); } try { updateHostPasswordCmd.execute(); } catch (final ServerApiException exception) { assertEquals("Failed to update config", exception.getDescription()); } assertFalse("The attribute updatePasswdOnHost should be false, but it isn't.", updateHostPasswordCmd.getUpdatePasswdOnHost()); verify(managementServer, times(1)).updateHostPassword(updateHostPasswordCmd); } }
@Override public void execute() { Pair<List<? extends Vlan>, Integer> vlans = _mgr.searchForVlans(this); ListResponse<VlanIpRangeResponse> response = new ListResponse<VlanIpRangeResponse>(); List<VlanIpRangeResponse> vlanResponses = new ArrayList<VlanIpRangeResponse>(); for (Vlan vlan : vlans.first()) { VlanIpRangeResponse vlanResponse = _responseGenerator.createVlanIpRangeResponse(vlan); vlanResponse.setObjectName("vlaniprange"); vlanResponses.add(vlanResponse); } response.setResponses(vlanResponses, vlans.second()); response.setResponseName(getCommandName()); setResponseObject(response); } }
@Override public void execute() { List<String> planners = _mgr.listDeploymentPlanners(); ListResponse<DeploymentPlannersResponse> response = new ListResponse<DeploymentPlannersResponse>(); List<DeploymentPlannersResponse> plannerResponses = new ArrayList<DeploymentPlannersResponse>(); for (String planner : planners) { DeploymentPlannersResponse plannerResponse = new DeploymentPlannersResponse(); plannerResponse.setName(planner); plannerResponse.setObjectName("deploymentPlanner"); plannerResponses.add(plannerResponse); } response.setResponses(plannerResponses); response.setResponseName(getCommandName()); this.setResponseObject(response); } }
@Override public void create() { GuestOSHypervisor guestOsMapping = _mgr.addGuestOsMapping(this); if (guestOsMapping != null) { setEntityId(guestOsMapping.getId()); setEntityUuid(guestOsMapping.getUuid()); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add guest OS mapping entity"); } }
@Override public void create() { GuestOS guestOs = _mgr.addGuestOs(this); if (guestOs != null) { setEntityId(guestOs.getId()); setEntityUuid(guestOs.getUuid()); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add new guest OS type entity"); } }
@Override public void execute() { if (ids == null && type == null && endDate == null) { throw new InvalidParameterValueException("either ids, type or enddate must be specified"); } else if (startDate != null && endDate == null) { throw new InvalidParameterValueException("enddate must be specified with startdate parameter"); } boolean result = _mgr.archiveEvents(this); if (result) { SuccessResponse response = new SuccessResponse(getCommandName()); setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Unable to archive Events, one or more parameters has invalid values"); } } }
@Override public void execute() { if (ids == null && type == null && endDate == null) { throw new InvalidParameterValueException("either ids, type, startdate or enddate must be specified"); } else if (startDate != null && endDate == null) { throw new InvalidParameterValueException("enddate must be specified with startdate parameter"); } boolean result = _mgr.archiveAlerts(this); if (result) { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Unable to archive Alerts, one or more parameters has invalid values"); } } }
@DB protected void updateSystemvmPassword() { String userid = System.getProperty("user.name"); if (!userid.startsWith("cloud")) { return; } if (!Boolean.valueOf(_configDao.getValue("system.vm.random.password"))) { return; } String already = _configDao.getValue("system.vm.password"); if (already == null) { TransactionLegacy txn = TransactionLegacy.currentTxn(); try { String rpassword = _mgrService.generateRandomPassword(); String wSql = "INSERT INTO `cloud`.`configuration` (category, instance, component, name, value, description) " + "VALUES ('Secure','DEFAULT', 'management-server','system.vm.password', ?,'randmon password generated each management server starts for system vm')"; PreparedStatement stmt = txn.prepareAutoCloseStatement(wSql); stmt.setString(1, DBEncryptionUtil.encrypt(rpassword)); stmt.executeUpdate(); s_logger.info("Updated systemvm password in database"); } catch (SQLException e) { s_logger.error("Cannot retrieve systemvm password", e); } } }
@Test public void testExecuteForNullResult() { updateHostPasswordCmd._mgr = managementServer; updateHostPasswordCmd._resourceService = resourceService; try { Mockito.when(managementServer.updateHostPassword(updateHostPasswordCmd)).thenReturn(false); } catch (final InvalidParameterValueException e) { fail(e.getMessage()); } catch (final IllegalArgumentException e) { fail(e.getMessage()); } try { updateHostPasswordCmd.execute(); } catch (final ServerApiException exception) { Assert.assertEquals("Failed to update config", exception.getDescription()); } assertFalse("The attribute updatePasswdOnHost should be false, but it isn't.", updateHostPasswordCmd.getUpdatePasswdOnHost()); verify(managementServer, times(1)).updateHostPassword(updateHostPasswordCmd); }
@Override public void execute() { Pair<List<? extends Vlan>, Integer> vlans = _mgr.searchForVlans(this); ListResponse<NuageVlanIpRangeResponse> response = new ListResponse<NuageVlanIpRangeResponse>(); List<NuageVlanIpRangeResponse> vlanIpRanges = _nuageVspManager.filterNuageVlanIpRanges(vlans.first(), underlay); response.setResponses(vlanIpRanges); response.setResponseName(getCommandName()); this.setResponseObject(response); }
final List<String> planners = _mgr.listDeploymentPlanners(); if (planners != null && !planners.isEmpty()) { if (!planners.contains(cmd.getDeploymentPlanner())) {
@Override public void create() { final GuestOSHypervisor guestOsMapping = _mgr.addGuestOsMapping(this); if (guestOsMapping != null) { setEntityId(guestOsMapping.getId()); setEntityUuid(guestOsMapping.getUuid()); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add guest OS mapping entity"); } }
@Override public void create() { final GuestOS guestOs = _mgr.addGuestOs(this); if (guestOs != null) { setEntityId(guestOs.getId()); setEntityUuid(guestOs.getUuid()); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add new guest OS type entity"); } }
@Override public void execute() { if (ids == null && type == null && endDate == null) { throw new InvalidParameterValueException("either ids, type or enddate must be specified"); } else if (startDate != null && endDate == null) { throw new InvalidParameterValueException("enddate must be specified with startdate parameter"); } final boolean result = _mgr.archiveEvents(this); if (result) { final SuccessResponse response = new SuccessResponse(getCommandName()); setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Unable to archive Events, one or more parameters has invalid values"); } }
@Override public void execute() { if (ids == null && type == null && endDate == null) { throw new InvalidParameterValueException("either ids, type, startdate or enddate must be specified"); } else if (startDate != null && endDate == null) { throw new InvalidParameterValueException("enddate must be specified with startdate parameter"); } final boolean result = _mgr.archiveAlerts(this); if (result) { final SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Unable to archive Alerts, one or more parameters has invalid values"); } }
@Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException{ password = _mgr.generateRandomPassword(); CallContext.current().setEventDetails("Vm Id: "+getId()); UserVm result = _userVmService.resetVMPassword(this, password); if (result != null){ UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", result).get(0); response.setResponseName(getCommandName()); setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to reset vm password"); } } }