diff --git a/src/main/java/net/geant/nmaas/portal/api/market/ApplicationController.java b/src/main/java/net/geant/nmaas/portal/api/market/ApplicationController.java index 4d1c58ba03218d0cb7173aa00d46800c4c313ef5..dc805ba395ab1d9dcef873917da84a768beb3a20 100644 --- a/src/main/java/net/geant/nmaas/portal/api/market/ApplicationController.java +++ b/src/main/java/net/geant/nmaas/portal/api/market/ApplicationController.java @@ -9,23 +9,15 @@ import lombok.extern.log4j.Log4j2; import net.geant.nmaas.notifications.MailAttributes; import net.geant.nmaas.notifications.NotificationEvent; import net.geant.nmaas.notifications.templates.MailType; -import net.geant.nmaas.portal.api.domain.AppRateView; -import net.geant.nmaas.portal.api.domain.ApplicationBaseView; -import net.geant.nmaas.portal.api.domain.ApplicationStateChangeRequest; -import net.geant.nmaas.portal.api.domain.ApplicationView; -import net.geant.nmaas.portal.api.domain.Id; -import net.geant.nmaas.portal.api.domain.UserView; +import net.geant.nmaas.orchestration.AppLifecycleManager; +import net.geant.nmaas.portal.api.domain.*; import net.geant.nmaas.portal.api.exception.MarketException; import net.geant.nmaas.portal.api.exception.MissingElementException; import net.geant.nmaas.portal.api.exception.ProcessingException; import net.geant.nmaas.portal.exceptions.ObjectAlreadyExistsException; -import net.geant.nmaas.portal.persistent.entity.Application; -import net.geant.nmaas.portal.persistent.entity.ApplicationBase; -import net.geant.nmaas.portal.persistent.entity.ApplicationState; -import net.geant.nmaas.portal.persistent.entity.ApplicationVersion; -import net.geant.nmaas.portal.persistent.entity.Role; -import net.geant.nmaas.portal.persistent.entity.User; +import net.geant.nmaas.portal.persistent.entity.*; import net.geant.nmaas.portal.persistent.repositories.RatingRepository; +import net.geant.nmaas.portal.service.ApplicationInstanceService; import net.geant.nmaas.portal.service.impl.ApplicationServiceImpl; import org.springframework.context.ApplicationEventPublisher; import org.springframework.http.HttpStatus; @@ -81,6 +73,12 @@ public class ApplicationController extends AppBaseController { private final RatingRepository ratingRepository; + private final ApplicationInstanceService applicationInstanceService; + + private final AppLifecycleManager appLifecycleManager; + + private final AppInstanceController appInstanceController; + /* * Application Base Part */ @@ -159,10 +157,8 @@ public class ApplicationController extends AppBaseController { ApplicationState state = ApplicationState.DELETED; for (ApplicationVersion appVersion : base.getVersions()) { Application app = getApp(appVersion.getAppVersionId()); - applicationService.changeApplicationState(app, state); - appVersion.setState(state); + if(app.getState() != ApplicationState.DELETED) throw new ProcessingException("Can not delete base, version " + app.getVersion() +" is not deleted"); } - appBaseService.deleteAppBase(base); } @@ -339,8 +335,23 @@ public class ApplicationController extends AppBaseController { @PatchMapping(value = "/state/{id}") @PreAuthorize("hasRole('ROLE_SYSTEM_ADMIN')") @Transactional - public void changeApplicationState(@PathVariable long id, @RequestBody ApplicationStateChangeRequest stateChangeRequest) { + public void changeApplicationState(@PathVariable long id, @RequestBody ApplicationStateChangeRequest stateChangeRequest, Principal principal) { Application app = getApp(id); + if(stateChangeRequest.getState().equals(ApplicationState.DELETED)) { + applicationInstanceService.findAllByApplication(app).forEach(ai -> { + AppInstanceStatus instanceState = appInstanceController.getState(ai.getId(), principal); + int numberOfRunningInstances = 0; + if(!(instanceState.getState().equals(AppInstanceState.DONE) + || instanceState.getState().equals(AppInstanceState.FAILURE) + || instanceState.getState().equals(AppInstanceState.REMOVED) )) { + numberOfRunningInstances = +1; + } + if(numberOfRunningInstances > 0) { + throw new ProcessingException("Can not set state to Disabled. There is still " + numberOfRunningInstances + " running instances of this version."); + } + } + ); + } applicationService.changeApplicationState(app, stateChangeRequest.getState()); appBaseService.updateApplicationVersionState(app.getName(), app.getVersion(), stateChangeRequest.getState()); this.sendMails(app, stateChangeRequest); diff --git a/src/main/java/net/geant/nmaas/portal/service/impl/ApplicationBaseServiceImpl.java b/src/main/java/net/geant/nmaas/portal/service/impl/ApplicationBaseServiceImpl.java index 99c33f6a9c286eeb589489bf7496d6efd0bdb500..b14732966429676d91f30800fff6e5ccf3706c51 100644 --- a/src/main/java/net/geant/nmaas/portal/service/impl/ApplicationBaseServiceImpl.java +++ b/src/main/java/net/geant/nmaas/portal/service/impl/ApplicationBaseServiceImpl.java @@ -97,7 +97,7 @@ public class ApplicationBaseServiceImpl implements ApplicationBaseService { .findAny() .ifPresent(appVersion -> appVersion.setState(state)); appBase.validate(); - appBaseRepository.save(appBase); + appBaseRepository.save(appBase); if (state.equals(ApplicationState.ACTIVE)) { eventPublisher.publishEvent(new ApplicationActivatedEvent(this, name, version)); } diff --git a/src/test/shell/data/i18n/de.json b/src/test/shell/data/i18n/de.json index 6d0b19d12f24876d4953b45d8279058ef58ae479..6399c7727a09b2d9554b529523c7dfaec018b137 100644 --- a/src/test/shell/data/i18n/de.json +++ b/src/test/shell/data/i18n/de.json @@ -735,6 +735,7 @@ "VIEW_BUTTON": "Anzeigen", "EDIT_BUTTON": "Bearbeiten", "DELETE_BUTTON": "Remove", + "SELECT_VERSION" : "Select version to be base in creator", "CONFIRM_REMOVAL" : { "HEADER": "Confirm application removal", "DESCRIPTION": "Do you want to completely remove this application from the catalogue along with all its versions?", diff --git a/src/test/shell/data/i18n/en.json b/src/test/shell/data/i18n/en.json index db0f617fa2cfdbc459e50a754b156396ed3f132e..a3e1a365ce6e285a2f56fcf79f1e32b483c34841 100644 --- a/src/test/shell/data/i18n/en.json +++ b/src/test/shell/data/i18n/en.json @@ -736,6 +736,7 @@ "VIEW_BUTTON": "View", "EDIT_BUTTON": "Edit", "DELETE_BUTTON": "Remove", + "SELECT_VERSION" : "Select version to be base in creator", "CONFIRM_REMOVAL" : { "HEADER": "Confirm application removal", "DESCRIPTION": "Do you want to completely remove this application from the catalogue along with all its versions?", diff --git a/src/test/shell/data/i18n/fr.json b/src/test/shell/data/i18n/fr.json index 2efa5331df0fdb4e9f60f1591a2014d056e0370c..8a1ade28d1092890f07ca38e5467d8fafd0f23c2 100644 --- a/src/test/shell/data/i18n/fr.json +++ b/src/test/shell/data/i18n/fr.json @@ -734,6 +734,7 @@ "VIEW_BUTTON": "View", "EDIT_BUTTON": "Edit", "DELETE_BUTTON": "Remove", + "SELECT_VERSION" : "Select version to be base in creator", "CONFIRM_REMOVAL" : { "HEADER": "Confirm application removal", "DESCRIPTION": "Do you want to completely remove this application from the catalogue along with all its versions?", diff --git a/src/test/shell/data/i18n/pl.json b/src/test/shell/data/i18n/pl.json index 992805e424c5f38f174d0e0624d17e969b5c652b..19e904699840b18e74475e72252277d1205594c0 100644 --- a/src/test/shell/data/i18n/pl.json +++ b/src/test/shell/data/i18n/pl.json @@ -735,6 +735,7 @@ "VIEW_BUTTON": "Pokaż", "EDIT_BUTTON": "Edytuj", "DELETE_BUTTON": "Usuń", + "SELECT_VERSION" : "Wybierz wersję aplikacji, która ma być podstawą w kreatorze", "CONFIRM_REMOVAL" : { "HEADER": "Potwierdź usunięcie aplikacji", "DESCRIPTION": "Czy na pewno chcesz całkowicie usunąć tą aplikację z katalogu razem ze wszystkimi wersjami?",