Skip to content

Commit 99be371

Browse files
committed
bug 3224:
multiple secondary storage, copying template between zone works
1 parent 24e86c1 commit 99be371

15 files changed

Lines changed: 216 additions & 301 deletions

File tree

api/src/com/cloud/agent/api/storage/DownloadCommand.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public DownloadCommand(DownloadCommand that) {
6161
this.id = that.id;
6262
this.description = that.description;
6363
this.auth = that.getAuth();
64+
this.setSecUrl(that.getSecUrl());
6465
this.maxDownloadSizeInBytes = that.getMaxDownloadSizeInBytes();
6566
}
6667

@@ -75,8 +76,13 @@ public DownloadCommand(String secUrl, VirtualMachineTemplate template, Long maxD
7576
}
7677

7778
public DownloadCommand(String secUrl, String url, VirtualMachineTemplate template, String user, String passwd, Long maxDownloadSizeInBytes) {
78-
this(secUrl, template, maxDownloadSizeInBytes);
79-
this.setUrl(url);
79+
super(template.getUniqueName(), url, template.getFormat(), template.getAccountId());
80+
this.hvm = template.isRequiresHvm();
81+
this.checksum = template.getChecksum();
82+
this.id = template.getId();
83+
this.description = template.getDisplayText();
84+
this.setSecUrl(secUrl);
85+
this.maxDownloadSizeInBytes = maxDownloadSizeInBytes;
8086
auth = new PasswordAuth(user, passwd);
8187
}
8288

api/src/com/cloud/api/commands/CopyIsoCmd.java

Lines changed: 0 additions & 125 deletions
This file was deleted.

api/src/com/cloud/template/TemplateService.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.net.URISyntaxException;
2121

2222
import com.cloud.api.commands.AttachIsoCmd;
23-
import com.cloud.api.commands.CopyIsoCmd;
2423
import com.cloud.api.commands.CopyTemplateCmd;
2524
import com.cloud.api.commands.DeleteIsoCmd;
2625
import com.cloud.api.commands.DeleteTemplateCmd;
@@ -39,8 +38,6 @@ public interface TemplateService {
3938

4039
VirtualMachineTemplate registerIso(RegisterIsoCmd cmd) throws IllegalArgumentException, ResourceAllocationException;
4140

42-
VirtualMachineTemplate copyIso(CopyIsoCmd cmd) throws StorageUnavailableException, ResourceAllocationException;
43-
4441
VirtualMachineTemplate copyTemplate(CopyTemplateCmd cmd) throws StorageUnavailableException, ResourceAllocationException;
4542

4643
boolean detachIso(DetachIsoCmd cmd);

client/tomcatconf/commands.properties.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ listIsos=com.cloud.api.commands.ListIsosCmd;15
7474
registerIso=com.cloud.api.commands.RegisterIsoCmd;15
7575
updateIso=com.cloud.api.commands.UpdateIsoCmd;15
7676
deleteIso=com.cloud.api.commands.DeleteIsoCmd;15
77-
copyIso=com.cloud.api.commands.CopyIsoCmd;15
77+
copyIso=com.cloud.api.commands.CopyTemplateCmd;15
7878
updateIsoPermissions=com.cloud.api.commands.UpdateIsoPermissionsCmd;15
7979
listIsoPermissions=com.cloud.api.commands.ListIsoPermissionsCmd;15
8080
extractIso=com.cloud.api.commands.ExtractIsoCmd;15

core/src/com/cloud/storage/JavaStorageLayer.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,25 @@ public boolean delete(String path) {
8989
return file.delete();
9090
}
9191
}
92-
92+
93+
@Override
94+
public boolean deleteDir(String dir) {
95+
File Dir = new File(dir);
96+
if ( !Dir.isDirectory() ) {
97+
return false;
98+
}
99+
100+
synchronized(dir.intern()) {
101+
File[] files = Dir.listFiles();
102+
for( File file : files) {
103+
if(!file.delete() ) {
104+
return false;
105+
}
106+
}
107+
}
108+
return true;
109+
}
110+
93111
@Override
94112
public boolean exists(String path) {
95113
synchronized(path.intern()) {

core/src/com/cloud/storage/StorageLayer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,6 @@ public interface StorageLayer extends Manager {
147147
* @return true if the file was set to be both world readable and writeable
148148
*/
149149
boolean setWorldReadableAndWriteable(File file);
150+
151+
boolean deleteDir(String dir);
150152
}

core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import java.util.HashMap;
3131
import java.util.List;
3232
import java.util.Map;
33-
import java.util.Random;
33+
3434
import java.util.UUID;
3535

3636
import javax.naming.ConfigurationException;
@@ -49,6 +49,7 @@
4949
import com.cloud.agent.api.ReadyAnswer;
5050
import com.cloud.agent.api.ReadyCommand;
5151
import com.cloud.agent.api.SecStorageFirewallCfgCommand;
52+
import com.cloud.agent.api.SecStorageSetupAnswer;
5253
import com.cloud.agent.api.SecStorageSetupCommand;
5354
import com.cloud.agent.api.StartupSecondaryStorageCommand;
5455
import com.cloud.agent.api.SecStorageFirewallCfgCommand.PortConfig;
@@ -95,8 +96,6 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
9596
boolean _inSystemVM = false;
9697
boolean _sslCopy = false;
9798

98-
Random _rand = new Random(System.currentTimeMillis());
99-
10099
DownloadManager _dlMgr;
101100
UploadManager _upldMgr;
102101
private String _configSslScr;
@@ -219,7 +218,11 @@ private Answer execute(SecStorageSetupCommand cmd) {
219218
String nfsHostIp = nfsHostAddr.getHostAddress();
220219

221220
addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask, nfsHostIp);
222-
return new Answer(cmd, true, "success");
221+
String nfsPath = nfsHostIp + ":" + uri.getPath();
222+
String dir = UUID.nameUUIDFromBytes(nfsPath.getBytes()).toString();
223+
String root = _parent + "/" + dir;
224+
mount(root, nfsPath);
225+
return new SecStorageSetupAnswer(dir);
223226
} catch (Exception e) {
224227
String msg = "GetRootDir for " + secUrl + " failed due to " + e.toString();
225228
s_logger.error(msg);
@@ -707,6 +710,15 @@ public StartupCommand[] initialize() {
707710
fillNetworkInformation(cmd);
708711
if(_publicIp != null)
709712
cmd.setPublicIpAddress(_publicIp);
713+
714+
Script command = new Script("/bin/bash", s_logger);
715+
command.add("-c");
716+
command.add("ln -sf " + _parent + " /var/www/html/copy");
717+
String result = command.execute();
718+
if (result != null) {
719+
s_logger.warn("Error in linking err=" + result);
720+
return null;
721+
}
710722
return new StartupCommand[] {cmd};
711723
}
712724

core/src/com/cloud/storage/template/DownloadManagerImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,9 @@ public String downloadPublicTemplate(long id, String url, String name, ImageForm
390390
}
391391

392392
File file = _storage.getFile(tmpDir + File.separator + TemplateLocation.Filename);
393+
if ( file.exists() ) {
394+
file.delete();
395+
}
393396

394397
if (!file.createNewFile()) {
395398
s_logger.warn("Unable to create new file: " + file.getAbsolutePath());

server/src/com/cloud/storage/StorageManager.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,5 +193,7 @@ VolumeVO createVolume(VolumeVO volume, VMInstanceVO vm, VMTemplateVO template, D
193193

194194
boolean createStoragePool(long hostId, StoragePoolVO pool);
195195

196-
boolean delPoolFromHost(long hostId);
196+
boolean delPoolFromHost(long hostId);
197+
198+
HostVO getSecondaryStorageHost(long zoneId, long tmpltId);
197199
}

server/src/com/cloud/storage/StorageManagerImpl.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,21 @@ public String getSecondaryStorageURL(long zoneId) {
940940
return secondaryStorageHost.getStorageUrl();
941941
}
942942

943+
@Override
944+
public HostVO getSecondaryStorageHost(long zoneId, long tmpltId) {
945+
List<HostVO> hosts = _hostDao.listSecondaryStorageHosts(zoneId);
946+
if( hosts == null || hosts.size() == 0) {
947+
return null;
948+
}
949+
for( HostVO host : hosts ) {
950+
VMTemplateHostVO tmpltHost = _vmTemplateHostDao.findByHostTemplate(host.getId(), tmpltId);
951+
if (tmpltHost != null && !tmpltHost.getDestroyed() && tmpltHost.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) {
952+
return host;
953+
}
954+
}
955+
return null;
956+
}
957+
943958
@Override
944959
public HostVO getSecondaryStorageHost(long zoneId) {
945960
List<HostVO> hosts = _hostDao.listSecondaryStorageHosts(zoneId);

0 commit comments

Comments
 (0)