mirror of https://github.com/apache/cloudstack.git
Bug 11261 - Allow to update host tags
Changes: - Changes to updateHostCmd to accepts hosttags parameter - Changes to wipe out existing tags and save new ones in host_tags DB. - UpdateHost is Admin only operation - so only root admin can update host tags
This commit is contained in:
parent
8c53dbcdd7
commit
1fefdd628d
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
package com.cloud.api.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.ApiConstants;
|
||||
|
|
@ -44,10 +46,13 @@ public class UpdateHostCmd extends BaseCmd {
|
|||
|
||||
@Parameter(name=ApiConstants.OS_CATEGORY_ID, type=CommandType.LONG, description="the id of Os category to update the host with")
|
||||
private Long osCategoryId;
|
||||
|
||||
|
||||
@Parameter(name=ApiConstants.ALLOCATION_STATE, type=CommandType.STRING, description="Allocation state of this Host for allocation of new resources")
|
||||
private String allocationState;
|
||||
|
||||
@Parameter(name=ApiConstants.HOST_TAGS, type=CommandType.LIST, collectionType=CommandType.STRING, description="list of tags to be added to the host")
|
||||
private List<String> hostTags;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
@ -59,29 +64,33 @@ public class UpdateHostCmd extends BaseCmd {
|
|||
public Long getOsCategoryId() {
|
||||
return osCategoryId;
|
||||
}
|
||||
|
||||
|
||||
public String getAllocationState() {
|
||||
return allocationState;
|
||||
}
|
||||
return allocationState;
|
||||
}
|
||||
|
||||
public List<String> getHostTags() {
|
||||
return hostTags;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
|
||||
public static String getResultObjectName() {
|
||||
return "updatehost";
|
||||
return "updatehost";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
return Account.ACCOUNT_ID_SYSTEM;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
Host result = _resourceService.updateHost(this);
|
||||
|
|
|
|||
|
|
@ -19,7 +19,9 @@ package com.cloud.host.dao;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import com.cloud.host.HostTagVO;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
|
|
@ -39,7 +41,7 @@ public class HostTagsDaoImpl extends GenericDaoBase<HostTagVO, Long> implements
|
|||
|
||||
@Override
|
||||
public List<String> gethostTags(long hostId) {
|
||||
SearchCriteria sc = HostSearch.create();
|
||||
SearchCriteria<HostTagVO> sc = HostSearch.create();
|
||||
sc.setParameters("hostId", hostId);
|
||||
|
||||
List<HostTagVO> results = search(sc, null);
|
||||
|
|
@ -56,6 +58,10 @@ public class HostTagsDaoImpl extends GenericDaoBase<HostTagVO, Long> implements
|
|||
Transaction txn = Transaction.currentTxn();
|
||||
|
||||
txn.start();
|
||||
SearchCriteria<HostTagVO> sc = HostSearch.create();
|
||||
sc.setParameters("hostId", hostId);
|
||||
expunge(sc);
|
||||
|
||||
for (String tag : hostTags) {
|
||||
HostTagVO vo = new HostTagVO(hostId, tag);
|
||||
persist(vo);
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import java.util.HashMap;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
|
|
@ -51,7 +52,6 @@ import com.cloud.dc.dao.ClusterDao;
|
|||
import com.cloud.dc.dao.DataCenterDao;
|
||||
import com.cloud.dc.dao.HostPodDao;
|
||||
import com.cloud.exception.AgentUnavailableException;
|
||||
import com.cloud.exception.DiscoveredWithErrorException;
|
||||
import com.cloud.exception.DiscoveryException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.PermissionDeniedException;
|
||||
|
|
@ -59,9 +59,9 @@ import com.cloud.host.Host;
|
|||
import com.cloud.host.Host.HostAllocationState;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.Status;
|
||||
import com.cloud.host.Status.Event;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.host.dao.HostDetailsDao;
|
||||
import com.cloud.host.dao.HostTagsDao;
|
||||
import com.cloud.hypervisor.Hypervisor;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.hypervisor.kvm.resource.KvmDummyResourceBase;
|
||||
|
|
@ -112,6 +112,8 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
|
|||
@Inject
|
||||
protected HostDetailsDao _hostDetailsDao;
|
||||
@Inject
|
||||
protected HostTagsDao _hostTagsDao;
|
||||
@Inject
|
||||
protected GuestOSCategoryDao _guestOSCategoryDao;
|
||||
|
||||
@Inject(adapter = Discoverer.class)
|
||||
|
|
@ -921,6 +923,19 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
|
|||
|
||||
_hostDao.update(hostId, host);
|
||||
}
|
||||
|
||||
List<String> hostTags = cmd.getHostTags();
|
||||
if (hostTags != null) {
|
||||
// Verify that the host exists
|
||||
HostVO host = _hostDao.findById(hostId);
|
||||
if (host == null) {
|
||||
throw new InvalidParameterValueException("Host with id " + hostId + " doesn't exist");
|
||||
}
|
||||
if(s_logger.isDebugEnabled()){
|
||||
s_logger.debug("Updating Host Tags to :"+hostTags);
|
||||
}
|
||||
_hostTagsDao.persist(hostId, hostTags);
|
||||
}
|
||||
|
||||
HostVO updatedHost = _hostDao.findById(hostId);
|
||||
return updatedHost;
|
||||
|
|
|
|||
Loading…
Reference in New Issue