mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
bug 6745: Using UUID instead of integers - for VM instances
This commit is contained in:
parent
fab2d1f880
commit
fa2dd8e93a
22
api/src/com/cloud/api/Identity.java
Normal file
22
api/src/com/cloud/api/Identity.java
Normal file
@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
|
||||
*
|
||||
* This software is licensed under the GNU General Public License v3 or later.
|
||||
*
|
||||
* It is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.cloud.api;
|
||||
|
||||
public interface Identity {
|
||||
String getUuid();
|
||||
}
|
||||
30
api/src/com/cloud/api/IdentityMapper.java
Normal file
30
api/src/com/cloud/api/IdentityMapper.java
Normal file
@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
|
||||
*
|
||||
* This software is licensed under the GNU General Public License v3 or later.
|
||||
*
|
||||
* It is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.cloud.api;
|
||||
|
||||
import static java.lang.annotation.ElementType.FIELD;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({FIELD})
|
||||
public @interface IdentityMapper {
|
||||
String entityTableName();
|
||||
}
|
||||
@ -22,6 +22,7 @@ import org.apache.log4j.Logger;
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.BaseAsyncCmd;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.IdentityMapper;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
@ -45,6 +46,7 @@ public class DestroyVMCmd extends BaseAsyncCmd {
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@IdentityMapper(entityTableName="vm_instance")
|
||||
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="The ID of the virtual machine")
|
||||
private Long id;
|
||||
|
||||
|
||||
@ -24,6 +24,7 @@ import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.IdentityMapper;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.response.GetVMPasswordResponse;
|
||||
@ -40,6 +41,7 @@ public class GetVMPasswordCmd extends BaseCmd {
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@IdentityMapper(entityTableName="vm_instance")
|
||||
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="The ID of the virtual machine")
|
||||
private Long id;
|
||||
|
||||
|
||||
@ -23,6 +23,7 @@ import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.BaseListCmd;
|
||||
import com.cloud.api.IdentityMapper;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.response.ListResponse;
|
||||
@ -55,6 +56,7 @@ public class ListVMsCmd extends BaseListCmd {
|
||||
@Parameter(name=ApiConstants.HOST_ID, type=CommandType.LONG, description="the host ID")
|
||||
private Long hostId;
|
||||
|
||||
@IdentityMapper(entityTableName="vm_instance")
|
||||
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="the ID of the virtual machine")
|
||||
private Long id;
|
||||
|
||||
|
||||
@ -22,6 +22,7 @@ import org.apache.log4j.Logger;
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.BaseAsyncCmd;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.IdentityMapper;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
@ -52,6 +53,7 @@ public class MigrateVMCmd extends BaseAsyncCmd {
|
||||
@Parameter(name=ApiConstants.HOST_ID, type=CommandType.LONG, required=false, description="destination Host ID to migrate VM to")
|
||||
private Long hostId;
|
||||
|
||||
@IdentityMapper(entityTableName="vm_instance")
|
||||
@Parameter(name=ApiConstants.VIRTUAL_MACHINE_ID, type=CommandType.LONG, required=true, description="the ID of the virtual machine")
|
||||
private Long virtualMachineId;
|
||||
|
||||
|
||||
@ -22,6 +22,7 @@ import org.apache.log4j.Logger;
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.BaseAsyncCmd;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.IdentityMapper;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
@ -44,6 +45,7 @@ public class RebootVMCmd extends BaseAsyncCmd {
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@IdentityMapper(entityTableName="vm_instance")
|
||||
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="The ID of the virtual machine")
|
||||
private Long id;
|
||||
|
||||
|
||||
@ -22,6 +22,7 @@ import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.IdentityMapper;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
@ -40,6 +41,7 @@ public class RecoverVMCmd extends BaseCmd {
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@IdentityMapper(entityTableName="vm_instance")
|
||||
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="The ID of the virtual machine")
|
||||
private Long id;
|
||||
|
||||
|
||||
@ -22,6 +22,7 @@ import org.apache.log4j.Logger;
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.BaseAsyncCmd;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.IdentityMapper;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
@ -46,6 +47,7 @@ public class ResetVMPasswordCmd extends BaseAsyncCmd {
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@IdentityMapper(entityTableName="vm_instance")
|
||||
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="The ID of the virtual machine")
|
||||
private Long id;
|
||||
|
||||
|
||||
@ -5,6 +5,7 @@ import org.apache.log4j.Logger;
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.BaseAsyncCmd;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.IdentityMapper;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
@ -25,6 +26,7 @@ public class RestoreVMCmd extends BaseAsyncCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(RestoreVMCmd.class);
|
||||
private static final String s_name = "restorevmresponse";
|
||||
|
||||
@IdentityMapper(entityTableName="vm_instance")
|
||||
@Parameter(name=ApiConstants.VIRTUAL_MACHINE_ID, type=CommandType.LONG, required=true, description="Virtual Machine ID")
|
||||
private Long vmId;
|
||||
|
||||
|
||||
@ -22,6 +22,7 @@ import org.apache.log4j.Logger;
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.BaseAsyncCmd;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.IdentityMapper;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
@ -49,6 +50,7 @@ public class StartVMCmd extends BaseAsyncCmd {
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@IdentityMapper(entityTableName="vm_instance")
|
||||
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="The ID of the virtual machine")
|
||||
private Long id;
|
||||
|
||||
|
||||
@ -22,6 +22,7 @@ import org.apache.log4j.Logger;
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.BaseAsyncCmd;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.IdentityMapper;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
@ -44,6 +45,7 @@ public class StopVMCmd extends BaseAsyncCmd {
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@IdentityMapper(entityTableName="vm_instance")
|
||||
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="The ID of the virtual machine")
|
||||
private Long id;
|
||||
|
||||
|
||||
@ -21,6 +21,7 @@ import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.IdentityMapper;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
@ -47,6 +48,7 @@ public class UpdateVMCmd extends BaseCmd{
|
||||
@Parameter(name=ApiConstants.HA_ENABLE, type=CommandType.BOOLEAN, description="true if high-availability is enabled for the virtual machine, false otherwise")
|
||||
private Boolean haEnable;
|
||||
|
||||
@IdentityMapper(entityTableName="vm_instance")
|
||||
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="The ID of the virtual machine")
|
||||
private Long id;
|
||||
|
||||
|
||||
@ -1,89 +1,91 @@
|
||||
/**
|
||||
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
|
||||
*
|
||||
* This software is licensed under the GNU General Public License v3 or later.
|
||||
*
|
||||
* It is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.cloud.api.commands;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.response.InstanceGroupResponse;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.vm.InstanceGroup;
|
||||
|
||||
@Implementation(description="Updates a vm group", responseObject=InstanceGroupResponse.class)
|
||||
public class UpdateVMGroupCmd extends BaseCmd{
|
||||
|
||||
private static final String s_name = "updateinstancegroupresponse";
|
||||
public static final Logger s_logger = Logger.getLogger(UpdateVMGroupCmd.class.getName());
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="Instance group ID")
|
||||
private Long id;
|
||||
|
||||
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="new instance group name")
|
||||
private String groupName;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getGroupName() {
|
||||
return groupName;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
InstanceGroup group = _entityMgr.findById(InstanceGroup.class, getId());
|
||||
if (group != null) {
|
||||
return group.getAccountId();
|
||||
}
|
||||
|
||||
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
InstanceGroup result = _mgr.updateVmGroup(this);
|
||||
if (result != null){
|
||||
InstanceGroupResponse response = _responseGenerator.createInstanceGroupResponse(result);
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
} else {
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update vm instance group");
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
|
||||
*
|
||||
* This software is licensed under the GNU General Public License v3 or later.
|
||||
*
|
||||
* It is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.cloud.api.commands;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.IdentityMapper;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.response.InstanceGroupResponse;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.vm.InstanceGroup;
|
||||
|
||||
@Implementation(description="Updates a vm group", responseObject=InstanceGroupResponse.class)
|
||||
public class UpdateVMGroupCmd extends BaseCmd{
|
||||
|
||||
private static final String s_name = "updateinstancegroupresponse";
|
||||
public static final Logger s_logger = Logger.getLogger(UpdateVMGroupCmd.class.getName());
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@IdentityMapper(entityTableName="instance_group")
|
||||
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="Instance group ID")
|
||||
private Long id;
|
||||
|
||||
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="new instance group name")
|
||||
private String groupName;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getGroupName() {
|
||||
return groupName;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
InstanceGroup group = _entityMgr.findById(InstanceGroup.class, getId());
|
||||
if (group != null) {
|
||||
return group.getAccountId();
|
||||
}
|
||||
|
||||
return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
InstanceGroup result = _mgr.updateVmGroup(this);
|
||||
if (result != null){
|
||||
InstanceGroupResponse response = _responseGenerator.createInstanceGroupResponse(result);
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
} else {
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update vm instance group");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,6 +21,7 @@ import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.IdentityMapper;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
@ -42,6 +43,7 @@ public class UpgradeVMCmd extends BaseCmd {
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@IdentityMapper(entityTableName="vm_instance")
|
||||
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="The ID of the virtual machine")
|
||||
private Long id;
|
||||
|
||||
|
||||
@ -27,7 +27,7 @@ import com.google.gson.annotations.SerializedName;
|
||||
@SuppressWarnings("unused")
|
||||
public class UserVmResponse extends BaseResponse implements ControlledEntityResponse {
|
||||
@SerializedName(ApiConstants.ID) @Param(description="the ID of the virtual machine")
|
||||
private Long id;
|
||||
private String id;
|
||||
|
||||
@SerializedName(ApiConstants.NAME) @Param(description="the name of the virtual machine")
|
||||
private String name;
|
||||
@ -160,11 +160,11 @@ public class UserVmResponse extends BaseResponse implements ControlledEntityResp
|
||||
this.hypervisor = hypervisor;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
@ -21,6 +21,7 @@ import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
import com.cloud.acl.ControlledEntity;
|
||||
import com.cloud.api.Identity;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.utils.fsm.StateMachine2;
|
||||
import com.cloud.utils.fsm.StateObject;
|
||||
@ -30,7 +31,7 @@ import com.cloud.utils.fsm.StateObject;
|
||||
* VirtualMachine describes the properties held by a virtual machine
|
||||
*
|
||||
*/
|
||||
public interface VirtualMachine extends RunningOn, ControlledEntity, StateObject<VirtualMachine.State> {
|
||||
public interface VirtualMachine extends RunningOn, ControlledEntity, Identity, StateObject<VirtualMachine.State> {
|
||||
|
||||
public enum State {
|
||||
Starting(true, "VM is being started. At this state, you should find host id filled which means it's being started on that host."),
|
||||
|
||||
@ -21,6 +21,7 @@ package com.cloud.vm;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.DiscriminatorColumn;
|
||||
@ -144,6 +145,9 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State, Vi
|
||||
|
||||
@Transient
|
||||
Map<String, String> details;
|
||||
|
||||
@Column(name="uuid")
|
||||
protected String uuid;
|
||||
|
||||
public VMInstanceVO(long id,
|
||||
long serviceOfferingId,
|
||||
@ -172,6 +176,7 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State, Vi
|
||||
this.serviceOfferingId = serviceOfferingId;
|
||||
this.hypervisorType = hypervisorType;
|
||||
this.limitCpuUse = false;
|
||||
this.uuid = UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
public VMInstanceVO(long id,
|
||||
@ -221,6 +226,15 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State, Vi
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public void setUuid(String uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HypervisorType getHypervisorType() {
|
||||
return hypervisorType;
|
||||
|
||||
26
server/src/com/cloud/Identity/dao/IdentityDao.java
Normal file
26
server/src/com/cloud/Identity/dao/IdentityDao.java
Normal file
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Copyright (C) 2011 Citrix Systems, Inc. All rights reserved.
|
||||
*
|
||||
* This software is licensed under the GNU General Public License v3 or later.
|
||||
*
|
||||
* It is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.cloud.Identity.dao;
|
||||
|
||||
import com.cloud.api.IdentityMapper;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
public interface IdentityDao extends GenericDao<IdentityVO, Long> {
|
||||
Long getIdentityId(IdentityMapper mapper, String identityString);
|
||||
}
|
||||
66
server/src/com/cloud/Identity/dao/IdentityDaoImpl.java
Normal file
66
server/src/com/cloud/Identity/dao/IdentityDaoImpl.java
Normal file
@ -0,0 +1,66 @@
|
||||
/**
|
||||
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
|
||||
*
|
||||
* This software is licensed under the GNU General Public License v3 or later.
|
||||
*
|
||||
* It is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.cloud.Identity.dao;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.IdentityMapper;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
|
||||
@Local(value={IdentityDao.class})
|
||||
public class IdentityDaoImpl extends GenericDaoBase<IdentityVO, Long> implements IdentityDao {
|
||||
private static final Logger s_logger = Logger.getLogger(IdentityDaoImpl.class);
|
||||
|
||||
public Long getIdentityId(IdentityMapper mapper, String identityString) {
|
||||
assert(mapper.entityTableName() != null);
|
||||
assert(identityString != null);
|
||||
|
||||
PreparedStatement pstmt = null;
|
||||
Transaction txn = Transaction.currentTxn();;
|
||||
|
||||
try {
|
||||
pstmt = txn.prepareAutoCloseStatement(
|
||||
String.format("SELECT id FROM %s WHERE id=? OR uuid=?", mapper.entityTableName()));
|
||||
|
||||
long id = 0;
|
||||
try {
|
||||
id = Long.parseLong(identityString);
|
||||
} catch(NumberFormatException e) {
|
||||
// this could happen when it is a uuid string, so catch and ignore it
|
||||
}
|
||||
|
||||
pstmt.setLong(1, id);
|
||||
pstmt.setString(2, identityString);
|
||||
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
if(rs.next()) {
|
||||
return rs.getLong(1);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
s_logger.error("Unexpected exception ", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
27
server/src/com/cloud/Identity/dao/IdentityVO.java
Normal file
27
server/src/com/cloud/Identity/dao/IdentityVO.java
Normal file
@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Copyright (C) 2011 Citrix Systems, Inc. All rights reserved.
|
||||
*
|
||||
* This software is licensed under the GNU General Public License v3 or later.
|
||||
*
|
||||
* It is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.cloud.Identity.dao;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
|
||||
/**
|
||||
* This is a dummy class to fit for CloudStack Dao framework
|
||||
*/
|
||||
@Entity
|
||||
public class IdentityVO {
|
||||
}
|
||||
@ -30,6 +30,8 @@ import java.util.regex.Matcher;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.Identity.dao.IdentityDao;
|
||||
import com.cloud.Identity.dao.IdentityDaoImpl;
|
||||
import com.cloud.api.BaseCmd.CommandType;
|
||||
import com.cloud.api.commands.ListEventsCmd;
|
||||
import com.cloud.async.AsyncCommandQueued;
|
||||
@ -55,6 +57,7 @@ public class ApiDispatcher {
|
||||
|
||||
ComponentLocator _locator;
|
||||
AsyncJobManager _asyncMgr;
|
||||
IdentityDao _identityDao;
|
||||
|
||||
// singleton class
|
||||
private static ApiDispatcher s_instance = new ApiDispatcher();
|
||||
@ -66,6 +69,7 @@ public class ApiDispatcher {
|
||||
private ApiDispatcher() {
|
||||
_locator = ComponentLocator.getLocator(ManagementServer.Name);
|
||||
_asyncMgr = _locator.getManager(AsyncJobManager.class);
|
||||
_identityDao = _locator.getDao(IdentityDao.class);
|
||||
}
|
||||
|
||||
public void dispatchCreateCmd(BaseAsyncCreateCmd cmd, Map<String, String> params) {
|
||||
@ -194,6 +198,8 @@ public class ApiDispatcher {
|
||||
if ((parameterAnnotation == null) || !parameterAnnotation.expose()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
IdentityMapper identityMapper = field.getAnnotation(IdentityMapper.class);
|
||||
|
||||
Object paramObj = unpackedParams.get(parameterAnnotation.name());
|
||||
if (paramObj == null) {
|
||||
@ -205,7 +211,7 @@ public class ApiDispatcher {
|
||||
|
||||
// marshall the parameter into the correct type and set the field value
|
||||
try {
|
||||
setFieldValue(field, cmd, paramObj, parameterAnnotation);
|
||||
setFieldValue(field, cmd, paramObj, parameterAnnotation, identityMapper);
|
||||
} catch (IllegalArgumentException argEx) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Unable to execute API command " + cmd.getCommandName() + " due to invalid value " + paramObj + " for parameter " + parameterAnnotation.name());
|
||||
@ -229,7 +235,7 @@ public class ApiDispatcher {
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
private static void setFieldValue(Field field, BaseCmd cmdObj, Object paramObj, Parameter annotation) throws IllegalArgumentException, ParseException {
|
||||
private static void setFieldValue(Field field, BaseCmd cmdObj, Object paramObj, Parameter annotation, IdentityMapper identityMapper) throws IllegalArgumentException, ParseException {
|
||||
try {
|
||||
field.setAccessible(true);
|
||||
CommandType fieldType = annotation.type();
|
||||
@ -296,7 +302,10 @@ public class ApiDispatcher {
|
||||
field.set(cmdObj, listParam);
|
||||
break;
|
||||
case LONG:
|
||||
field.set(cmdObj, Long.valueOf(paramObj.toString()));
|
||||
if(identityMapper != null)
|
||||
field.set(cmdObj, s_instance._identityDao.getIdentityId(identityMapper, paramObj.toString()));
|
||||
else
|
||||
field.set(cmdObj, Long.valueOf(paramObj.toString()));
|
||||
break;
|
||||
case SHORT:
|
||||
field.set(cmdObj, Short.valueOf(paramObj.toString()));
|
||||
|
||||
@ -1169,7 +1169,8 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
|
||||
// stats calculation
|
||||
String cpuUsed = null;
|
||||
VmStats vmStats = ApiDBUtils.getVmStatistics(userVmResponse.getId());
|
||||
// VmStats vmStats = ApiDBUtils.getVmStatistics(userVmResponse.getId());
|
||||
VmStats vmStats = ApiDBUtils.getVmStatistics(uvd.getId());
|
||||
if (vmStats != null) {
|
||||
float cpuUtil = (float) vmStats.getCPUUtilization();
|
||||
cpuUsed = decimalFormat.format(cpuUtil) + "%";
|
||||
@ -2525,7 +2526,10 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
public UserVmResponse newUserVmResponse(UserVmData userVmData, boolean caller_is_admin){
|
||||
UserVmResponse userVmResponse = new UserVmResponse();
|
||||
userVmResponse.setHypervisor(userVmData.getHypervisor());
|
||||
userVmResponse.setId(userVmData.getId());
|
||||
if(userVmData.getUuid() != null && !userVmData.getUuid().isEmpty())
|
||||
userVmResponse.setId(userVmData.getUuid());
|
||||
else
|
||||
userVmResponse.setId(String.valueOf(userVmData.getId()));
|
||||
userVmResponse.setName(userVmData.getName());
|
||||
userVmResponse.setDisplayName(userVmData.getDisplayName());
|
||||
userVmResponse.setIpAddress(userVmData.getIpAddress());
|
||||
|
||||
@ -22,6 +22,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.cloud.Identity.dao.IdentityDaoImpl;
|
||||
import com.cloud.agent.manager.ClusteredAgentManagerImpl;
|
||||
import com.cloud.alert.AlertManagerImpl;
|
||||
import com.cloud.alert.dao.AlertDaoImpl;
|
||||
@ -281,6 +282,7 @@ public class DefaultComponentLibrary extends ComponentLibraryBase implements Com
|
||||
addDao("ElasticLbVmMap", ElasticLbVmMapDaoImpl.class);
|
||||
addDao("ProjectsAccountDao", ProjectAccountDaoImpl.class);
|
||||
addDao("ProjectInvitationDao", ProjectInvitationDaoImpl.class);
|
||||
addDao("IdentityDao", IdentityDaoImpl.class);
|
||||
info = addDao("HypervisorCapabilitiesDao",HypervisorCapabilitiesDaoImpl.class);
|
||||
info.addParameter("cache.size", "100");
|
||||
info.addParameter("cache.time.to.live", "600");
|
||||
|
||||
@ -21,8 +21,6 @@ import java.util.Date;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.api.response.UserVmResponse;
|
||||
import com.cloud.uservm.UserVm;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
import com.cloud.vm.UserVmVO;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -27,6 +27,7 @@ import com.cloud.api.response.IngressRuleResponse;
|
||||
public class UserVmData {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String uuid;
|
||||
private String displayName;
|
||||
private String ipAddress;
|
||||
private String accountName;
|
||||
@ -119,6 +120,14 @@ public class UserVmData {
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getUuid() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
public void setUuid(String uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
|
||||
@ -870,6 +870,7 @@ CREATE TABLE `cloud`.`vm_template` (
|
||||
CREATE TABLE `cloud`.`vm_instance` (
|
||||
`id` bigint unsigned UNIQUE NOT NULL,
|
||||
`name` varchar(255) NOT NULL,
|
||||
`uuid` varchar(255),
|
||||
`instance_name` varchar(255) NOT NULL COMMENT 'name of the vm instance running on the hosts',
|
||||
`state` varchar(32) NOT NULL,
|
||||
`vm_template_id` bigint unsigned,
|
||||
@ -912,7 +913,8 @@ CREATE TABLE `cloud`.`vm_instance` (
|
||||
CONSTRAINT `fk_vm_instance__account_id` FOREIGN KEY `fk_vm_instance__account_id` (`account_id`) REFERENCES `account` (`id`),
|
||||
INDEX `i_vm_instance__account_id`(`account_id`),
|
||||
CONSTRAINT `fk_vm_instance__service_offering_id` FOREIGN KEY `fk_vm_instance__service_offering_id` (`service_offering_id`) REFERENCES `service_offering` (`id`),
|
||||
INDEX `i_vm_instance__service_offering_id`(`service_offering_id`)
|
||||
INDEX `i_vm_instance__service_offering_id`(`service_offering_id`),
|
||||
CONSTRAINT `uc_vm_instance_uuid` UNIQUE (`uuid`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE TABLE `cloud`.`user_vm` (
|
||||
|
||||
@ -109,10 +109,6 @@ update configuration set name = 'zone.virtualnetwork.publicip.capacity.notificat
|
||||
update configuration set name = 'pod.privateip.capacity.notificationthreshold' , category = 'Alert' where name = 'private.ip.capacity.threshold' ;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ALTER TABLE `cloud`.`domain_router` ADD COLUMN `template_version` varchar(100) COMMENT 'template version' AFTER role;
|
||||
ALTER TABLE `cloud`.`domain_router` ADD COLUMN `scripts_version` varchar(100) COMMENT 'scripts version' AFTER template_version;
|
||||
ALTER TABLE `cloud`.`alert` ADD `cluster_id` bigint unsigned;
|
||||
@ -121,3 +117,5 @@ DELETE from `cloud`.`op_host_capacity` where capacity_type in (2,4,6);
|
||||
|
||||
ALTER TABLE `cloud`.`user_statistics` ADD COLUMN `agg_bytes_received` bigint unsigned NOT NULL default '0';
|
||||
ALTER TABLE `cloud`.`user_statistics` ADD COLUMN `agg_bytes_sent` bigint unsigned NOT NULL default '0';
|
||||
ALTER TABLE `cloud`.`vm_instance` ADD COLUMN `uuid` varchar(255);
|
||||
ALTER TABLE `cloud`.`vm_instance` ADD CONSTRAINT `uc_vm_instance_uuid` UNIQUE (`uuid`);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user