mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-12-14 05:41:23 +01:00
ONOS-2091 Installing app when already installed will now raise an error
Change-Id: I4dacd63bf4a99244b23b932d35dd9cbd088548c1
This commit is contained in:
parent
e00733af97
commit
e18a330163
@ -50,6 +50,7 @@ import java.util.Set;
|
|||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipInputStream;
|
import java.util.zip.ZipInputStream;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
import static com.google.common.io.ByteStreams.toByteArray;
|
import static com.google.common.io.ByteStreams.toByteArray;
|
||||||
import static com.google.common.io.Files.createParentDirs;
|
import static com.google.common.io.Files.createParentDirs;
|
||||||
import static com.google.common.io.Files.write;
|
import static com.google.common.io.Files.write;
|
||||||
@ -108,7 +109,7 @@ public class ApplicationArchive
|
|||||||
*
|
*
|
||||||
* @return top-level directory path
|
* @return top-level directory path
|
||||||
*/
|
*/
|
||||||
protected String getRootPath() {
|
public String getRootPath() {
|
||||||
return root.getPath();
|
return root.getPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,6 +180,8 @@ public class ApplicationArchive
|
|||||||
boolean plainXml = isPlainXml(cache);
|
boolean plainXml = isPlainXml(cache);
|
||||||
ApplicationDescription desc = plainXml ?
|
ApplicationDescription desc = plainXml ?
|
||||||
parsePlainAppDescription(bis) : parseZippedAppDescription(bis);
|
parsePlainAppDescription(bis) : parseZippedAppDescription(bis);
|
||||||
|
checkState(!appFile(desc.name(), APP_XML).exists(),
|
||||||
|
"Application %s already installed", desc.name());
|
||||||
|
|
||||||
if (plainXml) {
|
if (plainXml) {
|
||||||
expandPlainApplication(cache, desc);
|
expandPlainApplication(cache, desc);
|
||||||
@ -309,6 +312,7 @@ public class ApplicationArchive
|
|||||||
private void expandPlainApplication(byte[] stream, ApplicationDescription desc)
|
private void expandPlainApplication(byte[] stream, ApplicationDescription desc)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
File file = appFile(desc.name(), APP_XML);
|
File file = appFile(desc.name(), APP_XML);
|
||||||
|
checkState(!file.getParentFile().exists(), "Application already installed");
|
||||||
createParentDirs(file);
|
createParentDirs(file);
|
||||||
write(stream, file);
|
write(stream, file);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -93,7 +93,6 @@ public class ApplicationManager implements ApplicationService, ApplicationAdminS
|
|||||||
@Override
|
@Override
|
||||||
public Set<Application> getApplications() {
|
public Set<Application> getApplications() {
|
||||||
checkPermission(Permission.APP_READ);
|
checkPermission(Permission.APP_READ);
|
||||||
|
|
||||||
return store.getApplications();
|
return store.getApplications();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +107,6 @@ public class ApplicationManager implements ApplicationService, ApplicationAdminS
|
|||||||
@Override
|
@Override
|
||||||
public Application getApplication(ApplicationId appId) {
|
public Application getApplication(ApplicationId appId) {
|
||||||
checkPermission(Permission.APP_READ);
|
checkPermission(Permission.APP_READ);
|
||||||
|
|
||||||
checkNotNull(appId, APP_ID_NULL);
|
checkNotNull(appId, APP_ID_NULL);
|
||||||
return store.getApplication(appId);
|
return store.getApplication(appId);
|
||||||
}
|
}
|
||||||
@ -116,7 +114,6 @@ public class ApplicationManager implements ApplicationService, ApplicationAdminS
|
|||||||
@Override
|
@Override
|
||||||
public ApplicationState getState(ApplicationId appId) {
|
public ApplicationState getState(ApplicationId appId) {
|
||||||
checkPermission(Permission.APP_READ);
|
checkPermission(Permission.APP_READ);
|
||||||
|
|
||||||
checkNotNull(appId, APP_ID_NULL);
|
checkNotNull(appId, APP_ID_NULL);
|
||||||
return store.getState(appId);
|
return store.getState(appId);
|
||||||
}
|
}
|
||||||
@ -124,7 +121,6 @@ public class ApplicationManager implements ApplicationService, ApplicationAdminS
|
|||||||
@Override
|
@Override
|
||||||
public Set<Permission> getPermissions(ApplicationId appId) {
|
public Set<Permission> getPermissions(ApplicationId appId) {
|
||||||
checkPermission(Permission.APP_READ);
|
checkPermission(Permission.APP_READ);
|
||||||
|
|
||||||
checkNotNull(appId, APP_ID_NULL);
|
checkNotNull(appId, APP_ID_NULL);
|
||||||
return store.getPermissions(appId);
|
return store.getPermissions(appId);
|
||||||
}
|
}
|
||||||
@ -167,14 +163,12 @@ public class ApplicationManager implements ApplicationService, ApplicationAdminS
|
|||||||
@Override
|
@Override
|
||||||
public void addListener(ApplicationListener listener) {
|
public void addListener(ApplicationListener listener) {
|
||||||
checkPermission(Permission.APP_EVENT);
|
checkPermission(Permission.APP_EVENT);
|
||||||
|
|
||||||
listenerRegistry.addListener(listener);
|
listenerRegistry.addListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeListener(ApplicationListener listener) {
|
public void removeListener(ApplicationListener listener) {
|
||||||
checkPermission(Permission.APP_EVENT);
|
checkPermission(Permission.APP_EVENT);
|
||||||
|
|
||||||
listenerRegistry.removeListener(listener);
|
listenerRegistry.removeListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -19,6 +19,7 @@ import com.google.common.collect.ImmutableSet;
|
|||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.onlab.util.Tools;
|
||||||
import org.onosproject.app.ApplicationEvent;
|
import org.onosproject.app.ApplicationEvent;
|
||||||
import org.onosproject.app.ApplicationStoreDelegate;
|
import org.onosproject.app.ApplicationStoreDelegate;
|
||||||
import org.onosproject.common.app.ApplicationArchive;
|
import org.onosproject.common.app.ApplicationArchive;
|
||||||
@ -28,6 +29,10 @@ import org.onosproject.core.Permission;
|
|||||||
import org.onosproject.core.ApplicationIdStoreAdapter;
|
import org.onosproject.core.ApplicationIdStoreAdapter;
|
||||||
import org.onosproject.core.DefaultApplicationId;
|
import org.onosproject.core.DefaultApplicationId;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.onosproject.app.ApplicationEvent.Type.APP_INSTALLED;
|
import static org.onosproject.app.ApplicationEvent.Type.APP_INSTALLED;
|
||||||
import static org.onosproject.app.ApplicationEvent.Type.APP_DEACTIVATED;
|
import static org.onosproject.app.ApplicationEvent.Type.APP_DEACTIVATED;
|
||||||
@ -42,24 +47,34 @@ import static org.onosproject.app.ApplicationState.INSTALLED;
|
|||||||
*/
|
*/
|
||||||
public class SimpleApplicationStoreTest {
|
public class SimpleApplicationStoreTest {
|
||||||
|
|
||||||
private SimpleApplicationStore store = new SimpleApplicationStore();
|
static final String ROOT = "/tmp/app-junit/";
|
||||||
|
static final String STORE = ROOT + new Random().nextInt(1000) + "/foo";
|
||||||
|
|
||||||
|
private TestApplicationStore store = new TestApplicationStore();
|
||||||
private TestDelegate delegate = new TestDelegate();
|
private TestDelegate delegate = new TestDelegate();
|
||||||
|
private static final Object LOCK = new Object();
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
store.idStore = new TestIdStore();
|
store.idStore = new TestIdStore();
|
||||||
|
store.setRootPath(STORE);
|
||||||
store.setDelegate(delegate);
|
store.setDelegate(delegate);
|
||||||
store.activate();
|
store.activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() throws IOException {
|
||||||
|
if (new File(ROOT).exists()) {
|
||||||
|
Tools.removeDirectory(ROOT);
|
||||||
|
}
|
||||||
store.deactivate();
|
store.deactivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Application createTestApp() {
|
private Application createTestApp() {
|
||||||
|
synchronized (LOCK) {
|
||||||
return store.create(ApplicationArchive.class.getResourceAsStream("app.zip"));
|
return store.create(ApplicationArchive.class.getResourceAsStream("app.zip"));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void create() {
|
public void create() {
|
||||||
@ -132,4 +147,11 @@ public class SimpleApplicationStoreTest {
|
|||||||
this.event = event;
|
this.event = event;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class TestApplicationStore extends SimpleApplicationStore {
|
||||||
|
@Override
|
||||||
|
public void setRootPath(String root) {
|
||||||
|
super.setRootPath(root);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* 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 org.onosproject.rest.exceptions;
|
||||||
|
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mapper for illegal state exceptions to the BAD_REQUEST response code.
|
||||||
|
*/
|
||||||
|
public class IllegalStateExceptionMapper extends AbstractMapper<IllegalStateException> {
|
||||||
|
@Override
|
||||||
|
protected Response.Status responseStatus() {
|
||||||
|
return Response.Status.CONFLICT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ -62,6 +62,7 @@
|
|||||||
org.onosproject.rest.exceptions.BadRequestMapper,
|
org.onosproject.rest.exceptions.BadRequestMapper,
|
||||||
org.onosproject.rest.exceptions.WebApplicationExceptionMapper,
|
org.onosproject.rest.exceptions.WebApplicationExceptionMapper,
|
||||||
org.onosproject.rest.exceptions.IllegalArgumentExceptionMapper,
|
org.onosproject.rest.exceptions.IllegalArgumentExceptionMapper,
|
||||||
|
org.onosproject.rest.exceptions.IllegalStateExceptionMapper,
|
||||||
org.onosproject.rest.resources.JsonBodyWriter,
|
org.onosproject.rest.resources.JsonBodyWriter,
|
||||||
|
|
||||||
org.onosproject.rest.resources.ApplicationsWebResource,
|
org.onosproject.rest.resources.ApplicationsWebResource,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user