Skip to content

Commit c443867

Browse files
author
Alex Huang
committed
more changes
1 parent 49143db commit c443867

28 files changed

Lines changed: 512 additions & 178 deletions

agent/src/com/cloud/agent/resource/computing/LibvirtComputingResource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
import com.cloud.agent.api.storage.DestroyCommand;
138138
import com.cloud.agent.api.storage.DownloadAnswer;
139139
import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
140-
import com.cloud.agent.api.to.StoragePoolTO;
140+
import com.cloud.agent.api.to.StorageFilerTO;
141141
import com.cloud.agent.api.to.VolumeTO;
142142
import com.cloud.agent.resource.computing.LibvirtStoragePoolDef.poolType;
143143
import com.cloud.agent.resource.computing.LibvirtStorageVolumeDef.volFormat;
@@ -1173,7 +1173,7 @@ protected Storage.StorageResourceType getStorageResourceType() {
11731173
}
11741174

11751175
protected Answer execute(CreateCommand cmd) {
1176-
StoragePoolTO pool = cmd.getPool();
1176+
StorageFilerTO pool = cmd.getPool();
11771177
DiskProfile dskch = cmd.getDiskCharacteristics();
11781178
StorageVol tmplVol = null;
11791179
StoragePool primaryPool = null;
File renamed without changes.

core/src/com/cloud/agent/api/storage/CreateCommand.java renamed to api/src/com/cloud/agent/api/storage/CreateCommand.java

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,16 @@
1818
package com.cloud.agent.api.storage;
1919

2020
import com.cloud.agent.api.Command;
21-
import com.cloud.agent.api.to.StoragePoolTO;
22-
import com.cloud.storage.StoragePoolVO;
23-
import com.cloud.storage.VolumeVO;
21+
import com.cloud.agent.api.to.StorageFilerTO;
22+
import com.cloud.storage.StoragePool;
2423
import com.cloud.vm.DiskProfile;
25-
import com.cloud.vm.VMInstanceVO;
2624

2725
public class CreateCommand extends Command {
2826
private long volId;
29-
private StoragePoolTO pool;
27+
private StorageFilerTO pool;
3028
private DiskProfile diskCharacteristics;
3129
private String templateUrl;
3230
private long size;
33-
private String instanceName;
3431

3532
protected CreateCommand() {
3633
super();
@@ -45,8 +42,8 @@ protected CreateCommand() {
4542
* @param templateUrl
4643
* @param pool
4744
*/
48-
public CreateCommand(VolumeVO vol, VMInstanceVO vm, DiskProfile diskCharacteristics, String templateUrl, StoragePoolVO pool) {
49-
this(vol, vm, diskCharacteristics, pool, 0);
45+
public CreateCommand(DiskProfile diskCharacteristics, String templateUrl, StorageFilerTO pool) {
46+
this(diskCharacteristics, pool, 0);
5047
this.templateUrl = templateUrl;
5148
}
5249

@@ -58,13 +55,20 @@ public CreateCommand(VolumeVO vol, VMInstanceVO vm, DiskProfile diskCharacterist
5855
* @param diskCharacteristics
5956
* @param pool
6057
*/
61-
public CreateCommand(VolumeVO vol, VMInstanceVO vm, DiskProfile diskCharacteristics, StoragePoolVO pool, long size) {
62-
this.volId = vol.getId();
58+
public CreateCommand(DiskProfile diskCharacteristics, StorageFilerTO pool, long size) {
59+
this.volId = diskCharacteristics.getVolumeId();
6360
this.diskCharacteristics = diskCharacteristics;
64-
this.pool = new StoragePoolTO(pool);
61+
this.pool = pool;
6562
this.templateUrl = null;
6663
this.size = size;
67-
//this.instanceName = vm.getInstanceName();
64+
}
65+
66+
public CreateCommand(DiskProfile diskCharacteristics, String templateUrl, StoragePool pool) {
67+
this(diskCharacteristics, templateUrl, new StorageFilerTO(pool));
68+
}
69+
70+
public CreateCommand(DiskProfile diskCharacteristics, StoragePool pool, long size) {
71+
this(diskCharacteristics, new StorageFilerTO(pool), size);
6872
}
6973

7074
@Override
@@ -76,7 +80,7 @@ public String getTemplateUrl() {
7680
return templateUrl;
7781
}
7882

79-
public StoragePoolTO getPool() {
83+
public StorageFilerTO getPool() {
8084
return pool;
8185
}
8286

@@ -92,7 +96,8 @@ public long getSize(){
9296
return this.size;
9397
}
9498

99+
@Deprecated
95100
public String getInstanceName() {
96-
return instanceName;
101+
return null;
97102
}
98103
}

core/src/com/cloud/agent/api/to/StoragePoolTO.java renamed to api/src/com/cloud/agent/api/to/StorageFilerTO.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,18 @@
1717
*/
1818
package com.cloud.agent.api.to;
1919

20-
import com.cloud.storage.StoragePoolVO;
2120
import com.cloud.storage.Storage.StoragePoolType;
21+
import com.cloud.storage.StoragePool;
2222

23-
24-
public class StoragePoolTO {
23+
public class StorageFilerTO {
2524
long id;
2625
String uuid;
2726
String host;
2827
String path;
2928
int port;
3029
StoragePoolType type;
3130

32-
public StoragePoolTO(StoragePoolVO pool) {
31+
public StorageFilerTO(StoragePool pool) {
3332
this.id = pool.getId();
3433
this.host = pool.getHostAddress();
3534
this.port = pool.getPort();
@@ -62,7 +61,7 @@ public StoragePoolType getType() {
6261
return type;
6362
}
6463

65-
protected StoragePoolTO() {
64+
protected StorageFilerTO() {
6665
}
6766

6867
@Override

api/src/com/cloud/exception/StorageUnavailableException.java

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,39 @@
2020
import com.cloud.utils.SerialVersionUID;
2121

2222
/**
23-
* This exception is thrown when the storage device can not be reached.
24-
*
23+
* This exception is thrown when storage for a VM is unavailable.
24+
* If the cause is due to storage pool unavailable, calling
25+
* getOffendingObject() will return the object that we have
26+
* problem with.
27+
*
2528
*/
26-
public class StorageUnavailableException extends AgentUnavailableException {
29+
public class StorageUnavailableException extends Exception {
30+
Object _obj;
2731

2832
private static final long serialVersionUID = SerialVersionUID.StorageUnavailableException;
2933

30-
public StorageUnavailableException(long hostId) {
31-
super(hostId);
32-
}
33-
3434
public StorageUnavailableException(String msg) {
35-
super(msg, -1);
35+
super(msg);
36+
}
37+
38+
public StorageUnavailableException(String msg, Throwable cause) {
39+
super(msg, cause);
40+
}
41+
42+
public StorageUnavailableException(String msg, Object cause) {
43+
super(msg);
44+
_obj = cause;
45+
}
46+
47+
public StorageUnavailableException(String msg, Object obj, Throwable cause) {
48+
super(msg, cause);
49+
_obj = obj;
50+
}
51+
52+
/**
53+
* @return object that caused this problem. It can either be a StoragePool or volume.
54+
*/
55+
public Object getOffendingObject() {
56+
return _obj;
3657
}
3758
}

api/src/com/cloud/network/NetworkConfiguration.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ enum Event {
2323
}
2424

2525
enum State implements FiniteState<State, Event> {
26-
Allocated, // Indicates the network configuration is in allocated but not setup.
27-
Setup, // Indicates the network configuration is setup.
28-
Implemented, // Indicates the network configuration is in use.
29-
Destroying;
26+
Allocated("Indicates the network configuration is in allocated but not setup"),
27+
Setup("Indicates the network configuration is setup"),
28+
Implemented("Indicates the network configuration is in use"),
29+
Destroying("Indicates the network configuration is being destroyed");
3030

3131
@Override
3232
public StateMachine<State, Event> getStateMachine() {
@@ -48,7 +48,23 @@ public Set<Event> getPossibleEvents() {
4848
return s_fsm.getPossibleEvents(this);
4949
}
5050

51+
String _description;
52+
53+
@Override
54+
public String getDescription() {
55+
return _description;
56+
}
57+
58+
private State(String description) {
59+
_description = description;
60+
}
61+
5162
private static StateMachine<State, Event> s_fsm = new StateMachine<State, Event>();
63+
static {
64+
s_fsm.addTransition(State.Allocated, Event.ImplementNetwork, State.Implemented);
65+
s_fsm.addTransition(State.Implemented, Event.DestroyNetwork, State.Destroying);
66+
}
67+
5268
}
5369

5470

api/src/com/cloud/resource/Resource.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ enum Event {
2626
}
2727

2828
enum State implements FiniteState<State, Event> {
29-
Allocated, // Resource is allocated
30-
Reserving, // Resource is being reserved right now.
31-
Reserved, // Resource is reserved
32-
Releasing, // Resource is being released.
33-
Ready; // Resource is ready which means it does not need to go through reservation.
29+
Allocated("Resource is allocated but not reserved"),
30+
Reserving("Resource is being reserved right now"),
31+
Reserved("Resource has been reserved."),
32+
Releasing("Resource is being released"),
33+
Ready("Resource is ready which means it doesn't need to go through resservation");
3434

35+
String _description;
36+
3537
@Override
3638
public StateMachine<State, Event> getStateMachine() {
3739

@@ -54,12 +56,24 @@ public Set<Event> getPossibleEvents() {
5456
return s_fsm.getPossibleEvents(this);
5557
}
5658

59+
private State(String description) {
60+
_description = description;
61+
}
62+
63+
@Override
64+
public String getDescription() {
65+
return _description;
66+
}
67+
5768
final static private StateMachine<State, Event> s_fsm = new StateMachine<State, Event>();
5869
static {
5970
s_fsm.addTransition(State.Allocated, Event.ReservationRequested, State.Reserving);
6071
s_fsm.addTransition(State.Reserving, Event.CancelRequested, State.Allocated);
6172
s_fsm.addTransition(State.Reserving, Event.OperationCompleted, State.Reserved);
6273
s_fsm.addTransition(State.Reserving, Event.OperationFailed, State.Allocated);
74+
s_fsm.addTransition(State.Reserved, Event.ReleaseRequested, State.Releasing);
75+
s_fsm.addTransition(State.Releasing, Event.OperationCompleted, State.Allocated);
76+
s_fsm.addTransition(State.Releasing, Event.OperationFailed, State.Reserved);
6377
}
6478
}
6579

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
3+
*
4+
* This software is licensed under the GNU General Public License v3 or later.
5+
*
6+
* It is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or any later version.
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
*/
18+
package com.cloud.storage;
19+
20+
import com.cloud.utils.component.Adapter;
21+
22+
/**
23+
* StorageGuru understands about how to implement different
24+
* types of storage pools.
25+
*/
26+
public interface StorageGuru extends Adapter {
27+
void createVolume();
28+
void prepareVolume();
29+
void destroyVolume();
30+
}

0 commit comments

Comments
 (0)