Fix issues with pending ops validation

pull/550/head
prathabanKavin 2 weeks ago
parent ad2a558d5c
commit 79c3837d8a

@ -180,7 +180,6 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
ApplicationDTO applicationDTO = getApplicationDTO(applicationUUID); ApplicationDTO applicationDTO = getApplicationDTO(applicationUUID);
ApplicationSubscriptionInfo applicationSubscriptionInfo = getAppSubscriptionInfo(applicationDTO, subType, ApplicationSubscriptionInfo applicationSubscriptionInfo = getAppSubscriptionInfo(applicationDTO, subType,
params); params);
validatePendingAppSubscription(applicationSubscriptionInfo, applicationDTO);
performExternalStoreSubscription(applicationDTO, applicationSubscriptionInfo); performExternalStoreSubscription(applicationDTO, applicationSubscriptionInfo);
ApplicationInstallResponse applicationInstallResponse = performActionOnDevices( ApplicationInstallResponse applicationInstallResponse = performActionOnDevices(
applicationSubscriptionInfo.getAppSupportingDeviceTypeName(), applicationSubscriptionInfo.getDevices(), applicationSubscriptionInfo.getAppSupportingDeviceTypeName(), applicationSubscriptionInfo.getDevices(),
@ -708,35 +707,16 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
} }
} }
private <T> void validatePendingAppSubscription(ApplicationSubscriptionInfo applicationSubscriptionInfo, ApplicationDTO applicationDTO) throws BadRequestException, ApplicationManagementException{ private <T> void validatePendingAppSubscription(List<Device> devices, SubscribingDeviceIdHolder subscribingDeviceIdHolder) throws BadRequestException{
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); Set<DeviceIdentifier> deviceIdentifiers = devices.stream()
int applicationReleaseId = applicationDTO.getApplicationReleaseDTOs().get(0).getId(); .map(device -> new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()))
try { .collect(Collectors.toSet());
List<DeviceSubscriptionDTO> deviceSubscriptionDTOS = subscriptionDAO Set<DeviceIdentifier> skippedDevices = subscribingDeviceIdHolder.getSkippedDevices().keySet();
.getDeviceSubscriptions(applicationReleaseId, tenantId, null, null); if (skippedDevices.containsAll(deviceIdentifiers) && deviceIdentifiers.containsAll(skippedDevices)) {
List<Integer> deviceIdList = new ArrayList<>(); String msg = "All devices in the subscription have pending operations for this application.";
deviceSubscriptionDTOS.forEach(deviceSubscriptionDTO -> {
if (!deviceSubscriptionDTO.isUnsubscribed() &&
Operation.Status.PENDING.toString().equalsIgnoreCase(deviceSubscriptionDTO.getStatus())) {
deviceIdList.add(deviceSubscriptionDTO.getDeviceId());
}
});
List<Integer> subscriptionDeviceIds = applicationSubscriptionInfo.getDevices().stream()
.map(Device::getId)
.collect(Collectors.toList());
boolean allDevicesPending = subscriptionDeviceIds.stream()
.allMatch(deviceIdList::contains);
if (allDevicesPending) {
String msg = "All devices in the subscription have pending operations for this application.";
log.error(msg); log.error(msg);
throw new BadRequestException(msg); throw new BadRequestException(msg);
} }
} catch (ApplicationManagementDAOException e) {
String msg = "Error while retrieving device subscriptions";
log.error(msg, e);
throw new ApplicationManagementException("Error while validating application subscription", e);
}
} }
/** /**
@ -773,6 +753,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
Map<String, List<DeviceIdentifier>> deviceIdentifierMap = new HashMap<>(); Map<String, List<DeviceIdentifier>> deviceIdentifierMap = new HashMap<>();
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) { if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
validatePendingAppSubscription(devices, subscribingDeviceIdHolder);
deviceIdentifiers.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstallableDevices().keySet())); deviceIdentifiers.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppInstallableDevices().keySet()));
deviceIdentifiers.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppReInstallableDevices().keySet())); deviceIdentifiers.addAll(new ArrayList<>(subscribingDeviceIdHolder.getAppReInstallableDevices().keySet()));
if (!isOperationReExecutingDisabled) { if (!isOperationReExecutingDisabled) {

Loading…
Cancel
Save