mirror of https://github.com/apache/cloudstack.git
Two things:
Load non-routing resource in ClusteredAgentManager includes External DHCP, PxeServer, ExternalFirewall, ExternalLoadBalancer Bug 9887 - baremetal: support for image operation (create template from guest disk) (edit) changes in line with UI
This commit is contained in:
parent
055e5c82c7
commit
b0b3f16dae
|
|
@ -155,6 +155,8 @@ public interface ResponseGenerator {
|
|||
Account findAccountByNameDomain(String accountName, Long domainId);
|
||||
|
||||
VirtualMachineTemplate findTemplateById(Long templateId);
|
||||
|
||||
Host findHostById(Long hostId);
|
||||
|
||||
List<TemplateResponse> createTemplateResponses(long templateId, Long zoneId, boolean readyOnly);
|
||||
List<TemplateResponse> createTemplateResponses(long templateId, long zoneId, boolean readyOnly);
|
||||
|
|
@ -196,4 +198,6 @@ public interface ResponseGenerator {
|
|||
List<TemplateResponse> createIsoResponses(long isoId, Long zoneId, boolean readyOnly);
|
||||
List<TemplateResponse> createIsoResponses(VirtualMachineTemplate iso, long zoneId, boolean readyOnly);
|
||||
|
||||
List<TemplateResponse> createTemplateResponses(long templateId, Long vmId);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -187,29 +187,46 @@ public class CreateTemplateCmd extends BaseAsyncCreateCmd {
|
|||
return AsyncJob.Type.Template;
|
||||
}
|
||||
|
||||
private boolean isBareMetal() {
|
||||
return (this.getVmId() != null && this.getUrl() != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create() throws ResourceAllocationException {
|
||||
VirtualMachineTemplate template = null;
|
||||
template = _userVmService.createPrivateTemplateRecord(this);
|
||||
if (isBareMetal()) {
|
||||
_bareMetalVmService.createPrivateTemplateRecord(this);
|
||||
/*Baremetal creates template record after taking image proceeded, use vmId as entity id here*/
|
||||
this.setEntityId(vmId);
|
||||
} else {
|
||||
VirtualMachineTemplate template = null;
|
||||
template = _userVmService.createPrivateTemplateRecord(this);
|
||||
|
||||
if (template != null) {
|
||||
this.setEntityId(template.getId());
|
||||
} else {
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a template");
|
||||
}
|
||||
if (template != null) {
|
||||
this.setEntityId(template.getId());
|
||||
} else {
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR,
|
||||
"Failed to create a template");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
UserContext.current().setEventDetails("Template Id: "+getEntityId()+((getSnapshotId() == null) ? " from volume Id: " + getVolumeId() : " from snapshot Id: " + getSnapshotId()));
|
||||
VirtualMachineTemplate template = null;
|
||||
if (vmId != null && url != null) {
|
||||
if (isBareMetal()) {
|
||||
template = _bareMetalVmService.createPrivateTemplate(this);
|
||||
} else {
|
||||
template = _userVmService.createPrivateTemplate(this);
|
||||
}
|
||||
|
||||
if (template != null){
|
||||
List<TemplateResponse> templateResponses = _responseGenerator.createTemplateResponses(template.getId(), snapshotId, volumeId, false);
|
||||
List<TemplateResponse> templateResponses;
|
||||
if (isBareMetal()) {
|
||||
templateResponses = _responseGenerator.createTemplateResponses(template.getId(), vmId);
|
||||
} else {
|
||||
templateResponses = _responseGenerator.createTemplateResponses(template.getId(), snapshotId, volumeId, false);
|
||||
}
|
||||
TemplateResponse response = new TemplateResponse();
|
||||
if (templateResponses != null && !templateResponses.isEmpty()) {
|
||||
response = templateResponses.get(0);
|
||||
|
|
|
|||
|
|
@ -156,6 +156,8 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
|
|||
// for agents that are self-managed, threshold to be considered as disconnected is 3 ping intervals
|
||||
long cutSeconds = (System.currentTimeMillis() >> 10) - (_pingInterval * 3);
|
||||
List<HostVO> hosts = _hostDao.findAndUpdateDirectAgentToLoad(cutSeconds, _loadSize, _nodeId);
|
||||
List<HostVO> appliances = _hostDao.findAndUpdateApplianceToLoad(cutSeconds, _nodeId);
|
||||
hosts.addAll(appliances);
|
||||
|
||||
if (hosts != null && hosts.size() > 0) {
|
||||
s_logger.debug("Found " + hosts.size() + " unmanaged direct hosts, processing connect for them...");
|
||||
|
|
|
|||
|
|
@ -1211,6 +1211,11 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
return vmResponse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Host findHostById(Long hostId) {
|
||||
return ApiDBUtils.findHostById(hostId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public User findUserById(Long userId) {
|
||||
return ApiDBUtils.findUserById(userId);
|
||||
|
|
@ -1621,7 +1626,6 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
|
||||
@Override
|
||||
public List<TemplateResponse> createTemplateResponses(long templateId, Long snapshotId, Long volumeId, boolean readyOnly) {
|
||||
Long zoneId = null;
|
||||
VolumeVO volume = null;
|
||||
if (snapshotId != null) {
|
||||
Snapshot snapshot = ApiDBUtils.findSnapshotById(snapshotId);
|
||||
|
|
@ -1631,6 +1635,14 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
}
|
||||
return createTemplateResponses(templateId, volume.getDataCenterId(), readyOnly);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TemplateResponse> createTemplateResponses(long templateId, Long vmId) {
|
||||
UserVm vm = findUserVmById(vmId);
|
||||
Long hostId = (vm.getHostId() == null ? vm.getLastHostId() : vm.getHostId());
|
||||
Host host = findHostById(hostId);
|
||||
return createTemplateResponses(templateId, host.getDataCenterId(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventResponse createEventResponse(Event event) {
|
||||
|
|
|
|||
|
|
@ -186,4 +186,6 @@ public interface HostDao extends GenericDao<HostVO, Long> {
|
|||
List<HostVO> listSecondaryStorageVM(long dcId);
|
||||
|
||||
List<HostVO> listAllRoutingAgents();
|
||||
|
||||
List<HostVO> findAndUpdateApplianceToLoad(long lastPingSecondsAfter, long managementServerId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
protected final SearchBuilder<HostVO> SequenceSearch;
|
||||
protected final SearchBuilder<HostVO> DirectlyConnectedSearch;
|
||||
protected final SearchBuilder<HostVO> UnmanagedDirectConnectSearch;
|
||||
protected final SearchBuilder<HostVO> UnmanagedExternalNetworkApplianceSearch;
|
||||
protected final SearchBuilder<HostVO> UnmanagedApplianceSearch;
|
||||
protected final SearchBuilder<HostVO> MaintenanceCountSearch;
|
||||
protected final SearchBuilder<HostVO> ClusterSearch;
|
||||
protected final SearchBuilder<HostVO> ConsoleProxyHostSearch;
|
||||
|
|
@ -99,6 +99,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
protected final SearchBuilder<HostVO> ManagedDirectConnectSearch;
|
||||
protected final SearchBuilder<HostVO> ManagedRoutingServersSearch;
|
||||
protected final SearchBuilder<HostVO> SecondaryStorageVMSearch;
|
||||
|
||||
|
||||
protected final GenericSearchBuilder<HostVO, Long> HostsInStatusSearch;
|
||||
protected final GenericSearchBuilder<HostVO, Long> CountRoutingByDc;
|
||||
|
|
@ -255,12 +256,12 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
DirectConnectSearch.cp();
|
||||
DirectConnectSearch.done();
|
||||
|
||||
UnmanagedExternalNetworkApplianceSearch = createSearchBuilder();
|
||||
UnmanagedExternalNetworkApplianceSearch.and("resource", UnmanagedExternalNetworkApplianceSearch.entity().getResource(), SearchCriteria.Op.NNULL);
|
||||
UnmanagedExternalNetworkApplianceSearch.and("server", UnmanagedExternalNetworkApplianceSearch.entity().getManagementServerId(), SearchCriteria.Op.NULL);
|
||||
UnmanagedExternalNetworkApplianceSearch.and("types", UnmanagedExternalNetworkApplianceSearch.entity().getType(), SearchCriteria.Op.IN);
|
||||
UnmanagedExternalNetworkApplianceSearch.and("lastPinged", UnmanagedExternalNetworkApplianceSearch.entity().getLastPinged(), SearchCriteria.Op.LTEQ);
|
||||
UnmanagedExternalNetworkApplianceSearch.done();
|
||||
UnmanagedApplianceSearch = createSearchBuilder();
|
||||
UnmanagedApplianceSearch.and("resource", UnmanagedApplianceSearch.entity().getResource(), SearchCriteria.Op.NNULL);
|
||||
UnmanagedApplianceSearch.and("server", UnmanagedApplianceSearch.entity().getManagementServerId(), SearchCriteria.Op.NULL);
|
||||
UnmanagedApplianceSearch.and("types", UnmanagedApplianceSearch.entity().getType(), SearchCriteria.Op.IN);
|
||||
UnmanagedApplianceSearch.and("lastPinged", UnmanagedApplianceSearch.entity().getLastPinged(), SearchCriteria.Op.LTEQ);
|
||||
UnmanagedApplianceSearch.done();
|
||||
|
||||
AvailHypevisorInZone = createSearchBuilder();
|
||||
AvailHypevisorInZone.and("zoneId", AvailHypevisorInZone.entity().getDataCenterId(), SearchCriteria.Op.EQ);
|
||||
|
|
@ -398,6 +399,26 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
|||
|
||||
return hosts;
|
||||
}
|
||||
|
||||
@Override @DB
|
||||
public List<HostVO> findAndUpdateApplianceToLoad(long lastPingSecondsAfter, long managementServerId) {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
|
||||
txn.start();
|
||||
SearchCriteria<HostVO> sc = UnmanagedApplianceSearch.create();
|
||||
sc.setParameters("lastPinged", lastPingSecondsAfter);
|
||||
sc.setParameters("types", Type.ExternalDhcp, Type.ExternalFirewall, Type.ExternalLoadBalancer, Type.PxeServer);
|
||||
List<HostVO> hosts = lockRows(sc, null, true);
|
||||
|
||||
for (HostVO host : hosts) {
|
||||
host.setManagementServerId(managementServerId);
|
||||
update(host.getId(), host);
|
||||
}
|
||||
|
||||
txn.commit();
|
||||
|
||||
return hosts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markHostsAsDisconnected(long msId) {
|
||||
|
|
|
|||
|
|
@ -1448,15 +1448,7 @@ dictionary = {
|
|||
<option value="false"><fmt:message key="label.no" /></option>
|
||||
<option value="true"><fmt:message key="label.yes" /></option>
|
||||
</select>
|
||||
</li>
|
||||
<li>
|
||||
<label>
|
||||
<fmt:message key="label.password.enabled" />:</label>
|
||||
<select class="select" name="create_template_password" id="create_template_password">
|
||||
<option value="false"><fmt:message key="label.no" /></option>
|
||||
<option value="true"><fmt:message key="label.yes" /></option>
|
||||
</select>
|
||||
</li>
|
||||
</li>
|
||||
<li id="image_directory_container">
|
||||
<label>
|
||||
<fmt:message key="image.directory" />:</label>
|
||||
|
|
|
|||
|
|
@ -2549,10 +2549,7 @@ function doCreateTemplateFromVM($actionLink, $detailsTab, $midmenuItem1) {
|
|||
|
||||
var isPublic = $thisDialog.find("#create_template_public").val();
|
||||
array1.push("&isPublic="+isPublic);
|
||||
|
||||
var password = $thisDialog.find("#create_template_password").val();
|
||||
array1.push("&passwordEnabled="+password);
|
||||
|
||||
|
||||
var imageDirectory = $thisDialog.find("#image_directory").val();
|
||||
array1.push("&url="+todb(imageDirectory));
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue