Search in sources :

Example 41 with UserVO

use of com.cloud.user.UserVO in project cloudstack by apache.

the class ServiceManagerImpl method createServiceVM.

/**
     * In the case of service instance the master object is in the contrail API server. This object stores the
     * service instance parameters in the database.
     *
     * @param owner     Used to determine the project.
     * @param name      Service instance name (user specified).
     * @param template  Image to execute.
     * @param serviceOffering
     * @param left      Inside network.
     * @param right     Outside network.
     * @return
     */
/**
     * create a new ServiceVM object.
     * @return
     */
@ActionEvent(eventType = EventTypes.EVENT_VM_CREATE, eventDescription = "createServiceInstance", create = true)
private ServiceVirtualMachine createServiceVM(DataCenter zone, Account owner, VirtualMachineTemplate template, ServiceOffering serviceOffering, String name, ServiceInstance siObj, Network left, Network right) {
    long id = _vmDao.getNextInSequence(Long.class, "id");
    DataCenterDeployment plan = new DataCenterDeployment(zone.getId());
    LinkedHashMap<NetworkVO, List<? extends NicProfile>> networks = new LinkedHashMap<NetworkVO, List<? extends NicProfile>>();
    NetworkVO linklocal = (NetworkVO) _networkModel.getSystemNetworkByZoneAndTrafficType(zone.getId(), TrafficType.Management);
    networks.put(linklocal, new ArrayList<NicProfile>());
    networks.put((NetworkVO) left, new ArrayList<NicProfile>());
    networks.put((NetworkVO) right, new ArrayList<NicProfile>());
    String instanceName = VirtualMachineName.getVmName(id, owner.getId(), "SRV");
    long userId = CallContext.current().getCallingUserId();
    if (CallContext.current().getCallingAccount().getId() != owner.getId()) {
        List<UserVO> userVOs = _userDao.listByAccount(owner.getAccountId());
        if (!userVOs.isEmpty()) {
            userId = userVOs.get(0).getId();
        }
    }
    ServiceVirtualMachine svm = new ServiceVirtualMachine(id, instanceName, name, template.getId(), serviceOffering.getId(), template.getHypervisorType(), template.getGuestOSId(), zone.getId(), owner.getDomainId(), owner.getAccountId(), userId, false);
    // database synchronization code must be able to distinguish service instance VMs.
    Map<String, String> kvmap = new HashMap<String, String>();
    kvmap.put("service-instance", siObj.getUuid());
    Gson json = new Gson();
    String userData = json.toJson(kvmap);
    svm.setUserData(userData);
    try {
        _vmManager.allocate(instanceName, template, serviceOffering, networks, plan, template.getHypervisorType());
    } catch (InsufficientCapacityException ex) {
        throw new CloudRuntimeException("Insufficient capacity", ex);
    }
    CallContext.current().setEventDetails("Vm Id: " + svm.getId());
    return svm;
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Gson(com.google.gson.Gson) NicProfile(com.cloud.vm.NicProfile) LinkedHashMap(java.util.LinkedHashMap) UserVO(com.cloud.user.UserVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ArrayList(java.util.ArrayList) List(java.util.List) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ActionEvent(com.cloud.event.ActionEvent)

Example 42 with UserVO

use of com.cloud.user.UserVO in project cloudstack by apache.

the class ActionEventUtilsTest method testPopulateFirstClassEntities.

@Test
public void testPopulateFirstClassEntities() {
    AccountVO account = new AccountVO("testaccount", 1L, "networkdomain", (short) 0, "uuid");
    account.setId(ACCOUNT_ID);
    UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
    Mockito.when(accountDao.findById(ACCOUNT_ID)).thenReturn(account);
    Mockito.when(userDao.findById(USER_ID)).thenReturn(user);
    CallContext.register(user, account);
    //Inject some entity UUIDs into the call context
    String instanceUuid = UUID.randomUUID().toString();
    String ipUuid = UUID.randomUUID().toString();
    CallContext.current().putContextParameter(VirtualMachine.class, instanceUuid);
    CallContext.current().putContextParameter(IpAddress.class, ipUuid);
    ActionEventUtils.onActionEvent(USER_ID, ACCOUNT_ID, account.getDomainId(), "StaticNat", "Test event");
    //Assertions
    Assert.assertNotEquals(publishedEvents.size(), 0);
    Assert.assertEquals(publishedEvents.size(), 1);
    Event event = publishedEvents.get(0);
    Assert.assertNotNull(event.getDescription());
    JsonObject json = new JsonParser().parse(event.getDescription()).getAsJsonObject();
    Assert.assertTrue(json.has("VirtualMachine"));
    Assert.assertTrue(json.has("IpAddress"));
    Assert.assertEquals(json.get("VirtualMachine").getAsString(), instanceUuid);
    Assert.assertEquals(json.get("IpAddress").getAsString(), ipUuid);
    CallContext.unregister();
}
Also used : UserVO(com.cloud.user.UserVO) Event(org.apache.cloudstack.framework.events.Event) JsonObject(com.google.gson.JsonObject) AccountVO(com.cloud.user.AccountVO) JsonParser(com.google.gson.JsonParser) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 43 with UserVO

use of com.cloud.user.UserVO in project cloudstack by apache.

the class FakeCmdWithRoleAdmin method testHandleWithUnknownParams.

@Test
public void testHandleWithUnknownParams() throws ResourceAllocationException {
    // Prepare
    final String unknownParamKey = "unknownParam";
    final BaseCmd cmd = new FakeCmd();
    final Map<String, String> params = new HashMap<String, String>();
    params.put(ApiConstants.COMMAND, "");
    params.put("addedParam", "");
    params.put(unknownParamKey, "");
    Account account = new AccountVO("testaccount", 1L, "networkdomain", (short) 0, "uuid");
    UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
    CallContext.register(user, account);
    // Execute
    try {
        driveTest(cmd, params);
    } finally {
        CallContext.unregister();
    }
    // Assert
    assertTrue("There should be error msg, since there is one unknown parameter", loggerOutput.contains(unknownParamKey));
    assertTrue("There should be error msg containing the correct command name", loggerOutput.contains(FAKE_CMD_NAME));
}
Also used : Account(com.cloud.user.Account) UserVO(com.cloud.user.UserVO) HashMap(java.util.HashMap) BaseCmd(org.apache.cloudstack.api.BaseCmd) AccountVO(com.cloud.user.AccountVO) Test(org.junit.Test)

Example 44 with UserVO

use of com.cloud.user.UserVO in project cloudstack by apache.

the class FakeCmdWithRoleAdmin method testHandle.

@Test
public void testHandle() throws ResourceAllocationException {
    // Prepare
    final BaseCmd cmd = new FakeCmd();
    final Map<String, String> params = new HashMap<String, String>();
    params.put(ApiConstants.COMMAND, "");
    params.put(ApiConstants.ACCOUNT_ID, "");
    params.put(ApiConstants.CTX_START_EVENT_ID, "");
    params.put(ApiConstants.COMMAND, "");
    params.put(ApiConstants.CMD_EVENT_TYPE, "");
    params.put(ApiConstants.USERNAME, "");
    params.put(ApiConstants.USER_ID, "");
    params.put(ApiConstants.PASSWORD, "");
    params.put(ApiConstants.DOMAIN, "");
    params.put(ApiConstants.DOMAIN_ID, "");
    params.put(ApiConstants.DOMAIN__ID, "");
    params.put(ApiConstants.SESSIONKEY, "");
    params.put(ApiConstants.RESPONSE, "");
    params.put(ApiConstants.PAGE, "");
    params.put(ApiConstants.USER_API_KEY, "");
    params.put(ApiConstants.API_KEY, "");
    params.put(ApiConstants.PAGE_SIZE, "");
    params.put(ApiConstants.HTTPMETHOD, "");
    params.put(ApiConstants.SIGNATURE, "");
    params.put(ApiConstants.CTX_ACCOUNT_ID, "");
    params.put(ApiConstants.CTX_START_EVENT_ID, "");
    // Make sure it's case insensitive
    params.put(ApiConstants.CTX_START_EVENT_ID, "");
    params.put(ApiConstants.CTX_START_EVENT_ID.toLowerCase(), "");
    params.put(ApiConstants.CTX_USER_ID.toUpperCase(), "");
    params.put(ApiConstants.CTX_USER_ID, "");
    params.put(ApiConstants.UUID, "");
    params.put(ApiConstants.ID, "");
    params.put("_", "");
    params.put("addedParam", "");
    Account account = new AccountVO("testaccount", 1L, "networkdomain", (short) 0, "uuid");
    UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
    CallContext.register(user, account);
    // Execute
    try {
        driveTest(cmd, params);
    } finally {
        CallContext.unregister();
    }
    // Assert
    assertEquals("There should be no errors since there are no unknown parameters for this command class", null, loggerOutput);
}
Also used : Account(com.cloud.user.Account) UserVO(com.cloud.user.UserVO) HashMap(java.util.HashMap) BaseCmd(org.apache.cloudstack.api.BaseCmd) AccountVO(com.cloud.user.AccountVO) Test(org.junit.Test)

Example 45 with UserVO

use of com.cloud.user.UserVO in project cloudstack by apache.

the class ApiRateLimitTest method createFakeUser.

private User createFakeUser() {
    UserVO user = new UserVO();
    user.setAccountId(s_acctIdSeq);
    return user;
}
Also used : UserVO(com.cloud.user.UserVO)

Aggregations

UserVO (com.cloud.user.UserVO)72 AccountVO (com.cloud.user.AccountVO)44 Account (com.cloud.user.Account)42 Test (org.junit.Test)23 Before (org.junit.Before)21 ArrayList (java.util.ArrayList)19 Field (java.lang.reflect.Field)15 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)11 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)11 HashMap (java.util.HashMap)11 DomainVO (com.cloud.domain.DomainVO)10 VMTemplateVO (com.cloud.storage.VMTemplateVO)8 DomainRouterVO (com.cloud.vm.DomainRouterVO)8 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)7 Service (com.cloud.network.Network.Service)7 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)6 DataCenterVO (com.cloud.dc.DataCenterVO)5 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)5 LinkedHashMap (java.util.LinkedHashMap)5 NetworkOrchestrationService (org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService)5