Skip to content
Snippets Groups Projects
Commit ad2a76d6 authored by Lukasz Lopatowski's avatar Lukasz Lopatowski
Browse files

Merge branch...

Merge branch '177-allow-for-refreshing-status-information-for-a-single-or-all-application-instances-in-a-bulk' into 'develop'

Resolve "Allow for refreshing status information for a single or all application instances in a bulk"

See merge request !25
parents bd9e2fb0 f1ffc439
No related branches found
No related tags found
3 merge requests!65Resolve "Prevent users from adding an existing SSH key",!601.6.5 fix processing bulk,!25Resolve "Allow for refreshing status information for a single or all application instances in a bulk"
Pipeline #89184 passed
......@@ -181,6 +181,18 @@ public class BulkController {
.collect(Collectors.toList());
}
@GetMapping("/refresh/{id}")
@PreAuthorize("hasRole('ROLE_SYSTEM_ADMIN') || hasRole('ROLE_VL_MANAGER')")
public ResponseEntity<BulkDeploymentViewS> getRefreshedState(@PathVariable Long id) {
return ResponseEntity.ok(mapToView(this.bulkApplicationService.updateState(id)));
}
private List<BulkDeploymentViewS> mapToView(List<BulkDeployment> deployments) {
return deployments.stream()
.map(bulk -> mapToView(bulk, BulkDeploymentViewS.class))
.collect(Collectors.toList());
}
private <T extends BulkDeploymentViewS> T mapToView(BulkDeployment bulk, Class<T> viewType) {
T bulkView = modelMapper.map(bulk, viewType);
bulkView.setCreator(getUserView(bulk.getCreatorId()));
......@@ -188,6 +200,14 @@ public class BulkController {
return bulkView;
}
private BulkDeploymentView mapToView(BulkDeployment deployment) {
BulkDeploymentView bulkView = modelMapper.map(deployment, BulkDeploymentView.class);
bulkView.setCreator(getUserView(deployment.getCreatorId()));
mapDetails(deployment, bulkView);
return bulkView;
}
private void mapDetails(BulkDeployment deployment, BulkDeploymentViewS view) {
if (deployment.getType().equals(BulkType.APPLICATION)) {
Map<String, String> details = new HashMap<>();
......
......@@ -7,6 +7,7 @@ import net.geant.nmaas.portal.api.bulk.BulkDeploymentView;
import net.geant.nmaas.portal.api.bulk.BulkDeploymentViewS;
import net.geant.nmaas.portal.api.bulk.CsvApplication;
import net.geant.nmaas.portal.api.domain.UserViewMinimal;
import net.geant.nmaas.portal.persistent.entity.BulkDeployment;
import org.springframework.context.ApplicationEvent;
import org.springframework.core.io.InputStreamResource;
......@@ -26,4 +27,6 @@ public interface BulkApplicationService {
void deleteAppInstancesFromBulk(BulkDeploymentView bulk);
BulkDeployment updateState(Long bulkId);
}
......@@ -321,6 +321,57 @@ public class BulkApplicationServiceImpl implements BulkApplicationService {
.orElseThrow(() -> new ObjectNotFoundException(key + " not found"));
}
@Override
public BulkDeployment updateState(Long bulkId) {
log.info("Update all states for bulk {}", bulkId);
Optional<BulkDeployment> bulk = this.bulkDeploymentRepository.findById(bulkId);
if(bulk.isPresent()) {
BulkDeployment bulkDeployment = bulk.get();
bulkDeployment.getEntries().forEach(entry -> {
try {
Long instanceId = Long.valueOf(entry.getDetails().get(BULK_ENTRY_DETAIL_KEY_APP_INSTANCE_ID));
AppInstance instance = instanceService.find(instanceId).orElseThrow();
AppLifecycleState state = appDeploymentMonitor.state(instance.getInternalId());
switch (state) {
case APPLICATION_DEPLOYMENT_VERIFIED:
entry.setState(BulkDeploymentState.COMPLETED);
bulkDeploymentEntryRepository.save(entry);
break;
case APPLICATION_CONFIGURATION_FAILED:
case APPLICATION_DEPLOYMENT_FAILED:
case APPLICATION_DEPLOYMENT_VERIFICATION_FAILED:
case INTERNAL_ERROR:
entry.setState(BulkDeploymentState.FAILED);
bulkDeploymentEntryRepository.save(entry);
break;
default:
entry.setState(BulkDeploymentState.PENDING);
bulkDeploymentEntryRepository.save(entry);
break;
}
logBulkStateUpdate(entry.getId(), entry.getState().name());
} catch (Exception e) {
log.error("Can not update state of {} bulk entry", entry.getId());
}
});
if (bulkDeployment.getEntries().stream().allMatch(e -> BulkDeploymentState.COMPLETED.equals(e.getState()))) {
bulkDeployment.setState(BulkDeploymentState.COMPLETED);
} else if (bulkDeployment.getEntries().stream().allMatch(e -> BulkDeploymentState.FAILED.equals(e.getState()))) {
bulkDeployment.setState(BulkDeploymentState.FAILED);
} else if (bulkDeployment.getEntries().stream().anyMatch(e -> BulkDeploymentState.FAILED.equals(e.getState()))) {
bulkDeployment.setState(BulkDeploymentState.PARTIALLY_FAILED);
}
logBulkStateUpdate(bulkDeployment.getId(),bulkDeployment.getState().name());
bulkDeploymentRepository.save(bulkDeployment);
return bulkDeployment;
} else {
log.error("Can not find bulk deployment {}", bulkId);
throw new MissingElementException("Can not find bulk deployment " + bulkId);
}
}
private static BulkDeployment createBulkDeployment(UserViewMinimal creator) {
BulkDeployment bulkDeployment = new BulkDeployment();
bulkDeployment.setType(BulkType.APPLICATION);
......
......@@ -1236,7 +1236,8 @@
"DOMAIN" : "Domain",
"CHECK_STATE" : "Check state",
"UPLOAD_TEXT" : "or enter CSV content below",
"DOWNLOAD_CSV" : "Download CSV"
"DOWNLOAD_CSV" : "Download CSV",
"REFRESH" : "Refresh states"
},
"STATE" : {
"PENDING" : "Pending",
......
......@@ -1239,7 +1239,8 @@
"DOMAIN" : "Domain",
"CHECK_STATE" : "Check state",
"UPLOAD_TEXT" : "or enter the csv content below",
"DOWNLOAD_CSV" : "Download CSV"
"DOWNLOAD_CSV" : "Download CSV",
"REFRESH" : "Refresh states"
},
"STATE" : {
"PENDING" : "Pending",
......
......@@ -1237,7 +1237,8 @@
"DOMAIN" : "Domain",
"CHECK_STATE" : "Check state",
"UPLOAD_TEXT" : "or enter CSV content below",
"DOWNLOAD_CSV" : "Download CSV"
"DOWNLOAD_CSV" : "Download CSV",
"REFRESH" : "Refresh states"
},
"STATE" : {
"PENDING" : "Pending",
......
......@@ -1238,7 +1238,8 @@
"DOMAIN" : "Domena",
"CHECK_STATE" : "Sprawdź status",
"UPLOAD_TEXT" : "lub podaj tekst w formacie CSV poniżej",
"DOWNLOAD_CSV" : "Pobierz CSV"
"DOWNLOAD_CSV" : "Pobierz CSV",
"REFRESH" : "Odśwież stany"
},
"STATE" : {
"PENDING" : "Oczekuje",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment