mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
fix user data, and template sync
This commit is contained in:
parent
b06d477425
commit
59a6e2157a
@ -21,6 +21,7 @@ package com.cloud.agent.vmdata;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
@ -38,6 +39,7 @@ import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.mortbay.jetty.Connector;
|
||||
import org.mortbay.jetty.Handler;
|
||||
@ -294,10 +296,18 @@ public class JettyVmDataServer implements VmDataServer {
|
||||
try {
|
||||
_fs.create(vmDataDir, item[1]);
|
||||
String vmDataFile = vmDataDir + File.separator + item[1];
|
||||
byte[] data;
|
||||
if (item[2] != null) {
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(vmDataFile));
|
||||
writer.write(item[2]);
|
||||
writer.close();
|
||||
if (item[1].equals("userdata")) {
|
||||
data = Base64.decodeBase64(item[2]);
|
||||
} else {
|
||||
data = item[2].getBytes();
|
||||
}
|
||||
if (data != null && data.length > 0) {
|
||||
FileOutputStream writer = new FileOutputStream(vmDataFile);
|
||||
writer.write(data);
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
s_logger.warn("Failed to write vm data item " + item[1], e);
|
||||
|
||||
@ -489,9 +489,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager {
|
||||
@Override
|
||||
public HostVO getSSAgent(HostVO ssHost) {
|
||||
if( ssHost.getType() == Host.Type.LocalSecondaryStorage ) {
|
||||
if( ssHost.getStatus() == Status.Up ) {
|
||||
return ssHost;
|
||||
}
|
||||
return ssHost;
|
||||
} else if ( ssHost.getType() == Host.Type.SecondaryStorage) {
|
||||
Long dcId = ssHost.getDataCenterId();
|
||||
List<HostVO> ssAHosts = _hostDao.listBy(Host.Type.SecondaryStorageVM, dcId);
|
||||
|
||||
@ -484,12 +484,14 @@ public class ApiDBUtils {
|
||||
if (vmTemplate.getHypervisorType() == HypervisorType.BareMetal) {
|
||||
return _templateHostDao.listByTemplateId(templateId);
|
||||
} else {
|
||||
HostVO secondaryStorageHost = _storageMgr.getSecondaryStorageHost(zoneId);
|
||||
if (secondaryStorageHost == null) {
|
||||
return new ArrayList<VMTemplateHostVO>();
|
||||
} else {
|
||||
return _templateHostDao.listByHostTemplate(secondaryStorageHost.getId(), templateId);
|
||||
List<VMTemplateHostVO> templates = new ArrayList<VMTemplateHostVO>();
|
||||
List<HostVO> secondaryStorageHosts = _storageMgr.getSecondaryStorageHosts(zoneId);
|
||||
if (!secondaryStorageHosts.isEmpty()) {
|
||||
for (HostVO ssh : secondaryStorageHosts) {
|
||||
templates.addAll(_templateHostDao.listByHostTemplate(ssh.getId(), templateId));
|
||||
}
|
||||
}
|
||||
return templates;
|
||||
}
|
||||
} else {
|
||||
return _templateHostDao.listByOnlyTemplateId(templateId);
|
||||
|
||||
@ -195,5 +195,7 @@ public interface StorageManager extends Manager {
|
||||
|
||||
boolean delPoolFromHost(long hostId);
|
||||
|
||||
HostVO getSecondaryStorageHost(long zoneId, long tmpltId);
|
||||
HostVO getSecondaryStorageHost(long zoneId, long tmpltId);
|
||||
|
||||
List<HostVO> getSecondaryStorageHosts(long zoneId);
|
||||
}
|
||||
|
||||
@ -970,6 +970,18 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
|
||||
int index = rn.nextInt(size);
|
||||
return hosts.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HostVO> getSecondaryStorageHosts(long zoneId) {
|
||||
List<HostVO> hosts = _hostDao.listSecondaryStorageHosts(zoneId);
|
||||
if( hosts == null || hosts.size() == 0) {
|
||||
hosts = _hostDao.listLocalSecondaryStorageHosts(zoneId);
|
||||
if (hosts.isEmpty()) {
|
||||
return new ArrayList<HostVO>();
|
||||
}
|
||||
}
|
||||
return hosts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStoragePoolTags(long poolId) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user