Commit 912d4f73 by Johannes Stelzer

Remove conflict detection (what is it really good for?)

parent 8e2ce75d
...@@ -30,7 +30,6 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -30,7 +30,6 @@ import org.springframework.web.bind.annotation.RestController;
import de.codecentric.boot.admin.model.Application; import de.codecentric.boot.admin.model.Application;
import de.codecentric.boot.admin.registry.ApplicationRegistry; import de.codecentric.boot.admin.registry.ApplicationRegistry;
import de.codecentric.boot.admin.registry.ApplicationRegistryConflictException;
/** /**
* REST controller for controlling registration of managed applications. * REST controller for controlling registration of managed applications.
...@@ -57,12 +56,8 @@ public class RegistryController { ...@@ -57,12 +56,8 @@ public class RegistryController {
@RequestMapping(method = RequestMethod.POST) @RequestMapping(method = RequestMethod.POST)
public ResponseEntity<Application> register(@RequestBody Application app) { public ResponseEntity<Application> register(@RequestBody Application app) {
LOGGER.debug("Register application {}", app.toString()); LOGGER.debug("Register application {}", app.toString());
try {
Application registeredApp = registry.register(app); Application registeredApp = registry.register(app);
return new ResponseEntity<Application>(registeredApp, HttpStatus.CREATED); return new ResponseEntity<Application>(registeredApp, HttpStatus.CREATED);
} catch (ApplicationRegistryConflictException ex) {
return new ResponseEntity<Application>(HttpStatus.CONFLICT);
}
} }
/** /**
......
...@@ -21,7 +21,7 @@ public interface ApplicationIdGenerator { ...@@ -21,7 +21,7 @@ public interface ApplicationIdGenerator {
/** /**
* Generate an id based on the given Application * Generate an id based on the given Application
* *
* @param a the application the id is computed for. * @param a the application the id is computed for.
* @return the application id * @return the application id
*/ */
......
...@@ -69,8 +69,7 @@ public class ApplicationRegistry implements ApplicationContextAware { ...@@ -69,8 +69,7 @@ public class ApplicationRegistry implements ApplicationContextAware {
if ((app.getUrl().equals(oldApp.getUrl()) && app.getName().equals(oldApp.getName()))) { if ((app.getUrl().equals(oldApp.getUrl()) && app.getName().equals(oldApp.getName()))) {
LOGGER.debug("Application {} refreshed", newApp); LOGGER.debug("Application {} refreshed", newApp);
} else { } else {
LOGGER.warn("Application {} not registered because of conflict with {}", newApp, oldApp); LOGGER.warn("Application {} replaced by Application {}", newApp, oldApp);
throw new ApplicationRegistryConflictException(oldApp, app);
} }
} }
return newApp; return newApp;
......
/*
* Copyright 2013-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.codecentric.boot.admin.registry;
import de.codecentric.boot.admin.model.Application;
public class ApplicationRegistryConflictException extends RuntimeException {
private static final long serialVersionUID = 1L;
public ApplicationRegistryConflictException(Application oldApp, Application newApp) {
super("Conflict in ApplicationRegistry: " + oldApp.toString() + " vs. " + newApp.toString());
}
}
/*
* Copyright 2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.codecentric.boot.admin.registry.store; package de.codecentric.boot.admin.registry.store;
import java.util.Collection; import java.util.Collection;
...@@ -17,7 +32,7 @@ public class HazelcastApplicationStore implements ApplicationStore { ...@@ -17,7 +32,7 @@ public class HazelcastApplicationStore implements ApplicationStore {
@Override @Override
public Application save(Application app) { public Application save(Application app) {
return store.putIfAbsent(app.getId(), app); return store.put(app.getId(), app);
} }
@Override @Override
......
...@@ -31,7 +31,7 @@ public class SimpleApplicationStore implements ApplicationStore { ...@@ -31,7 +31,7 @@ public class SimpleApplicationStore implements ApplicationStore {
@Override @Override
public Application save(Application app) { public Application save(Application app) {
return map.putIfAbsent(app.getId(), app); return map.put(app.getId(), app);
} }
@Override @Override
......
...@@ -69,7 +69,7 @@ public class RegistryControllerTest { ...@@ -69,7 +69,7 @@ public class RegistryControllerTest {
public void register_sameUrl() { public void register_sameUrl() {
controller.register(new Application("http://localhost", "FOO")); controller.register(new Application("http://localhost", "FOO"));
ResponseEntity<?> response = controller.register(new Application("http://localhost", "BAR")); ResponseEntity<?> response = controller.register(new Application("http://localhost", "BAR"));
assertEquals(HttpStatus.CONFLICT, response.getStatusCode()); assertEquals(HttpStatus.CREATED, response.getStatusCode());
} }
@Test @Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment