Committed by
Gerrit Code Review
Added protection against redundant feature repo & feature operations.
Change-Id: Idca031e811a659a68ac55080acdef074fcfa80e1
Showing
1 changed file
with
26 additions
and
11 deletions
| ... | @@ -170,21 +170,24 @@ public class ApplicationManager implements ApplicationService, ApplicationAdminS | ... | @@ -170,21 +170,24 @@ public class ApplicationManager implements ApplicationService, ApplicationAdminS |
| 170 | Application app = event.subject(); | 170 | Application app = event.subject(); |
| 171 | try { | 171 | try { |
| 172 | if (type == APP_ACTIVATED) { | 172 | if (type == APP_ACTIVATED) { |
| 173 | - installAppFeatures(app); | 173 | + if (installAppFeatures(app)) { |
| 174 | log.info("Application {} has been activated", app.id().name()); | 174 | log.info("Application {} has been activated", app.id().name()); |
| 175 | + } | ||
| 175 | 176 | ||
| 176 | } else if (type == APP_DEACTIVATED) { | 177 | } else if (type == APP_DEACTIVATED) { |
| 177 | - uninstallAppFeatures(app); | 178 | + if (uninstallAppFeatures(app)) { |
| 178 | log.info("Application {} has been deactivated", app.id().name()); | 179 | log.info("Application {} has been deactivated", app.id().name()); |
| 180 | + } | ||
| 179 | 181 | ||
| 180 | } else if (type == APP_INSTALLED) { | 182 | } else if (type == APP_INSTALLED) { |
| 181 | - installAppArtifacts(app); | 183 | + if (installAppArtifacts(app)) { |
| 182 | log.info("Application {} has been installed", app.id().name()); | 184 | log.info("Application {} has been installed", app.id().name()); |
| 185 | + } | ||
| 183 | 186 | ||
| 184 | } else if (type == APP_UNINSTALLED) { | 187 | } else if (type == APP_UNINSTALLED) { |
| 185 | - uninstallAppFeatures(app); | 188 | + if (uninstallAppFeatures(app) || uninstallAppArtifacts(app)) { |
| 186 | - uninstallAppArtifacts(app); | ||
| 187 | log.info("Application {} has been uninstalled", app.id().name()); | 189 | log.info("Application {} has been uninstalled", app.id().name()); |
| 190 | + } | ||
| 188 | 191 | ||
| 189 | } | 192 | } |
| 190 | eventDispatcher.post(event); | 193 | eventDispatcher.post(event); |
| ... | @@ -198,40 +201,52 @@ public class ApplicationManager implements ApplicationService, ApplicationAdminS | ... | @@ -198,40 +201,52 @@ public class ApplicationManager implements ApplicationService, ApplicationAdminS |
| 198 | // The following methods are fully synchronized to guard against remote vs. | 201 | // The following methods are fully synchronized to guard against remote vs. |
| 199 | // locally induced feature service interactions. | 202 | // locally induced feature service interactions. |
| 200 | 203 | ||
| 201 | - private synchronized void installAppArtifacts(Application app) throws Exception { | 204 | + private synchronized boolean installAppArtifacts(Application app) throws Exception { |
| 202 | - if (app.featuresRepo().isPresent()) { | 205 | + if (app.featuresRepo().isPresent() && |
| 206 | + featuresService.getRepository(app.featuresRepo().get()) == null) { | ||
| 203 | featuresService.addRepository(app.featuresRepo().get()); | 207 | featuresService.addRepository(app.featuresRepo().get()); |
| 208 | + return true; | ||
| 204 | } | 209 | } |
| 210 | + return false; | ||
| 205 | } | 211 | } |
| 206 | 212 | ||
| 207 | - private synchronized void uninstallAppArtifacts(Application app) throws Exception { | 213 | + private synchronized boolean uninstallAppArtifacts(Application app) throws Exception { |
| 208 | - if (app.featuresRepo().isPresent()) { | 214 | + if (app.featuresRepo().isPresent() && |
| 215 | + featuresService.getRepository(app.featuresRepo().get()) != null) { | ||
| 209 | featuresService.removeRepository(app.featuresRepo().get()); | 216 | featuresService.removeRepository(app.featuresRepo().get()); |
| 217 | + return true; | ||
| 210 | } | 218 | } |
| 219 | + return false; | ||
| 211 | } | 220 | } |
| 212 | 221 | ||
| 213 | - private synchronized void installAppFeatures(Application app) throws Exception { | 222 | + private synchronized boolean installAppFeatures(Application app) throws Exception { |
| 223 | + boolean changed = false; | ||
| 214 | for (String name : app.features()) { | 224 | for (String name : app.features()) { |
| 215 | Feature feature = featuresService.getFeature(name); | 225 | Feature feature = featuresService.getFeature(name); |
| 216 | if (feature != null && !featuresService.isInstalled(feature)) { | 226 | if (feature != null && !featuresService.isInstalled(feature)) { |
| 217 | featuresService.installFeature(name); | 227 | featuresService.installFeature(name); |
| 228 | + changed = true; | ||
| 218 | } else if (feature == null && !initializing) { | 229 | } else if (feature == null && !initializing) { |
| 219 | // Suppress feature-not-found reporting during startup since these | 230 | // Suppress feature-not-found reporting during startup since these |
| 220 | // can arise naturally from the staggered cluster install. | 231 | // can arise naturally from the staggered cluster install. |
| 221 | log.warn("Feature {} not found", name); | 232 | log.warn("Feature {} not found", name); |
| 222 | } | 233 | } |
| 223 | } | 234 | } |
| 235 | + return changed; | ||
| 224 | } | 236 | } |
| 225 | 237 | ||
| 226 | - private synchronized void uninstallAppFeatures(Application app) throws Exception { | 238 | + private synchronized boolean uninstallAppFeatures(Application app) throws Exception { |
| 239 | + boolean changed = false; | ||
| 227 | for (String name : app.features()) { | 240 | for (String name : app.features()) { |
| 228 | Feature feature = featuresService.getFeature(name); | 241 | Feature feature = featuresService.getFeature(name); |
| 229 | if (feature != null && featuresService.isInstalled(feature)) { | 242 | if (feature != null && featuresService.isInstalled(feature)) { |
| 230 | featuresService.uninstallFeature(name); | 243 | featuresService.uninstallFeature(name); |
| 244 | + changed = true; | ||
| 231 | } else if (feature == null) { | 245 | } else if (feature == null) { |
| 232 | log.warn("Feature {} not found", name); | 246 | log.warn("Feature {} not found", name); |
| 233 | } | 247 | } |
| 234 | } | 248 | } |
| 249 | + return changed; | ||
| 235 | } | 250 | } |
| 236 | 251 | ||
| 237 | } | 252 | } | ... | ... |
-
Please register or login to post a comment