Skip to content

Commit aa678bb

Browse files
committed
add support to add setup persistent networks' resources when a disabled host is enabled
1 parent 9a9d042 commit aa678bb

File tree

10 files changed

+92
-23
lines changed

10 files changed

+92
-23
lines changed

engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/HypervisorHostListener.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@ public interface HypervisorHostListener {
3030
boolean hostAboutToBeRemoved(long hostId);
3131

3232
boolean hostRemoved(long hostId, long clusterId);
33+
34+
boolean hostEnabled(long hostId);
3335
}

engine/components-api/src/main/java/com/cloud/storage/StorageManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ public interface StorageManager extends StorageService {
268268

269269
void disconnectHostFromSharedPool(long hostId, long poolId) throws StorageUnavailableException, StorageConflictException;
270270

271+
void enableHost(long hostId) throws StorageUnavailableException, StorageConflictException;
272+
271273
void createCapacityEntry(long poolId);
272274

273275
DataStore createLocalStorage(Host host, StoragePoolInfo poolInfo) throws ConnectionException;

engine/storage/volume/src/main/java/org/apache/cloudstack/storage/datastore/provider/DefaultHostListener.java

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -96,25 +96,7 @@ private boolean createPersistentNetworkResourcesOnHost(long hostId) {
9696
s_logger.warn(String.format("Host with id %ld can't be found", hostId));
9797
return false;
9898
}
99-
100-
List<NetworkVO> allPersistentNetworks = networkDao.getAllPersistentNetworksFromZone(host.getDataCenterId());
101-
102-
for (NetworkVO networkVO : allPersistentNetworks) {
103-
NetworkOfferingVO networkOfferingVO = networkOfferingDao.findById(networkVO.getNetworkOfferingId());
104-
105-
SetupPersistentNetworkCommand persistentNetworkCommand =
106-
new SetupPersistentNetworkCommand(createNicTOFromNetworkAndOffering(networkVO, networkOfferingVO, host));
107-
Answer answer = agentMgr.easySend(hostId, persistentNetworkCommand);
108-
if (answer == null) {
109-
throw new CloudRuntimeException("Unable to get answer to the setup persistent network command " + networkVO.getId());
110-
}
111-
if (!answer.getResult()) {
112-
String msg = String.format("Unable to create L2 persistent network resources from network %ld on the host %ld in zone %ld", networkVO.getId(), hostId, networkVO.getDataCenterId());
113-
alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, networkVO.getDataCenterId(), host.getPodId(), msg, msg);
114-
throw new CloudRuntimeException("Unable to create persistent network resources from network " + networkVO.getId() +
115-
" on " + hostId + " due to " + answer.getDetails());
116-
}
117-
}
99+
setupPersistentNetwork(host);
118100
return true;
119101
}
120102

@@ -224,12 +206,12 @@ public boolean hostAboutToBeRemoved(long hostId) {
224206
new CleanupPersistentNetworkResourceCommand(createNicTOFromNetworkAndOffering(persistentNetworkVO, networkOfferingVO, host));
225207
Answer answer = agentMgr.easySend(hostId, cleanupCmd);
226208
if (answer == null) {
227-
throw new CloudRuntimeException("Unable to get answer to the cleanup persistent network command " + persistentNetworkVO.getId());
209+
s_logger.error("Unable to get answer to the cleanup persistent network command " + persistentNetworkVO.getId());
210+
continue;
228211
}
229212
if (!answer.getResult()) {
230-
String msg = String.format("Unable to cleanup L2 persistent network resources from network %ld on the host %ld", persistentNetworkVO.getId(), hostId);
231-
232-
alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, persistentNetworkVO.getDataCenterId(), host.getPodId(), msg, msg);
213+
String msg = String.format("Unable to cleanup persistent network resources from network %d on the host %d", persistentNetworkVO.getId(), hostId);
214+
s_logger.error(msg);
233215
}
234216
}
235217
return true;
@@ -239,4 +221,34 @@ public boolean hostAboutToBeRemoved(long hostId) {
239221
public boolean hostRemoved(long hostId, long clusterId) {
240222
return true;
241223
}
224+
225+
@Override
226+
public boolean hostEnabled(long hostId) {
227+
HostVO host = hostDao.findById(hostId);
228+
if (host == null) {
229+
s_logger.warn(String.format("Host with id %d can't be found", hostId));
230+
return false;
231+
}
232+
setupPersistentNetwork(host);
233+
return true;
234+
}
235+
236+
private void setupPersistentNetwork(HostVO host) {
237+
List<NetworkVO> allPersistentNetworks = networkDao.getAllPersistentNetworksFromZone(host.getDataCenterId());
238+
239+
for (NetworkVO networkVO : allPersistentNetworks) {
240+
NetworkOfferingVO networkOfferingVO = networkOfferingDao.findById(networkVO.getNetworkOfferingId());
241+
242+
SetupPersistentNetworkCommand persistentNetworkCommand =
243+
new SetupPersistentNetworkCommand(createNicTOFromNetworkAndOffering(networkVO, networkOfferingVO, host));
244+
Answer answer = agentMgr.easySend(host.getId(), persistentNetworkCommand);
245+
if (answer == null) {
246+
throw new CloudRuntimeException("Unable to get answer to the setup persistent network command " + networkVO.getId());
247+
}
248+
if (!answer.getResult()) {
249+
String msg = String.format("Unable to create persistent network resources for network %d on the host %d in zone %d", networkVO.getId(), host.getId(), networkVO.getDataCenterId());
250+
s_logger.error(msg);
251+
}
252+
}
253+
}
242254
}

plugins/storage/volume/cloudbyte/src/main/java/org/apache/cloudstack/storage/datastore/provider/ElastistorHostListener.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,9 @@ public boolean hostAboutToBeRemoved(long hostId) {
140140
public boolean hostRemoved(long hostId, long clusterId) {
141141
return true;
142142
}
143+
144+
@Override
145+
public boolean hostEnabled(long hostId) {
146+
return true;
147+
}
143148
}

plugins/storage/volume/datera/src/main/java/org/apache/cloudstack/storage/datastore/provider/DateraHostListener.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ public boolean hostRemoved(long hostId, long clusterId) {
178178
return true;
179179
}
180180

181+
@Override
182+
public boolean hostEnabled(long hostId) {
183+
return true;
184+
}
185+
181186
private void handleXenServer(long clusterId, long hostId, long storagePoolId) {
182187
List<String> storagePaths = getStoragePaths(clusterId, storagePoolId);
183188

plugins/storage/volume/nexenta/src/main/java/org/apache/cloudstack/storage/datastore/provider/NexentaHostListener.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,9 @@ public boolean hostRemoved(long hostId, long clusterId) {
5959

6060
return true;
6161
}
62+
63+
@Override
64+
public boolean hostEnabled(long hostId) {
65+
return true;
66+
}
6267
}

plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/provider/ScaleIOHostListener.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,9 @@ public boolean hostAboutToBeRemoved(long hostId) {
138138
public boolean hostRemoved(long hostId, long clusterId) {
139139
return true;
140140
}
141+
142+
@Override
143+
public boolean hostEnabled(long hostId) {
144+
return true;
145+
}
141146
}

plugins/storage/volume/solidfire/src/main/java/org/apache/cloudstack/storage/datastore/provider/SolidFireHostListener.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ public boolean hostRemoved(long hostId, long clusterId) {
141141
return true;
142142
}
143143

144+
@Override
145+
public boolean hostEnabled(long hostId) {
146+
return true;
147+
}
148+
144149
private void handleXenServer(long clusterId, long hostId, long storagePoolId) {
145150
List<String> storagePaths = getStoragePaths(clusterId, storagePoolId);
146151

plugins/storage/volume/solidfire/src/main/java/org/apache/cloudstack/storage/datastore/provider/SolidFireSharedHostListener.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ public boolean hostRemoved(long hostId, long clusterId) {
140140
return true;
141141
}
142142

143+
@Override
144+
public boolean hostEnabled(long hostId) {
145+
return true;
146+
}
147+
143148
private void handleVMware(HostVO host, boolean add, ModifyTargetsCommand.TargetTypeToRemove targetTypeToRemove) {
144149
if (HypervisorType.VMware.equals(host.getHypervisorType())) {
145150
List<StoragePoolVO> storagePools = storagePoolDao.findPoolsByProvider(SolidFireUtil.SHARED_PROVIDER_NAME);

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver;
8080
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
8181
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle;
82+
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreProvider;
8283
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory;
8384
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
8485
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotService;
@@ -1119,6 +1120,28 @@ public void disconnectHostFromSharedPool(long hostId, long poolId) throws Storag
11191120
listener.hostDisconnected(hostId, pool.getId());
11201121
}
11211122

1123+
@Override
1124+
public void enableHost(long hostId) throws StorageUnavailableException, StorageConflictException {
1125+
List<DataStoreProvider> providers = _dataStoreProviderMgr.getProviders();
1126+
1127+
if (providers != null) {
1128+
for (DataStoreProvider provider : providers) {
1129+
if (provider instanceof PrimaryDataStoreProvider) {
1130+
try {
1131+
HypervisorHostListener hypervisorHostListener = provider.getHostListener();
1132+
1133+
if (hypervisorHostListener != null) {
1134+
hypervisorHostListener.hostEnabled(hostId);
1135+
}
1136+
}
1137+
catch (Exception ex) {
1138+
s_logger.error("hostEnabled(long) failed for storage provider " + provider.getName(), ex);
1139+
}
1140+
}
1141+
}
1142+
}
1143+
}
1144+
11221145
@Override
11231146
public BigDecimal getStorageOverProvisioningFactor(Long poolId) {
11241147
return new BigDecimal(CapacityManager.StorageOverprovisioningFactor.valueIn(poolId));

0 commit comments

Comments
 (0)