Skip to content

Commit 0785ba0

Browse files
committed
Merge branch '4.19' of https://github.com/apache/cloudstack into 4.20
2 parents 5d28e66 + 9d9737a commit 0785ba0

File tree

35 files changed

+868
-962
lines changed

35 files changed

+868
-962
lines changed

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,12 +477,11 @@ public class ApiConstants {
477477
public static final String STATE = "state";
478478
public static final String STATS = "stats";
479479
public static final String STATUS = "status";
480+
public static final String STORAGE_TYPE = "storagetype";
481+
public static final String STORAGE_POLICY = "storagepolicy";
482+
public static final String STORAGE_MOTION_ENABLED = "storagemotionenabled";
480483
public static final String STORAGE_CAPABILITIES = "storagecapabilities";
481484
public static final String STORAGE_CUSTOM_STATS = "storagecustomstats";
482-
public static final String STORAGE_MOTION_ENABLED = "storagemotionenabled";
483-
public static final String STORAGE_POLICY = "storagepolicy";
484-
public static final String STORAGE_POOL = "storagepool";
485-
public static final String STORAGE_TYPE = "storagetype";
486485
public static final String SUBNET = "subnet";
487486
public static final String OWNER = "owner";
488487
public static final String SWAP_OWNER = "swapowner";

api/src/main/java/org/apache/cloudstack/api/response/HostResponse.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public class HostResponse extends BaseResponseWithAnnotations {
152152
@Deprecated
153153
@SerializedName("memoryallocated")
154154
@Param(description = "the amount of the host's memory currently allocated")
155-
private Long memoryAllocated;
155+
private long memoryAllocated;
156156

157157
@SerializedName("memoryallocatedpercentage")
158158
@Param(description = "the amount of the host's memory currently allocated in percentage")
@@ -407,7 +407,7 @@ public void setMemWithOverprovisioning(String memWithOverprovisioning){
407407
this.memWithOverprovisioning=memWithOverprovisioning;
408408
}
409409

410-
public void setMemoryAllocated(Long memoryAllocated) {
410+
public void setMemoryAllocated(long memoryAllocated) {
411411
this.memoryAllocated = memoryAllocated;
412412
}
413413

@@ -687,8 +687,8 @@ public Long getMemoryTotal() {
687687
return memoryTotal;
688688
}
689689

690-
public Long getMemoryAllocated() {
691-
return memoryAllocated == null ? 0 : memoryAllocated;
690+
public long getMemoryAllocated() {
691+
return memoryAllocated;
692692
}
693693

694694
public void setMemoryAllocatedPercentage(String memoryAllocatedPercentage) {

engine/components-api/src/main/java/com/cloud/event/UsageEventUtils.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@
2525
import javax.annotation.PostConstruct;
2626
import javax.inject.Inject;
2727

28+
import com.cloud.network.Network;
29+
import org.apache.commons.collections.MapUtils;
30+
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
31+
2832
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
2933
import org.apache.cloudstack.framework.events.Event;
3034
import org.apache.cloudstack.framework.events.EventBus;
3135
import org.apache.cloudstack.framework.events.EventDistributor;
32-
import org.apache.commons.collections.MapUtils;
3336
import org.apache.logging.log4j.LogManager;
3437
import org.apache.logging.log4j.Logger;
35-
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
3638

3739
import com.cloud.dc.DataCenterVO;
3840
import com.cloud.dc.dao.DataCenterDao;
@@ -243,4 +245,22 @@ private static void publishUsageEvent(String usageEventType, Long accountId, Lon
243245

244246
static final String Name = "management-server";
245247

248+
public static void publishNetworkCreation(Network network) {
249+
publishUsageEvent(EventTypes.EVENT_NETWORK_CREATE, network.getAccountId(), network.getDataCenterId(),
250+
network.getId(), network.getName(), network.getNetworkOfferingId(), null, null, null, network.getState().name(),
251+
network.getUuid());
252+
}
253+
254+
public static void publishNetworkUpdate(Network network) {
255+
publishUsageEvent(EventTypes.EVENT_NETWORK_UPDATE, network.getAccountId(), network.getDataCenterId(),
256+
network.getId(), network.getName(), network.getNetworkOfferingId(), null, network.getState().name(),
257+
Network.class.getName(), network.getUuid(), true);
258+
}
259+
260+
public static void publishNetworkDeletion(Network network) {
261+
publishUsageEvent(EventTypes.EVENT_NETWORK_DELETE, network.getAccountId(), network.getDataCenterId(),
262+
network.getId(), network.getName(), network.getNetworkOfferingId(), null, null, null,
263+
Network.class.getName(), network.getUuid());
264+
}
265+
246266
}

engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,8 +1528,6 @@ public Pair<NetworkGuru, NetworkVO> implementNetwork(final long networkId, final
15281528
if (isNetworkImplemented(network)) {
15291529
logger.debug("Network {} is already implemented", network);
15301530
implemented.set(guru, network);
1531-
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_UPDATE, network.getAccountId(), network.getDataCenterId(), network.getId(),
1532-
network.getName(), network.getNetworkOfferingId(), null, network.getState().name(), Network.class.getName(), network.getUuid(), true);
15331531
return implemented;
15341532
}
15351533

@@ -1585,9 +1583,8 @@ public Pair<NetworkGuru, NetworkVO> implementNetwork(final long networkId, final
15851583

15861584
network.setRestartRequired(false);
15871585
_networksDao.update(network.getId(), network);
1586+
UsageEventUtils.publishNetworkUpdate(network);
15881587
implemented.set(guru, network);
1589-
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_CREATE, network.getAccountId(), network.getDataCenterId(), network.getId(),
1590-
network.getName(), network.getNetworkOfferingId(), null, null, null, network.getState().name(), network.getUuid());
15911588
return implemented;
15921589
} catch (final NoTransitionException e) {
15931590
logger.error(e.getMessage());
@@ -3087,6 +3084,7 @@ public Network doInTransaction(final TransactionStatus status) {
30873084
if (updateResourceCount) {
30883085
_resourceLimitMgr.incrementResourceCount(owner.getId(), ResourceType.network, isDisplayNetworkEnabled);
30893086
}
3087+
UsageEventUtils.publishNetworkCreation(network);
30903088

30913089
return network;
30923090
}
@@ -3168,13 +3166,14 @@ public boolean shutdownNetwork(final long networkId, final ReservationContext co
31683166
}
31693167
logger.debug("Lock is acquired for network {} as a part of network shutdown", network);
31703168

3171-
if (network.getState() == Network.State.Allocated) {
3172-
logger.debug("Network is already shutdown: {}", network);
3169+
final Network.State initialState = network.getState();
3170+
if (initialState == Network.State.Allocated) {
3171+
logger.debug(String.format("Network [%s] is in Allocated state, no need to shutdown.", network));
31733172
return true;
31743173
}
31753174

3176-
if (network.getState() != Network.State.Implemented && network.getState() != Network.State.Shutdown) {
3177-
logger.debug("Network is not implemented: {}", network);
3175+
if (initialState != Network.State.Implemented && initialState != Network.State.Shutdown) {
3176+
logger.debug("Network is not implemented: " + network);
31783177
return false;
31793178
}
31803179

@@ -3218,6 +3217,9 @@ public Boolean doInTransaction(final TransactionStatus status) {
32183217
}
32193218
_networksDao.update(networkFinal.getId(), networkFinal);
32203219
_networksDao.clearCheckForGc(networkId);
3220+
if (initialState == Network.State.Implemented) {
3221+
UsageEventUtils.publishNetworkUpdate(networkFinal);
3222+
}
32213223
result = true;
32223224
} else {
32233225
try {
@@ -3469,8 +3471,7 @@ public List<VlanVO> doInTransaction(TransactionStatus status) {
34693471
final Pair<Class<?>, Long> networkMsg = new Pair<Class<?>, Long>(Network.class, networkFinal.getId());
34703472
_messageBus.publish(_name, EntityManager.MESSAGE_REMOVE_ENTITY_EVENT, PublishScope.LOCAL, networkMsg);
34713473
}
3472-
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_DELETE, network.getAccountId(), network.getDataCenterId(), network.getId(),
3473-
network.getName(), network.getNetworkOfferingId(), null, null, null, Network.class.getName(), network.getUuid());
3474+
UsageEventUtils.publishNetworkDeletion(network);
34743475
return true;
34753476
} catch (final CloudRuntimeException e) {
34763477
logger.error("Failed to delete network", e);

engine/orchestration/src/test/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestratorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ public void testShutdownNetworkInImplementingState() {
891891
boolean shutdownNetworkStatus = testOrchestrator.shutdownNetwork(networkId, reservationContext, false);
892892
Assert.assertFalse(shutdownNetworkStatus);
893893

894-
verify(network, times(3)).getState();
894+
verify(network).getState();
895895
verify(testOrchestrator._networksDao, times(1)).acquireInLockTable(networkId, NetworkLockTimeout.value());
896896
verify(testOrchestrator._networksDao, times(1)).releaseFromLockTable(networkId);
897897
}

plugins/acl/dynamic-role-based/src/main/java/org/apache/cloudstack/acl/DynamicRoleBasedAPIAccessChecker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class DynamicRoleBasedAPIAccessChecker extends AdapterBase implements API
4747
private RoleService roleService;
4848

4949
private List<PluggableService> services;
50-
private Map<RoleType, Set<String>> annotationRoleBasedApisMap = new HashMap<>();
50+
private Map<RoleType, Set<String>> annotationRoleBasedApisMap = new HashMap<RoleType, Set<String>>();
5151

5252
private LazyCache<Long, Account> accountCache;
5353
private LazyCache<Long, Pair<Role, List<RolePermission>>> rolePermissionsCache;
@@ -56,7 +56,7 @@ public class DynamicRoleBasedAPIAccessChecker extends AdapterBase implements API
5656
protected DynamicRoleBasedAPIAccessChecker() {
5757
super();
5858
for (RoleType roleType : RoleType.values()) {
59-
annotationRoleBasedApisMap.put(roleType, new HashSet<>());
59+
annotationRoleBasedApisMap.put(roleType, new HashSet<String>());
6060
}
6161
}
6262

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/VmwareDatacenterService.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,12 @@
2222
import com.cloud.dc.VsphereStoragePolicy;
2323
import com.cloud.exception.DiscoveryException;
2424
import com.cloud.exception.ResourceInUseException;
25-
import com.cloud.hypervisor.vmware.mo.HostMO;
2625
import com.cloud.storage.StoragePool;
27-
import com.cloud.utils.Pair;
2826
import com.cloud.utils.component.PluggableService;
2927
import com.cloud.utils.exception.CloudRuntimeException;
3028
import org.apache.cloudstack.api.command.admin.zone.AddVmwareDcCmd;
3129
import org.apache.cloudstack.api.command.admin.zone.ImportVsphereStoragePoliciesCmd;
3230
import org.apache.cloudstack.api.command.admin.zone.ListVmwareDcVmsCmd;
33-
import org.apache.cloudstack.api.command.admin.zone.ListVmwareDcHostsCmd;
3431
import org.apache.cloudstack.api.command.admin.zone.ListVmwareDcsCmd;
3532
import org.apache.cloudstack.api.command.admin.zone.ListVsphereStoragePoliciesCmd;
3633
import org.apache.cloudstack.api.command.admin.zone.ListVsphereStoragePolicyCompatiblePoolsCmd;
@@ -56,7 +53,5 @@ public interface VmwareDatacenterService extends PluggableService {
5653

5754
List<StoragePool> listVsphereStoragePolicyCompatibleStoragePools(ListVsphereStoragePolicyCompatiblePoolsCmd cmd);
5855

59-
List<HostMO> listHostsInDatacenter(ListVmwareDcHostsCmd cmd);
60-
61-
Pair<String, List<UnmanagedInstanceTO>> listVMsInDatacenter(ListVmwareDcVmsCmd cmd);
56+
List<UnmanagedInstanceTO> listVMsInDatacenter(ListVmwareDcVmsCmd cmd);
6257
}

0 commit comments

Comments
 (0)