Skip to content

Commit b81fa6d

Browse files
committed
add copy template to cache store
1 parent bb64672 commit b81fa6d

37 files changed

Lines changed: 527 additions & 75 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public abstract class AbstractDownloadCommand extends ssCommand {
2828
protected AbstractDownloadCommand() {
2929
}
3030

31-
protected AbstractDownloadCommand(String name, String url, ImageFormat format, long accountId) {
31+
protected AbstractDownloadCommand(String name, String url, ImageFormat format, Long accountId) {
3232
assert(url != null);
3333
url = url.replace('\\', '/');
3434

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,16 @@ public class PrimaryStorageDownloadCommand extends AbstractDownloadCommand {
3434
String primaryStorageUrl;
3535

3636
protected PrimaryStorageDownloadCommand() {
37+
3738
}
39+
40+
public PrimaryStorageDownloadCommand(String url, StoragePool pool, int wait) {
41+
super(null, url, null, null);
42+
this.poolId = pool.getId();
43+
this.poolUuid = pool.getUuid();
44+
this.primaryPool = new StorageFilerTO(pool);
45+
setWait(wait);
46+
}
3847

3948
public PrimaryStorageDownloadCommand(String name, String url, ImageFormat format, long accountId, StoragePool pool, int wait) {
4049
super(name, url, format, accountId);

engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataObject.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@
2020

2121
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.DiskFormat;
2222

23+
import com.cloud.agent.api.Answer;
24+
2325
public interface DataObject {
2426
public long getId();
2527
public String getUri();
28+
public DataTO getTO();
2629
public DataStore getDataStore();
2730
public Long getSize();
2831
public DataObjectType getType();
2932
public DiskFormat getFormat();
3033
public String getUuid();
3134
public void processEvent(ObjectInDataStoreStateMachine.Event event);
35+
public void processEvent(ObjectInDataStoreStateMachine.Event event, Answer answer);
3236
}

engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStore.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ public interface DataStore {
2626
String getName();
2727
DataObject create(DataObject obj);
2828
boolean delete(DataObject obj);
29+
DataStoreTO getTO();
2930
}

engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreDriver.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ public interface DataStoreDriver {
3131
public void copyAsync(DataObject srcdata, DataObject destData, AsyncCompletionCallback<CopyCommandResult> callback);
3232
public boolean canCopy(DataObject srcData, DataObject destData);
3333
public void resize(DataObject data, AsyncCompletionCallback<CreateCmdResult> callback);
34+
public DataTO getTO(DataObject data);
3435
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.cloudstack.engine.subsystem.api.storage;
20+
21+
public interface DataStoreTO {
22+
public DataStoreRole getRole();
23+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.cloudstack.engine.subsystem.api.storage;
20+
21+
public interface DataTO {
22+
public DataObjectType getObjectType();
23+
public DataStoreTO getDataStore();
24+
/**
25+
* @return
26+
*/
27+
String getPath();
28+
}

engine/storage/src/org/apache/cloudstack/storage/endpoint/EndPointSelector.java renamed to engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/EndPointSelector.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,10 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
package org.apache.cloudstack.storage.endpoint;
19+
package org.apache.cloudstack.engine.subsystem.api.storage;
2020

2121
import java.util.List;
2222

23-
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
24-
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
25-
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
2623

2724
public interface EndPointSelector {
2825
public EndPoint select(DataObject srcData, DataObject destData);

engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateInfo.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@
1919
package org.apache.cloudstack.engine.subsystem.api.storage;
2020

2121
public interface TemplateInfo extends DataObject {
22+
public String getUniqueName();
2223
}

engine/storage/cache/src/org/apache/cloudstack/storage/cache/manager/StorageCacheManagerImpl.java

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,30 @@
2020

2121
import java.util.List;
2222
import java.util.Map;
23+
import java.util.concurrent.ExecutionException;
2324

2425
import javax.inject.Inject;
2526
import javax.naming.ConfigurationException;
2627

28+
import org.apache.cloudstack.engine.subsystem.api.storage.CommandResult;
2729
import org.apache.cloudstack.engine.subsystem.api.storage.DataMotionService;
2830
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
2931
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
32+
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event;
3033
import org.apache.cloudstack.engine.subsystem.api.storage.Scope;
3134
import org.apache.cloudstack.engine.subsystem.api.storage.StorageCacheManager;
35+
import org.apache.cloudstack.framework.async.AsyncCallFuture;
36+
import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher;
37+
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
38+
import org.apache.cloudstack.framework.async.AsyncRpcConext;
3239
import org.apache.cloudstack.storage.cache.allocator.StorageCacheAllocator;
40+
import org.apache.log4j.Logger;
3341

3442
import com.cloud.utils.component.Manager;
3543

3644
public class StorageCacheManagerImpl implements StorageCacheManager, Manager {
45+
private static final Logger s_logger = Logger
46+
.getLogger(StorageCacheManagerImpl.class);
3747
@Inject
3848
List<StorageCacheAllocator> storageCacheAllocator;
3949
@Inject
@@ -101,14 +111,62 @@ public boolean stop() {
101111
// TODO Auto-generated method stub
102112
return true;
103113
}
114+
115+
116+
117+
private class CreateCacheObjectContext<T> extends AsyncRpcConext<T> {
118+
final AsyncCallFuture<CommandResult> future;
119+
/**
120+
* @param callback
121+
*/
122+
public CreateCacheObjectContext(AsyncCompletionCallback<T> callback, AsyncCallFuture<CommandResult> future) {
123+
super(callback);
124+
this.future = future;
125+
}
126+
127+
}
104128

105129
@Override
106130
public DataObject createCacheObject(DataObject data, Scope scope) {
107131
DataStore cacheStore = this.getCacheStorage(scope);
108132
DataObject objOnCacheStore = cacheStore.create(data);
109-
//AsyncCallFuture<>
110-
//dataMotionSvr.copyAsync(data, objOnCacheStore, callback);
111-
// TODO Auto-generated method stub
133+
AsyncCallFuture<CommandResult> future = new AsyncCallFuture<CommandResult>();
134+
CreateCacheObjectContext<CommandResult> context = new CreateCacheObjectContext<CommandResult>(null, future);
135+
AsyncCallbackDispatcher<StorageCacheManagerImpl, CommandResult> caller = AsyncCallbackDispatcher.create(this);
136+
caller.setContext(context);
137+
138+
139+
CommandResult result = null;
140+
try {
141+
objOnCacheStore.processEvent(Event.CreateOnlyRequested);
142+
143+
dataMotionSvr.copyAsync(data, objOnCacheStore, caller);
144+
result = future.get();
145+
146+
if (result.isFailed()) {
147+
cacheStore.delete(data);
148+
} else {
149+
objOnCacheStore.processEvent(Event.OperationSuccessed);
150+
}
151+
} catch (InterruptedException e) {
152+
s_logger.debug("create cache storage failed: " + e.toString());
153+
} catch (ExecutionException e) {
154+
s_logger.debug("create cache storage failed: " + e.toString());
155+
} catch (Exception e) {
156+
s_logger.debug("create cache storage failed: " + e.toString());
157+
} finally {
158+
if (result == null) {
159+
cacheStore.delete(data);
160+
}
161+
}
162+
112163
return null;
113164
}
165+
166+
protected Void createCacheObjectCallBack(AsyncCallbackDispatcher<StorageCacheManagerImpl, CommandResult> callback,
167+
CreateCacheObjectContext<CommandResult> context) {
168+
AsyncCallFuture<CommandResult> future = context.future;
169+
future.complete(callback.getResult());
170+
return null;
171+
}
114172
}

0 commit comments

Comments
 (0)