Committed by
Gerrit Code Review
ONOS-542 Defining application subsystem interfaces & public constructs.
Change-Id: Iba0d2cb69dace5beee8a68def9918059ce755b5c
Showing
64 changed files
with
3200 additions
and
34 deletions
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.cli; | ||
17 | + | ||
18 | +import org.apache.karaf.shell.commands.Command; | ||
19 | + | ||
20 | +import java.io.BufferedReader; | ||
21 | +import java.io.IOException; | ||
22 | +import java.io.InputStreamReader; | ||
23 | + | ||
24 | +/** | ||
25 | + * Lists application ID information. | ||
26 | + */ | ||
27 | +@Command(scope = "onos", name = "app-install", | ||
28 | + description = "Lists application ID information") | ||
29 | +public class ApplicationInstallCommand extends AbstractShellCommand { | ||
30 | + | ||
31 | + @Override | ||
32 | + protected void execute() { | ||
33 | + // FIXME: merely an experiment for now | ||
34 | + try (InputStreamReader isr = new InputStreamReader(System.in); | ||
35 | + BufferedReader br = new BufferedReader(isr)) { | ||
36 | + String line; | ||
37 | + while ((line = br.readLine()) != null) { | ||
38 | + print("%s", line.toUpperCase()); | ||
39 | + } | ||
40 | + } catch (IOException e) { | ||
41 | + e.printStackTrace(); | ||
42 | + } | ||
43 | + } | ||
44 | + | ||
45 | +} |
... | @@ -21,6 +21,10 @@ | ... | @@ -21,6 +21,10 @@ |
21 | </command> | 21 | </command> |
22 | 22 | ||
23 | <command> | 23 | <command> |
24 | + <action class="org.onosproject.cli.ApplicationInstallCommand"/> | ||
25 | + </command> | ||
26 | + | ||
27 | + <command> | ||
24 | <action class="org.onosproject.cli.MetricsListCommand"/> | 28 | <action class="org.onosproject.cli.MetricsListCommand"/> |
25 | </command> | 29 | </command> |
26 | 30 | ... | ... |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.app; | ||
17 | + | ||
18 | +import org.onosproject.core.Application; | ||
19 | +import org.onosproject.core.ApplicationId; | ||
20 | +import org.onosproject.core.Permission; | ||
21 | + | ||
22 | +import java.io.InputStream; | ||
23 | +import java.util.Set; | ||
24 | + | ||
25 | +/** | ||
26 | + * Service for managing network control applications. | ||
27 | + */ | ||
28 | +public interface ApplicationAdminService extends ApplicationService { | ||
29 | + | ||
30 | + /** | ||
31 | + * Installs the application contained in the specified application archive | ||
32 | + * input stream. | ||
33 | + * | ||
34 | + * @param appDescStream application descriptor input stream | ||
35 | + * @return installed application descriptor | ||
36 | + * @throws org.onosproject.app.ApplicationException if unable to read the app archive stream | ||
37 | + */ | ||
38 | + Application install(InputStream appDescStream); | ||
39 | + | ||
40 | + /** | ||
41 | + * Uninstalls the specified application. | ||
42 | + * | ||
43 | + * @param appId application identifier | ||
44 | + */ | ||
45 | + void uninstall(ApplicationId appId); | ||
46 | + | ||
47 | + /** | ||
48 | + * Activates the specified application. | ||
49 | + * | ||
50 | + * @param appId application identifier | ||
51 | + */ | ||
52 | + void activate(ApplicationId appId); | ||
53 | + | ||
54 | + /** | ||
55 | + * Deactivates the specified application. | ||
56 | + * | ||
57 | + * @param appId application identifier | ||
58 | + */ | ||
59 | + void deactivate(ApplicationId appId); | ||
60 | + | ||
61 | + /** | ||
62 | + * Updates the permissions granted to the applications. | ||
63 | + * | ||
64 | + * @param appId application identifier | ||
65 | + * @param permissions set of granted permissions | ||
66 | + */ | ||
67 | + void setPermissions(ApplicationId appId, Set<Permission> permissions); | ||
68 | +} |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.app; | ||
17 | + | ||
18 | +import org.onosproject.core.Permission; | ||
19 | +import org.onosproject.core.Version; | ||
20 | + | ||
21 | +import java.net.URI; | ||
22 | +import java.util.Optional; | ||
23 | +import java.util.Set; | ||
24 | + | ||
25 | +/** | ||
26 | + * Description of a network control/management application. | ||
27 | + */ | ||
28 | +public interface ApplicationDescription { | ||
29 | + | ||
30 | + /** | ||
31 | + * Returns the application name id. | ||
32 | + * | ||
33 | + * @return application identifier | ||
34 | + */ | ||
35 | + String name(); | ||
36 | + | ||
37 | + /** | ||
38 | + * Returns the application version. | ||
39 | + * | ||
40 | + * @return application version | ||
41 | + */ | ||
42 | + Version version(); | ||
43 | + | ||
44 | + /** | ||
45 | + * Returns description of the application. | ||
46 | + * | ||
47 | + * @return application description text | ||
48 | + */ | ||
49 | + String description(); | ||
50 | + | ||
51 | + /** | ||
52 | + * Returns the name of the application origin, group or company. | ||
53 | + * | ||
54 | + * @return application origin | ||
55 | + */ | ||
56 | + String origin(); | ||
57 | + | ||
58 | + /** | ||
59 | + * Returns the permissions requested by the application. | ||
60 | + * | ||
61 | + * @return requested permissions | ||
62 | + */ | ||
63 | + Set<Permission> permissions(); | ||
64 | + | ||
65 | + /** | ||
66 | + * Returns the feature repository URI. Null value signifies that the | ||
67 | + * application did not provide its own features repository. | ||
68 | + * | ||
69 | + * @return optional feature repo URL | ||
70 | + */ | ||
71 | + Optional<URI> featuresRepo(); | ||
72 | + | ||
73 | + /** | ||
74 | + * Returns the set of features comprising the application. At least one | ||
75 | + * feature must be given. | ||
76 | + * | ||
77 | + * @return application features | ||
78 | + */ | ||
79 | + Set<String> features(); | ||
80 | +} |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.app; | ||
17 | + | ||
18 | +import org.onosproject.core.Application; | ||
19 | +import org.onosproject.event.AbstractEvent; | ||
20 | + | ||
21 | +/** | ||
22 | + * Describes application lifecycle event. | ||
23 | + */ | ||
24 | +public class ApplicationEvent extends AbstractEvent<ApplicationEvent.Type, Application> { | ||
25 | + | ||
26 | + public enum Type { | ||
27 | + /** | ||
28 | + * Signifies that an application has been installed. | ||
29 | + */ | ||
30 | + APP_INSTALLED, | ||
31 | + | ||
32 | + /** | ||
33 | + * Signifies that an application has been activated. | ||
34 | + */ | ||
35 | + APP_ACTIVATED, | ||
36 | + | ||
37 | + /** | ||
38 | + * Signifies that an application has been deactivated. | ||
39 | + */ | ||
40 | + APP_DEACTIVATED, | ||
41 | + | ||
42 | + /** | ||
43 | + * Signifies that an application has been uninstalled. | ||
44 | + */ | ||
45 | + APP_UNINSTALLED, | ||
46 | + | ||
47 | + /** | ||
48 | + * Signifies that application granted permissions have changed. | ||
49 | + */ | ||
50 | + APP_PERMISSIONS_CHANGED | ||
51 | + } | ||
52 | + | ||
53 | + /** | ||
54 | + * Creates an event of a given type and for the specified app and the | ||
55 | + * current time. | ||
56 | + * | ||
57 | + * @param type app event type | ||
58 | + * @param app event app subject | ||
59 | + */ | ||
60 | + public ApplicationEvent(Type type, Application app) { | ||
61 | + super(type, app); | ||
62 | + } | ||
63 | + | ||
64 | + /** | ||
65 | + * Creates an event of a given type and for the specified app and time. | ||
66 | + * | ||
67 | + * @param type app event type | ||
68 | + * @param app event app subject | ||
69 | + * @param time occurrence time | ||
70 | + */ | ||
71 | + public ApplicationEvent(Type type, Application app, long time) { | ||
72 | + super(type, app, time); | ||
73 | + } | ||
74 | + | ||
75 | +} |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.app; | ||
17 | + | ||
18 | +/** | ||
19 | + * Represents class of errors related to application management. | ||
20 | + */ | ||
21 | +public class ApplicationException extends RuntimeException { | ||
22 | + | ||
23 | + private static final long serialVersionUID = -2287403908433720122L; | ||
24 | + | ||
25 | + /** | ||
26 | + * Constructs an exception with no message and no underlying cause. | ||
27 | + */ | ||
28 | + public ApplicationException() { | ||
29 | + } | ||
30 | + | ||
31 | + /** | ||
32 | + * Constructs an exception with the specified message. | ||
33 | + * | ||
34 | + * @param message the message describing the specific nature of the error | ||
35 | + */ | ||
36 | + public ApplicationException(String message) { | ||
37 | + super(message); | ||
38 | + } | ||
39 | + | ||
40 | + /** | ||
41 | + * Constructs an exception with the specified message and the underlying cause. | ||
42 | + * | ||
43 | + * @param message the message describing the specific nature of the error | ||
44 | + * @param cause the underlying cause of this error | ||
45 | + */ | ||
46 | + public ApplicationException(String message, Throwable cause) { | ||
47 | + super(message, cause); | ||
48 | + } | ||
49 | +} |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.app; | ||
17 | + | ||
18 | +import org.onosproject.event.EventListener; | ||
19 | + | ||
20 | +/** | ||
21 | + * Entity capable of receiving application related events. | ||
22 | + */ | ||
23 | +public interface ApplicationListener extends EventListener<ApplicationEvent> { | ||
24 | +} |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.app; | ||
17 | + | ||
18 | +import org.onosproject.core.Application; | ||
19 | +import org.onosproject.core.ApplicationId; | ||
20 | +import org.onosproject.core.Permission; | ||
21 | + | ||
22 | +import java.util.Set; | ||
23 | + | ||
24 | +/** | ||
25 | + * Service for inspecting inventory of network control applications. | ||
26 | + */ | ||
27 | +public interface ApplicationService { | ||
28 | + | ||
29 | + /** | ||
30 | + * Returns the set of all installed applications. | ||
31 | + * | ||
32 | + * @return set of installed apps | ||
33 | + */ | ||
34 | + Set<Application> getApplications(); | ||
35 | + | ||
36 | + /** | ||
37 | + * Returns the registered id of the application with the given name. | ||
38 | + * | ||
39 | + * @param name application name | ||
40 | + * @return registered application id | ||
41 | + */ | ||
42 | + ApplicationId getId(String name); | ||
43 | + | ||
44 | + /** | ||
45 | + * Returns the application with the supplied application identifier. | ||
46 | + * | ||
47 | + * @param appId application identifier | ||
48 | + * @return application descriptor | ||
49 | + */ | ||
50 | + Application getApplication(ApplicationId appId); | ||
51 | + | ||
52 | + /** | ||
53 | + * Return the application state. | ||
54 | + * | ||
55 | + * @param appId application identifier | ||
56 | + * @return application state | ||
57 | + */ | ||
58 | + ApplicationState getState(ApplicationId appId); | ||
59 | + | ||
60 | + /** | ||
61 | + * Returns the permissions currently granted to the applications. | ||
62 | + * | ||
63 | + * @param appId application identifier | ||
64 | + * @return set of granted permissions | ||
65 | + */ | ||
66 | + Set<Permission> getPermissions(ApplicationId appId); | ||
67 | + | ||
68 | + /** | ||
69 | + * Adds the given listener for application lifecycle events. | ||
70 | + * | ||
71 | + * @param listener listener to be added | ||
72 | + */ | ||
73 | + void addListener(ApplicationListener listener); | ||
74 | + | ||
75 | + /** | ||
76 | + * Removes the specified listener for application lifecycle events. | ||
77 | + * | ||
78 | + * @param listener listener to be removed | ||
79 | + */ | ||
80 | + void removeListener(ApplicationListener listener); | ||
81 | + | ||
82 | +} |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.app; | ||
17 | + | ||
18 | +/** | ||
19 | + * Representation of an application state. | ||
20 | + */ | ||
21 | +public enum ApplicationState { | ||
22 | + | ||
23 | + /** | ||
24 | + * Indicates that application has been installed, but is not running. | ||
25 | + */ | ||
26 | + INSTALLED, | ||
27 | + | ||
28 | + /** | ||
29 | + * Indicates that application is active. | ||
30 | + */ | ||
31 | + ACTIVE | ||
32 | + | ||
33 | +} |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.app; | ||
17 | + | ||
18 | +import org.onosproject.core.Application; | ||
19 | +import org.onosproject.core.ApplicationId; | ||
20 | +import org.onosproject.core.Permission; | ||
21 | +import org.onosproject.store.Store; | ||
22 | + | ||
23 | +import java.io.InputStream; | ||
24 | +import java.util.Set; | ||
25 | + | ||
26 | +/** | ||
27 | + * Service for managing network control applications. | ||
28 | + */ | ||
29 | +public interface ApplicationStore extends Store<ApplicationEvent, ApplicationStoreDelegate> { | ||
30 | + | ||
31 | + /** | ||
32 | + * Returns the set of all installed applications. | ||
33 | + * | ||
34 | + * @return set of installed apps | ||
35 | + */ | ||
36 | + Set<Application> getApplications(); | ||
37 | + | ||
38 | + /** | ||
39 | + * Returns the registered id of the application with the given name. | ||
40 | + * | ||
41 | + * @param name application name | ||
42 | + * @return registered application id | ||
43 | + */ | ||
44 | + ApplicationId getId(String name); | ||
45 | + | ||
46 | + /** | ||
47 | + * Returns the application with the supplied application identifier. | ||
48 | + * | ||
49 | + * @param appId application identifier | ||
50 | + * @return application descriptor | ||
51 | + */ | ||
52 | + Application getApplication(ApplicationId appId); | ||
53 | + | ||
54 | + /** | ||
55 | + * Returns the current application state. | ||
56 | + * | ||
57 | + * @param appId application identifier | ||
58 | + * @return application state | ||
59 | + */ | ||
60 | + ApplicationState getState(ApplicationId appId); | ||
61 | + | ||
62 | + /** | ||
63 | + * Creates the application from the specified application descriptor | ||
64 | + * input stream. | ||
65 | + * | ||
66 | + * @param appDescStream application archive input stream | ||
67 | + * @return application descriptor | ||
68 | + */ | ||
69 | + Application create(InputStream appDescStream); | ||
70 | + | ||
71 | + /** | ||
72 | + * Removes the specified application. | ||
73 | + * | ||
74 | + * @param appId application identifier | ||
75 | + */ | ||
76 | + void remove(ApplicationId appId); | ||
77 | + | ||
78 | + /** | ||
79 | + * Mark the application as actived. | ||
80 | + * | ||
81 | + * @param appId application identifier | ||
82 | + */ | ||
83 | + void activate(ApplicationId appId); | ||
84 | + | ||
85 | + /** | ||
86 | + * Mark the application as deactivated. | ||
87 | + * | ||
88 | + * @param appId application identifier | ||
89 | + */ | ||
90 | + void deactivate(ApplicationId appId); | ||
91 | + | ||
92 | + /** | ||
93 | + * Returns the permissions granted to the applications. | ||
94 | + * | ||
95 | + * @param appId application identifier | ||
96 | + * @return set of granted permissions | ||
97 | + */ | ||
98 | + Set<Permission> getPermissions(ApplicationId appId); | ||
99 | + | ||
100 | + /** | ||
101 | + * Updates the permissions granted to the applications. | ||
102 | + * | ||
103 | + * @param appId application identifier | ||
104 | + * @param permissions set of granted permissions | ||
105 | + */ | ||
106 | + void setPermissions(ApplicationId appId, Set<Permission> permissions); | ||
107 | + | ||
108 | +} |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.app; | ||
17 | + | ||
18 | +import org.onosproject.store.StoreDelegate; | ||
19 | + | ||
20 | +/** | ||
21 | + * Application store delegate abstraction. | ||
22 | + */ | ||
23 | +public interface ApplicationStoreDelegate extends StoreDelegate<ApplicationEvent> { | ||
24 | +} |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.app; | ||
17 | + | ||
18 | +import org.onosproject.core.Permission; | ||
19 | +import org.onosproject.core.Version; | ||
20 | + | ||
21 | +import java.net.URI; | ||
22 | +import java.util.Optional; | ||
23 | +import java.util.Set; | ||
24 | + | ||
25 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
26 | +import static com.google.common.base.Preconditions.checkArgument; | ||
27 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
28 | + | ||
29 | +/** | ||
30 | + * Default implementation of network control/management application descriptor. | ||
31 | + */ | ||
32 | +public class DefaultApplicationDescription implements ApplicationDescription { | ||
33 | + | ||
34 | + private final String name; | ||
35 | + private final Version version; | ||
36 | + private final String description; | ||
37 | + private final String origin; | ||
38 | + private final Set<Permission> permissions; | ||
39 | + private final Optional<URI> featuresRepo; | ||
40 | + private final Set<String> features; | ||
41 | + | ||
42 | + /** | ||
43 | + * Creates a new application descriptor using the supplied data. | ||
44 | + * | ||
45 | + * @param name application name | ||
46 | + * @param version application version | ||
47 | + * @param description application description | ||
48 | + * @param origin origin company | ||
49 | + * @param permissions requested permissions | ||
50 | + * @param featuresRepo optional features repo URI | ||
51 | + * @param features application features | ||
52 | + */ | ||
53 | + public DefaultApplicationDescription(String name, Version version, | ||
54 | + String description, String origin, | ||
55 | + Set<Permission> permissions, | ||
56 | + URI featuresRepo, Set<String> features) { | ||
57 | + this.name = checkNotNull(name, "Name cannot be null"); | ||
58 | + this.version = checkNotNull(version, "Version cannot be null"); | ||
59 | + this.description = checkNotNull(description, "Description cannot be null"); | ||
60 | + this.origin = checkNotNull(origin, "Origin cannot be null"); | ||
61 | + this.permissions = checkNotNull(permissions, "Permissions cannot be null"); | ||
62 | + this.featuresRepo = Optional.ofNullable(featuresRepo); | ||
63 | + this.features = checkNotNull(features, "Features cannot be null"); | ||
64 | + checkArgument(!features.isEmpty(), "There must be at least one feature"); | ||
65 | + } | ||
66 | + | ||
67 | + @Override | ||
68 | + public String name() { | ||
69 | + return name; | ||
70 | + } | ||
71 | + | ||
72 | + @Override | ||
73 | + public Version version() { | ||
74 | + return version; | ||
75 | + } | ||
76 | + | ||
77 | + @Override | ||
78 | + public String description() { | ||
79 | + return description; | ||
80 | + } | ||
81 | + | ||
82 | + @Override | ||
83 | + public String origin() { | ||
84 | + return origin; | ||
85 | + } | ||
86 | + | ||
87 | + @Override | ||
88 | + public Set<Permission> permissions() { | ||
89 | + return permissions; | ||
90 | + } | ||
91 | + | ||
92 | + @Override | ||
93 | + public Optional<URI> featuresRepo() { | ||
94 | + return featuresRepo; | ||
95 | + } | ||
96 | + | ||
97 | + @Override | ||
98 | + public Set<String> features() { | ||
99 | + return features; | ||
100 | + } | ||
101 | + | ||
102 | + @Override | ||
103 | + public String toString() { | ||
104 | + return toStringHelper(this) | ||
105 | + .add("name", name) | ||
106 | + .add("version", version) | ||
107 | + .add("description", description) | ||
108 | + .add("origin", origin) | ||
109 | + .add("permissions", permissions) | ||
110 | + .add("featuresRepo", featuresRepo) | ||
111 | + .add("features", features) | ||
112 | + .toString(); | ||
113 | + } | ||
114 | +} |
1 | /* | 1 | /* |
2 | - * Copyright 2014 Open Networking Laboratory | 2 | + * Copyright 2015 Open Networking Laboratory |
3 | * | 3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
... | @@ -15,6 +15,6 @@ | ... | @@ -15,6 +15,6 @@ |
15 | */ | 15 | */ |
16 | 16 | ||
17 | /** | 17 | /** |
18 | - * Implementation of JSON codec factory and of the builtin codecs. | 18 | + * Set of abstractions for managing network control applications. |
19 | */ | 19 | */ |
20 | -package org.onosproject.json.impl; | 20 | +package org.onosproject.app; |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.core; | ||
17 | + | ||
18 | +import java.net.URI; | ||
19 | +import java.util.Optional; | ||
20 | +import java.util.Set; | ||
21 | + | ||
22 | +/** | ||
23 | + * Abstraction of a network control/management application. | ||
24 | + */ | ||
25 | +public interface Application { | ||
26 | + | ||
27 | + /** | ||
28 | + * Returns the application name id. | ||
29 | + * | ||
30 | + * @return application identifier | ||
31 | + */ | ||
32 | + ApplicationId id(); | ||
33 | + | ||
34 | + /** | ||
35 | + * Returns the application version. | ||
36 | + * | ||
37 | + * @return application version | ||
38 | + */ | ||
39 | + Version version(); | ||
40 | + | ||
41 | + /** | ||
42 | + * Returns description of the application. | ||
43 | + * | ||
44 | + * @return application description text | ||
45 | + */ | ||
46 | + String description(); | ||
47 | + | ||
48 | + /** | ||
49 | + * Returns the name of the application origin, group or company. | ||
50 | + * | ||
51 | + * @return application origin | ||
52 | + */ | ||
53 | + String origin(); | ||
54 | + | ||
55 | + /** | ||
56 | + * Returns the permissions requested by the application. | ||
57 | + * | ||
58 | + * @return requested permissions | ||
59 | + */ | ||
60 | + Set<Permission> permissions(); | ||
61 | + | ||
62 | + /** | ||
63 | + * Returns the feature repository URI. Null value signifies that the | ||
64 | + * application did not provide its own features repository. | ||
65 | + * | ||
66 | + * @return optional feature repo URL | ||
67 | + */ | ||
68 | + Optional<URI> featuresRepo(); | ||
69 | + | ||
70 | + /** | ||
71 | + * Returns the set of features comprising the application. At least one | ||
72 | + * feature must be given. | ||
73 | + * | ||
74 | + * @return application features | ||
75 | + */ | ||
76 | + Set<String> features(); | ||
77 | +} |
... | @@ -14,6 +14,7 @@ | ... | @@ -14,6 +14,7 @@ |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | package org.onosproject.core; | 16 | package org.onosproject.core; |
17 | +// FIXME: Move to org.onosproject.app package | ||
17 | 18 | ||
18 | import java.util.Set; | 19 | import java.util.Set; |
19 | 20 | ||
... | @@ -31,12 +32,21 @@ public interface ApplicationIdStore { | ... | @@ -31,12 +32,21 @@ public interface ApplicationIdStore { |
31 | 32 | ||
32 | /** | 33 | /** |
33 | * Returns an existing application id from a given id. | 34 | * Returns an existing application id from a given id. |
35 | + * | ||
34 | * @param id the short value of the id | 36 | * @param id the short value of the id |
35 | - * @return an application id | 37 | + * @return an application id; null if no such app registered |
36 | */ | 38 | */ |
37 | ApplicationId getAppId(Short id); | 39 | ApplicationId getAppId(Short id); |
38 | 40 | ||
39 | /** | 41 | /** |
42 | + * Returns registered application id from the given name. | ||
43 | + * | ||
44 | + * @param name application name | ||
45 | + * @return an application id; null if no such app registered | ||
46 | + */ | ||
47 | + ApplicationId getAppId(String name); | ||
48 | + | ||
49 | + /** | ||
40 | * Registers a new application by its name, which is expected | 50 | * Registers a new application by its name, which is expected |
41 | * to follow the reverse DNS convention, e.g. | 51 | * to follow the reverse DNS convention, e.g. |
42 | * {@code org.flying.circus.app} | 52 | * {@code org.flying.circus.app} | ... | ... |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.core; | ||
17 | + | ||
18 | +import java.net.URI; | ||
19 | +import java.util.Objects; | ||
20 | +import java.util.Optional; | ||
21 | +import java.util.Set; | ||
22 | + | ||
23 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
24 | +import static com.google.common.base.Preconditions.checkArgument; | ||
25 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
26 | + | ||
27 | +/** | ||
28 | + * Default implementation of network control/management application descriptor. | ||
29 | + */ | ||
30 | +public class DefaultApplication implements Application { | ||
31 | + | ||
32 | + private final ApplicationId appId; | ||
33 | + private final Version version; | ||
34 | + private final String description; | ||
35 | + private final String origin; | ||
36 | + private final Set<Permission> permissions; | ||
37 | + private final Optional<URI> featuresRepo; | ||
38 | + private final Set<String> features; | ||
39 | + | ||
40 | + /** | ||
41 | + * Creates a new application descriptor using the supplied data. | ||
42 | + * | ||
43 | + * @param appId application identifier | ||
44 | + * @param version application version | ||
45 | + * @param description application description | ||
46 | + * @param origin origin company | ||
47 | + * @param permissions requested permissions | ||
48 | + * @param featuresRepo optional features repo URI | ||
49 | + * @param features application features | ||
50 | + */ | ||
51 | + public DefaultApplication(ApplicationId appId, Version version, | ||
52 | + String description, String origin, | ||
53 | + Set<Permission> permissions, | ||
54 | + Optional<URI> featuresRepo, Set<String> features) { | ||
55 | + this.appId = checkNotNull(appId, "ID cannot be null"); | ||
56 | + this.version = checkNotNull(version, "Version cannot be null"); | ||
57 | + this.description = checkNotNull(description, "Description cannot be null"); | ||
58 | + this.origin = checkNotNull(origin, "Origin cannot be null"); | ||
59 | + this.permissions = checkNotNull(permissions, "Permissions cannot be null"); | ||
60 | + this.featuresRepo = checkNotNull(featuresRepo, "Features repo cannot be null"); | ||
61 | + this.features = checkNotNull(features, "Features cannot be null"); | ||
62 | + checkArgument(!features.isEmpty(), "There must be at least one feature"); | ||
63 | + } | ||
64 | + | ||
65 | + @Override | ||
66 | + public ApplicationId id() { | ||
67 | + return appId; | ||
68 | + } | ||
69 | + | ||
70 | + @Override | ||
71 | + public Version version() { | ||
72 | + return version; | ||
73 | + } | ||
74 | + | ||
75 | + @Override | ||
76 | + public String description() { | ||
77 | + return description; | ||
78 | + } | ||
79 | + | ||
80 | + @Override | ||
81 | + public String origin() { | ||
82 | + return origin; | ||
83 | + } | ||
84 | + | ||
85 | + @Override | ||
86 | + public Set<Permission> permissions() { | ||
87 | + return permissions; | ||
88 | + } | ||
89 | + | ||
90 | + @Override | ||
91 | + public Optional<URI> featuresRepo() { | ||
92 | + return featuresRepo; | ||
93 | + } | ||
94 | + | ||
95 | + @Override | ||
96 | + public Set<String> features() { | ||
97 | + return features; | ||
98 | + } | ||
99 | + | ||
100 | + @Override | ||
101 | + public int hashCode() { | ||
102 | + return Objects.hash(appId, version, description, origin, permissions, | ||
103 | + featuresRepo, features); | ||
104 | + } | ||
105 | + | ||
106 | + @Override | ||
107 | + public boolean equals(Object obj) { | ||
108 | + if (this == obj) { | ||
109 | + return true; | ||
110 | + } | ||
111 | + if (obj == null || getClass() != obj.getClass()) { | ||
112 | + return false; | ||
113 | + } | ||
114 | + final DefaultApplication other = (DefaultApplication) obj; | ||
115 | + return Objects.equals(this.appId, other.appId) && | ||
116 | + Objects.equals(this.version, other.version) && | ||
117 | + Objects.equals(this.description, other.description) && | ||
118 | + Objects.equals(this.origin, other.origin) && | ||
119 | + Objects.equals(this.permissions, other.permissions) && | ||
120 | + Objects.equals(this.featuresRepo, other.featuresRepo) && | ||
121 | + Objects.equals(this.features, other.features); | ||
122 | + } | ||
123 | + | ||
124 | + @Override | ||
125 | + public String toString() { | ||
126 | + return toStringHelper(this) | ||
127 | + .add("appId", appId) | ||
128 | + .add("version", version) | ||
129 | + .add("description", description) | ||
130 | + .add("origin", origin) | ||
131 | + .add("permissions", permissions) | ||
132 | + .add("featuresRepo", featuresRepo) | ||
133 | + .add("features", features) | ||
134 | + .toString(); | ||
135 | + } | ||
136 | +} |
... | @@ -18,6 +18,7 @@ package org.onosproject.core; | ... | @@ -18,6 +18,7 @@ package org.onosproject.core; |
18 | import java.util.Objects; | 18 | import java.util.Objects; |
19 | 19 | ||
20 | import static com.google.common.base.MoreObjects.toStringHelper; | 20 | import static com.google.common.base.MoreObjects.toStringHelper; |
21 | +import static com.google.common.base.Preconditions.checkArgument; | ||
21 | 22 | ||
22 | /** | 23 | /** |
23 | * Application identifier. | 24 | * Application identifier. |
... | @@ -33,8 +34,9 @@ public class DefaultApplicationId implements ApplicationId { | ... | @@ -33,8 +34,9 @@ public class DefaultApplicationId implements ApplicationId { |
33 | * @param id application identifier | 34 | * @param id application identifier |
34 | * @param name application name | 35 | * @param name application name |
35 | */ | 36 | */ |
36 | - public DefaultApplicationId(Short id, String name) { | 37 | + public DefaultApplicationId(int id, String name) { |
37 | - this.id = id; | 38 | + checkArgument(0 <= id && id <= Short.MAX_VALUE, "id is outside range"); |
39 | + this.id = (short) id; | ||
38 | this.name = name; | 40 | this.name = name; |
39 | } | 41 | } |
40 | 42 | ... | ... |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.core; | ||
17 | + | ||
18 | +/** | ||
19 | + * Representation of an application permission. | ||
20 | + */ | ||
21 | +public interface Permission { | ||
22 | + // TODO: to be fleshed out | ||
23 | +} |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.app; | ||
17 | + | ||
18 | +import org.onosproject.core.Application; | ||
19 | +import org.onosproject.core.ApplicationId; | ||
20 | +import org.onosproject.core.Permission; | ||
21 | + | ||
22 | +import java.io.InputStream; | ||
23 | +import java.util.Set; | ||
24 | + | ||
25 | +/** | ||
26 | + * Adapter for testing against application admin service. | ||
27 | + */ | ||
28 | +public class ApplicationAdminServiceAdapter extends ApplicationServiceAdapter | ||
29 | + implements ApplicationAdminService { | ||
30 | + @Override | ||
31 | + public Set<Application> getApplications() { | ||
32 | + return null; | ||
33 | + } | ||
34 | + | ||
35 | + @Override | ||
36 | + public Application getApplication(ApplicationId appId) { | ||
37 | + return null; | ||
38 | + } | ||
39 | + | ||
40 | + @Override | ||
41 | + public ApplicationState getState(ApplicationId appId) { | ||
42 | + return null; | ||
43 | + } | ||
44 | + | ||
45 | + @Override | ||
46 | + public Set<Permission> getPermissions(ApplicationId appId) { | ||
47 | + return null; | ||
48 | + } | ||
49 | + | ||
50 | + @Override | ||
51 | + public void addListener(ApplicationListener listener) { | ||
52 | + } | ||
53 | + | ||
54 | + @Override | ||
55 | + public void removeListener(ApplicationListener listener) { | ||
56 | + } | ||
57 | + | ||
58 | + @Override | ||
59 | + public Application install(InputStream appDescStream) { | ||
60 | + return null; | ||
61 | + } | ||
62 | + | ||
63 | + @Override | ||
64 | + public void uninstall(ApplicationId appId) { | ||
65 | + } | ||
66 | + | ||
67 | + @Override | ||
68 | + public void activate(ApplicationId appId) { | ||
69 | + } | ||
70 | + | ||
71 | + @Override | ||
72 | + public void deactivate(ApplicationId appId) { | ||
73 | + } | ||
74 | + | ||
75 | + @Override | ||
76 | + public void setPermissions(ApplicationId appId, Set<Permission> permissions) { | ||
77 | + } | ||
78 | +} |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.app; | ||
17 | + | ||
18 | +import org.junit.Test; | ||
19 | +import org.onosproject.core.Application; | ||
20 | +import org.onosproject.core.DefaultApplication; | ||
21 | +import org.onosproject.event.AbstractEventTest; | ||
22 | + | ||
23 | +import java.util.Optional; | ||
24 | + | ||
25 | +import static org.onosproject.app.ApplicationEvent.Type.APP_ACTIVATED; | ||
26 | +import static org.onosproject.app.DefaultApplicationDescriptionTest.*; | ||
27 | +import static org.onosproject.core.DefaultApplicationTest.APP_ID; | ||
28 | + | ||
29 | +/** | ||
30 | + * Test of the application event. | ||
31 | + */ | ||
32 | +public class ApplicationEventTest extends AbstractEventTest { | ||
33 | + | ||
34 | + private Application createApp() { | ||
35 | + return new DefaultApplication(APP_ID, VER, DESC, ORIGIN, | ||
36 | + PERMS, Optional.of(FURL), FEATURES); | ||
37 | + } | ||
38 | + | ||
39 | + @Test | ||
40 | + public void withoutTime() { | ||
41 | + Application app = createApp(); | ||
42 | + ApplicationEvent event = new ApplicationEvent(APP_ACTIVATED, app, 123L); | ||
43 | + validateEvent(event, APP_ACTIVATED, app, 123L); | ||
44 | + } | ||
45 | + | ||
46 | + @Test | ||
47 | + public void withTime() { | ||
48 | + Application app = createApp(); | ||
49 | + long before = System.currentTimeMillis(); | ||
50 | + ApplicationEvent event = new ApplicationEvent(APP_ACTIVATED, app); | ||
51 | + long after = System.currentTimeMillis(); | ||
52 | + validateEvent(event, APP_ACTIVATED, app, before, after); | ||
53 | + } | ||
54 | + | ||
55 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.app; | ||
17 | + | ||
18 | +import org.onlab.junit.ExceptionTest; | ||
19 | + | ||
20 | +public class ApplicationExceptionTest extends ExceptionTest { | ||
21 | + | ||
22 | + @Override | ||
23 | + protected Exception getDefault() { | ||
24 | + return new ApplicationException(); | ||
25 | + } | ||
26 | + | ||
27 | + @Override | ||
28 | + protected Exception getWithMessage() { | ||
29 | + return new ApplicationException(MESSAGE); | ||
30 | + } | ||
31 | + | ||
32 | + @Override | ||
33 | + protected Exception getWithMessageAndCause() { | ||
34 | + return new ApplicationException(MESSAGE, CAUSE); | ||
35 | + } | ||
36 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.app; | ||
17 | + | ||
18 | +import org.onosproject.core.Application; | ||
19 | +import org.onosproject.core.ApplicationId; | ||
20 | +import org.onosproject.core.Permission; | ||
21 | + | ||
22 | +import java.util.Set; | ||
23 | + | ||
24 | +/** | ||
25 | + * Adapter for testing against application service. | ||
26 | + */ | ||
27 | +public class ApplicationServiceAdapter implements ApplicationService { | ||
28 | + @Override | ||
29 | + public Set<Application> getApplications() { | ||
30 | + return null; | ||
31 | + } | ||
32 | + | ||
33 | + @Override | ||
34 | + public ApplicationId getId(String name) { | ||
35 | + return null; | ||
36 | + } | ||
37 | + | ||
38 | + @Override | ||
39 | + public Application getApplication(ApplicationId appId) { | ||
40 | + return null; | ||
41 | + } | ||
42 | + | ||
43 | + @Override | ||
44 | + public ApplicationState getState(ApplicationId appId) { | ||
45 | + return null; | ||
46 | + } | ||
47 | + | ||
48 | + @Override | ||
49 | + public Set<Permission> getPermissions(ApplicationId appId) { | ||
50 | + return null; | ||
51 | + } | ||
52 | + | ||
53 | + @Override | ||
54 | + public void addListener(ApplicationListener listener) { | ||
55 | + } | ||
56 | + | ||
57 | + @Override | ||
58 | + public void removeListener(ApplicationListener listener) { | ||
59 | + } | ||
60 | +} |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.app; | ||
17 | + | ||
18 | +import org.onosproject.core.Application; | ||
19 | +import org.onosproject.core.ApplicationId; | ||
20 | +import org.onosproject.core.Permission; | ||
21 | +import org.onosproject.store.AbstractStore; | ||
22 | + | ||
23 | +import java.io.InputStream; | ||
24 | +import java.util.Set; | ||
25 | + | ||
26 | +/** | ||
27 | + * Adapter for application testing against application store. | ||
28 | + */ | ||
29 | +public class ApplicationStoreAdapter | ||
30 | + extends AbstractStore<ApplicationEvent, ApplicationStoreDelegate> | ||
31 | + implements ApplicationStore { | ||
32 | + @Override | ||
33 | + public Set<Application> getApplications() { | ||
34 | + return null; | ||
35 | + } | ||
36 | + | ||
37 | + @Override | ||
38 | + public ApplicationId getId(String name) { | ||
39 | + return null; | ||
40 | + } | ||
41 | + | ||
42 | + @Override | ||
43 | + public Application getApplication(ApplicationId appId) { | ||
44 | + return null; | ||
45 | + } | ||
46 | + | ||
47 | + @Override | ||
48 | + public ApplicationState getState(ApplicationId appId) { | ||
49 | + return null; | ||
50 | + } | ||
51 | + | ||
52 | + @Override | ||
53 | + public Application create(InputStream appDescStream) { | ||
54 | + return null; | ||
55 | + } | ||
56 | + | ||
57 | + @Override | ||
58 | + public void remove(ApplicationId appId) { | ||
59 | + } | ||
60 | + | ||
61 | + @Override | ||
62 | + public void activate(ApplicationId appId) { | ||
63 | + } | ||
64 | + | ||
65 | + @Override | ||
66 | + public void deactivate(ApplicationId appId) { | ||
67 | + } | ||
68 | + | ||
69 | + @Override | ||
70 | + public Set<Permission> getPermissions(ApplicationId appId) { | ||
71 | + return null; | ||
72 | + } | ||
73 | + | ||
74 | + @Override | ||
75 | + public void setPermissions(ApplicationId appId, Set<Permission> permissions) { | ||
76 | + } | ||
77 | + | ||
78 | +} |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.app; | ||
17 | + | ||
18 | +import com.google.common.collect.ImmutableSet; | ||
19 | +import org.junit.Test; | ||
20 | +import org.onosproject.core.Permission; | ||
21 | +import org.onosproject.core.Version; | ||
22 | + | ||
23 | +import java.net.URI; | ||
24 | +import java.util.Set; | ||
25 | + | ||
26 | +import static org.junit.Assert.assertEquals; | ||
27 | +import static org.junit.Assert.assertTrue; | ||
28 | + | ||
29 | +/** | ||
30 | + * Basic tests of the default app description. | ||
31 | + */ | ||
32 | +public class DefaultApplicationDescriptionTest { | ||
33 | + | ||
34 | + public static final String APP_NAME = "org.foo.app"; | ||
35 | + public static final Version VER = Version.version(1, 2, "a", null); | ||
36 | + public static final String DESC = "Awesome application from Circus"; | ||
37 | + public static final String ORIGIN = "Circus"; | ||
38 | + public static final Set<Permission> PERMS = ImmutableSet.of(); | ||
39 | + public static final URI FURL = URI.create("mvn:org.foo-features/1.2a/xml/features"); | ||
40 | + public static final Set<String> FEATURES = ImmutableSet.of("foo"); | ||
41 | + | ||
42 | + @Test | ||
43 | + public void basics() { | ||
44 | + ApplicationDescription app = | ||
45 | + new DefaultApplicationDescription(APP_NAME, VER, DESC, ORIGIN, | ||
46 | + PERMS, FURL, FEATURES); | ||
47 | + assertEquals("incorrect id", APP_NAME, app.name()); | ||
48 | + assertEquals("incorrect version", VER, app.version()); | ||
49 | + assertEquals("incorrect description", DESC, app.description()); | ||
50 | + assertEquals("incorrect origin", ORIGIN, app.origin()); | ||
51 | + assertEquals("incorrect permissions", PERMS, app.permissions()); | ||
52 | + assertEquals("incorrect features repo", FURL, app.featuresRepo().get()); | ||
53 | + assertEquals("incorrect features", FEATURES, app.features()); | ||
54 | + assertTrue("incorrect toString", app.toString().contains(APP_NAME)); | ||
55 | + } | ||
56 | + | ||
57 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.core; | ||
17 | + | ||
18 | +import java.util.Set; | ||
19 | + | ||
20 | +/** | ||
21 | + * Adapter for testing against app id store. | ||
22 | + */ | ||
23 | +public class ApplicationIdStoreAdapter implements ApplicationIdStore { | ||
24 | + @Override | ||
25 | + public Set<ApplicationId> getAppIds() { | ||
26 | + return null; | ||
27 | + } | ||
28 | + | ||
29 | + @Override | ||
30 | + public ApplicationId getAppId(Short id) { | ||
31 | + return null; | ||
32 | + } | ||
33 | + | ||
34 | + @Override | ||
35 | + public ApplicationId getAppId(String name) { | ||
36 | + return null; | ||
37 | + } | ||
38 | + | ||
39 | + @Override | ||
40 | + public ApplicationId registerApplication(String identifier) { | ||
41 | + return null; | ||
42 | + } | ||
43 | +} |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.core; | ||
17 | + | ||
18 | +import com.google.common.testing.EqualsTester; | ||
19 | +import org.junit.Test; | ||
20 | + | ||
21 | +import java.util.Optional; | ||
22 | + | ||
23 | +import static org.junit.Assert.assertEquals; | ||
24 | +import static org.junit.Assert.assertTrue; | ||
25 | +import static org.onosproject.app.DefaultApplicationDescriptionTest.*; | ||
26 | + | ||
27 | +/** | ||
28 | + * Basic tests of the default app descriptor. | ||
29 | + */ | ||
30 | +public class DefaultApplicationTest { | ||
31 | + | ||
32 | + public static final ApplicationId APP_ID = new DefaultApplicationId(2, APP_NAME); | ||
33 | + | ||
34 | + @Test | ||
35 | + public void basics() { | ||
36 | + Application app = new DefaultApplication(APP_ID, VER, DESC, ORIGIN, | ||
37 | + PERMS, Optional.of(FURL), FEATURES); | ||
38 | + assertEquals("incorrect id", APP_ID, app.id()); | ||
39 | + assertEquals("incorrect version", VER, app.version()); | ||
40 | + assertEquals("incorrect description", DESC, app.description()); | ||
41 | + assertEquals("incorrect origin", ORIGIN, app.origin()); | ||
42 | + assertEquals("incorrect permissions", PERMS, app.permissions()); | ||
43 | + assertEquals("incorrect features repo", FURL, app.featuresRepo().get()); | ||
44 | + assertEquals("incorrect features", FEATURES, app.features()); | ||
45 | + assertTrue("incorrect toString", app.toString().contains(APP_NAME)); | ||
46 | + } | ||
47 | + | ||
48 | + @Test | ||
49 | + public void testEquality() { | ||
50 | + Application a1 = new DefaultApplication(APP_ID, VER, DESC, ORIGIN, | ||
51 | + PERMS, Optional.of(FURL), FEATURES); | ||
52 | + Application a2 = new DefaultApplication(APP_ID, VER, DESC, ORIGIN, | ||
53 | + PERMS, Optional.of(FURL), FEATURES); | ||
54 | + Application a3 = new DefaultApplication(APP_ID, VER, DESC, ORIGIN, | ||
55 | + PERMS, Optional.empty(), FEATURES); | ||
56 | + Application a4 = new DefaultApplication(APP_ID, VER, DESC, ORIGIN + "asd", | ||
57 | + PERMS, Optional.of(FURL), FEATURES); | ||
58 | + new EqualsTester().addEqualityGroup(a1, a2) | ||
59 | + .addEqualityGroup(a3).addEqualityGroup(a4).testEquals(); | ||
60 | + } | ||
61 | + | ||
62 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.core; | ||
17 | + | ||
18 | +import org.onlab.junit.ExceptionTest; | ||
19 | + | ||
20 | +public class UnavailableIdExceptionTest extends ExceptionTest { | ||
21 | + | ||
22 | + @Override | ||
23 | + protected Exception getDefault() { | ||
24 | + return new UnavailableIdException(); | ||
25 | + } | ||
26 | + | ||
27 | + @Override | ||
28 | + protected Exception getWithMessage() { | ||
29 | + return new UnavailableIdException(MESSAGE); | ||
30 | + } | ||
31 | + | ||
32 | + @Override | ||
33 | + protected Exception getWithMessageAndCause() { | ||
34 | + return new UnavailableIdException(MESSAGE, CAUSE); | ||
35 | + } | ||
36 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -45,7 +45,7 @@ public class IntentOperationsTest { | ... | @@ -45,7 +45,7 @@ public class IntentOperationsTest { |
45 | final TrafficSelector selector = new IntentTestsMocks.MockSelector(); | 45 | final TrafficSelector selector = new IntentTestsMocks.MockSelector(); |
46 | final IntentTestsMocks.MockTreatment treatment = new IntentTestsMocks.MockTreatment(); | 46 | final IntentTestsMocks.MockTreatment treatment = new IntentTestsMocks.MockTreatment(); |
47 | 47 | ||
48 | - private final ApplicationId appId = new DefaultApplicationId((short) 1, "IntentOperationsTest"); | 48 | + private final ApplicationId appId = new DefaultApplicationId(1, "IntentOperationsTest"); |
49 | 49 | ||
50 | private Intent intent; | 50 | private Intent intent; |
51 | protected IdGenerator idGenerator = new MockIdGenerator(); | 51 | protected IdGenerator idGenerator = new MockIdGenerator(); | ... | ... |
... | @@ -26,16 +26,17 @@ | ... | @@ -26,16 +26,17 @@ |
26 | <relativePath>../pom.xml</relativePath> | 26 | <relativePath>../pom.xml</relativePath> |
27 | </parent> | 27 | </parent> |
28 | 28 | ||
29 | - <artifactId>onos-json</artifactId> | 29 | + <artifactId>onos-core-common</artifactId> |
30 | <packaging>bundle</packaging> | 30 | <packaging>bundle</packaging> |
31 | 31 | ||
32 | - <description>ONOS JSON encode/decode facilities</description> | 32 | + <description>ONOS utilities common to the core modules</description> |
33 | 33 | ||
34 | <dependencies> | 34 | <dependencies> |
35 | <dependency> | 35 | <dependency> |
36 | <groupId>org.onosproject</groupId> | 36 | <groupId>org.onosproject</groupId> |
37 | <artifactId>onos-api</artifactId> | 37 | <artifactId>onos-api</artifactId> |
38 | </dependency> | 38 | </dependency> |
39 | + | ||
39 | <dependency> | 40 | <dependency> |
40 | <groupId>org.onosproject</groupId> | 41 | <groupId>org.onosproject</groupId> |
41 | <artifactId>onos-api</artifactId> | 42 | <artifactId>onos-api</artifactId> |
... | @@ -44,13 +45,17 @@ | ... | @@ -44,13 +45,17 @@ |
44 | </dependency> | 45 | </dependency> |
45 | 46 | ||
46 | <dependency> | 47 | <dependency> |
47 | - <groupId>org.onosproject</groupId> | 48 | + <groupId>org.easymock</groupId> |
48 | - <artifactId>onos-core-trivial</artifactId> | 49 | + <artifactId>easymock</artifactId> |
49 | - <version>${project.version}</version> | ||
50 | <scope>test</scope> | 50 | <scope>test</scope> |
51 | </dependency> | 51 | </dependency> |
52 | 52 | ||
53 | <dependency> | 53 | <dependency> |
54 | + <groupId>org.osgi</groupId> | ||
55 | + <artifactId>org.osgi.compendium</artifactId> | ||
56 | + </dependency> | ||
57 | + | ||
58 | + <dependency> | ||
54 | <groupId>org.apache.felix</groupId> | 59 | <groupId>org.apache.felix</groupId> |
55 | <artifactId>org.apache.felix.scr.annotations</artifactId> | 60 | <artifactId>org.apache.felix.scr.annotations</artifactId> |
56 | </dependency> | 61 | </dependency> | ... | ... |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.common.app; | ||
17 | + | ||
18 | +import com.google.common.collect.ImmutableSet; | ||
19 | +import com.google.common.io.ByteStreams; | ||
20 | +import com.google.common.io.Files; | ||
21 | +import org.apache.commons.configuration.ConfigurationException; | ||
22 | +import org.apache.commons.configuration.XMLConfiguration; | ||
23 | +import org.onlab.util.Tools; | ||
24 | +import org.onosproject.app.ApplicationDescription; | ||
25 | +import org.onosproject.app.ApplicationEvent; | ||
26 | +import org.onosproject.app.ApplicationException; | ||
27 | +import org.onosproject.app.ApplicationStoreDelegate; | ||
28 | +import org.onosproject.app.DefaultApplicationDescription; | ||
29 | +import org.onosproject.core.Permission; | ||
30 | +import org.onosproject.core.Version; | ||
31 | +import org.onosproject.store.AbstractStore; | ||
32 | +import org.slf4j.Logger; | ||
33 | +import org.slf4j.LoggerFactory; | ||
34 | + | ||
35 | +import java.io.ByteArrayInputStream; | ||
36 | +import java.io.File; | ||
37 | +import java.io.FileInputStream; | ||
38 | +import java.io.FileNotFoundException; | ||
39 | +import java.io.IOException; | ||
40 | +import java.io.InputStream; | ||
41 | +import java.net.URI; | ||
42 | +import java.util.Set; | ||
43 | +import java.util.zip.ZipEntry; | ||
44 | +import java.util.zip.ZipInputStream; | ||
45 | + | ||
46 | +import static com.google.common.io.ByteStreams.toByteArray; | ||
47 | +import static com.google.common.io.Files.createParentDirs; | ||
48 | +import static com.google.common.io.Files.write; | ||
49 | + | ||
50 | +/** | ||
51 | + * Facility for reading application archive stream and managing application | ||
52 | + * directory structure. | ||
53 | + */ | ||
54 | +public class ApplicationArchive | ||
55 | + extends AbstractStore<ApplicationEvent, ApplicationStoreDelegate> { | ||
56 | + | ||
57 | + private static final String NAME = "[@name]"; | ||
58 | + private static final String ORIGIN = "[@origin]"; | ||
59 | + private static final String VERSION = "[@version]"; | ||
60 | + private static final String FEATURES_REPO = "[@featuresRepo]"; | ||
61 | + private static final String FEATURES = "[@features]"; | ||
62 | + private static final String DESCRIPTION = "description"; | ||
63 | + | ||
64 | + private static Logger log = LoggerFactory.getLogger(ApplicationArchive.class); | ||
65 | + private static final String APP_XML = "app.xml"; | ||
66 | + private static final String APPS_ROOT = "data/apps/"; | ||
67 | + | ||
68 | + private File appsDir = new File(APPS_ROOT); | ||
69 | + | ||
70 | + /** | ||
71 | + * Sets the root directory where application artifacts are kept. | ||
72 | + * | ||
73 | + * @param appsRoot top-level applications directory path | ||
74 | + */ | ||
75 | + protected void setAppsRoot(String appsRoot) { | ||
76 | + this.appsDir = new File(appsRoot); | ||
77 | + } | ||
78 | + | ||
79 | + /** | ||
80 | + * Returns the root directory where application artifacts are kept. | ||
81 | + * | ||
82 | + * @return top-level applications directory path | ||
83 | + */ | ||
84 | + protected String getAppsRoot() { | ||
85 | + return appsDir.getPath(); | ||
86 | + } | ||
87 | + | ||
88 | + /** | ||
89 | + * Returns the set of installed application names. | ||
90 | + * | ||
91 | + * @return installed application names | ||
92 | + */ | ||
93 | + public Set<String> getApplicationNames() { | ||
94 | + ImmutableSet.Builder<String> names = ImmutableSet.builder(); | ||
95 | + File[] files = appsDir.listFiles(File::isDirectory); | ||
96 | + if (files != null) { | ||
97 | + for (File file : files) { | ||
98 | + names.add(file.getName()); | ||
99 | + } | ||
100 | + } | ||
101 | + return names.build(); | ||
102 | + } | ||
103 | + | ||
104 | + /** | ||
105 | + * Loads the application descriptor from the specified application archive | ||
106 | + * stream and saves the stream in the appropriate application archive | ||
107 | + * directory. | ||
108 | + * | ||
109 | + * @param appName application name | ||
110 | + * @return application descriptor | ||
111 | + * @throws org.onosproject.app.ApplicationException if unable to read application description | ||
112 | + */ | ||
113 | + public ApplicationDescription getApplicationDescription(String appName) { | ||
114 | + try { | ||
115 | + return loadAppDescription(new XMLConfiguration(appFile(appName, APP_XML))); | ||
116 | + } catch (Exception e) { | ||
117 | + throw new ApplicationException("Unable to get app description", e); | ||
118 | + } | ||
119 | + } | ||
120 | + | ||
121 | + /** | ||
122 | + * Loads the application descriptor from the specified application archive | ||
123 | + * stream and saves the stream in the appropriate application archive | ||
124 | + * directory. | ||
125 | + * | ||
126 | + * @param stream application archive stream | ||
127 | + * @return application descriptor | ||
128 | + * @throws org.onosproject.app.ApplicationException if unable to read the | ||
129 | + * archive stream or store | ||
130 | + * the application archive | ||
131 | + */ | ||
132 | + public ApplicationDescription saveApplication(InputStream stream) { | ||
133 | + try (InputStream ais = stream) { | ||
134 | + byte[] cache = toByteArray(ais); | ||
135 | + InputStream bis = new ByteArrayInputStream(cache); | ||
136 | + ApplicationDescription desc = parseAppDescription(bis); | ||
137 | + bis.reset(); | ||
138 | + | ||
139 | + expandApplication(bis, desc); | ||
140 | + bis.reset(); | ||
141 | + | ||
142 | + saveApplication(bis, desc); | ||
143 | + installArtifacts(desc); | ||
144 | + return desc; | ||
145 | + } catch (IOException e) { | ||
146 | + throw new ApplicationException("Unable to save application", e); | ||
147 | + } | ||
148 | + } | ||
149 | + | ||
150 | + /** | ||
151 | + * Purges the application archive directory. | ||
152 | + * | ||
153 | + * @param appName application name | ||
154 | + */ | ||
155 | + public void purgeApplication(String appName) { | ||
156 | + try { | ||
157 | + Tools.removeDirectory(new File(appsDir, appName)); | ||
158 | + } catch (IOException e) { | ||
159 | + throw new ApplicationException("Unable to purge application " + appName, e); | ||
160 | + } | ||
161 | + } | ||
162 | + | ||
163 | + /** | ||
164 | + * Returns application archive stream for the specified application. | ||
165 | + * | ||
166 | + * @param appName application name | ||
167 | + * @return application archive stream | ||
168 | + */ | ||
169 | + public InputStream getApplicationInputStream(String appName) { | ||
170 | + try { | ||
171 | + return new FileInputStream(appFile(appName, appName + ".zip")); | ||
172 | + } catch (FileNotFoundException e) { | ||
173 | + throw new ApplicationException("Application " + appName + " not found"); | ||
174 | + } | ||
175 | + } | ||
176 | + | ||
177 | + // Scans the specified ZIP stream for app.xml entry and parses it producing | ||
178 | + // an application descriptor. | ||
179 | + private ApplicationDescription parseAppDescription(InputStream stream) | ||
180 | + throws IOException { | ||
181 | + try (ZipInputStream zis = new ZipInputStream(stream)) { | ||
182 | + ZipEntry entry; | ||
183 | + while ((entry = zis.getNextEntry()) != null) { | ||
184 | + if (entry.getName().equals(APP_XML)) { | ||
185 | + byte[] data = new byte[(int) entry.getSize()]; | ||
186 | + ByteStreams.readFully(zis, data); | ||
187 | + XMLConfiguration cfg = new XMLConfiguration(); | ||
188 | + try { | ||
189 | + cfg.load(new ByteArrayInputStream(data)); | ||
190 | + return loadAppDescription(cfg); | ||
191 | + } catch (ConfigurationException e) { | ||
192 | + throw new IOException("Unable to parse " + APP_XML, e); | ||
193 | + } | ||
194 | + } | ||
195 | + zis.closeEntry(); | ||
196 | + } | ||
197 | + } | ||
198 | + throw new IOException("Unable to locate " + APP_XML); | ||
199 | + } | ||
200 | + | ||
201 | + private ApplicationDescription loadAppDescription(XMLConfiguration cfg) { | ||
202 | + cfg.setAttributeSplittingDisabled(true); | ||
203 | + String name = cfg.getString(NAME); | ||
204 | + Version version = Version.version(cfg.getString(VERSION)); | ||
205 | + String desc = cfg.getString(DESCRIPTION); | ||
206 | + String origin = cfg.getString(ORIGIN); | ||
207 | + Set<Permission> perms = ImmutableSet.of(); | ||
208 | + String featRepo = cfg.getString(FEATURES_REPO); | ||
209 | + URI featuresRepo = featRepo != null ? URI.create(featRepo) : null; | ||
210 | + Set<String> features = ImmutableSet.copyOf(cfg.getString(FEATURES).split(",")); | ||
211 | + | ||
212 | + return new DefaultApplicationDescription(name, version, desc, origin, | ||
213 | + perms, featuresRepo, features); | ||
214 | + } | ||
215 | + | ||
216 | + // Expands the specified ZIP stream into app-specific directory. | ||
217 | + private void expandApplication(InputStream stream, ApplicationDescription desc) | ||
218 | + throws IOException { | ||
219 | + ZipInputStream zis = new ZipInputStream(stream); | ||
220 | + ZipEntry entry; | ||
221 | + File appDir = new File(appsDir, desc.name()); | ||
222 | + while ((entry = zis.getNextEntry()) != null) { | ||
223 | + byte[] data = new byte[(int) entry.getSize()]; | ||
224 | + ByteStreams.readFully(zis, data); | ||
225 | + zis.closeEntry(); | ||
226 | + | ||
227 | + File file = new File(appDir, entry.getName()); | ||
228 | + createParentDirs(file); | ||
229 | + write(data, file); | ||
230 | + } | ||
231 | + zis.close(); | ||
232 | + } | ||
233 | + | ||
234 | + // Saves the specified ZIP stream into a file under app-specific directory. | ||
235 | + private void saveApplication(InputStream stream, ApplicationDescription desc) | ||
236 | + throws IOException { | ||
237 | + Files.write(toByteArray(stream), appFile(desc.name(), desc.name() + ".zip")); | ||
238 | + } | ||
239 | + | ||
240 | + // Installs application artifacts into M2 repository. | ||
241 | + private void installArtifacts(ApplicationDescription desc) { | ||
242 | + // FIXME: implement M2 repository copy | ||
243 | + } | ||
244 | + | ||
245 | + protected boolean setActive(String appName) { | ||
246 | + try { | ||
247 | + return appFile(appName, "active").createNewFile(); | ||
248 | + } catch (IOException e) { | ||
249 | + throw new ApplicationException("Unable to mark app as active", e); | ||
250 | + } | ||
251 | + } | ||
252 | + | ||
253 | + protected boolean clearActive(String appName) { | ||
254 | + return appFile(appName, "active").delete(); | ||
255 | + } | ||
256 | + | ||
257 | + protected boolean isActive(String appName) { | ||
258 | + return appFile(appName, "active").exists(); | ||
259 | + } | ||
260 | + | ||
261 | + | ||
262 | + // Returns the name of the file located under the specified app directory. | ||
263 | + private File appFile(String appName, String fileName) { | ||
264 | + return new File(new File(appsDir, appName), fileName); | ||
265 | + } | ||
266 | + | ||
267 | +} |
1 | /* | 1 | /* |
2 | - * Copyright 2014 Open Networking Laboratory | 2 | + * Copyright 2015 Open Networking Laboratory |
3 | * | 3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
... | @@ -13,10 +13,8 @@ | ... | @@ -13,10 +13,8 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.json.impl; | ||
17 | 16 | ||
18 | /** | 17 | /** |
19 | - * Created by tom on 10/16/14. | 18 | + * Common facilities for construction of application management subsystem. |
20 | */ | 19 | */ |
21 | -public class DeleteMe { | 20 | +package org.onosproject.common.app; |
22 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.common.app; | ||
17 | + | ||
18 | +import com.google.common.collect.ImmutableSet; | ||
19 | +import com.google.common.io.ByteStreams; | ||
20 | +import org.junit.Before; | ||
21 | +import org.junit.Test; | ||
22 | +import org.onosproject.app.ApplicationDescription; | ||
23 | +import org.onosproject.app.ApplicationException; | ||
24 | + | ||
25 | +import java.io.IOException; | ||
26 | +import java.io.InputStream; | ||
27 | +import java.util.Set; | ||
28 | + | ||
29 | +import static org.junit.Assert.assertArrayEquals; | ||
30 | +import static org.junit.Assert.assertEquals; | ||
31 | +import static org.onosproject.app.DefaultApplicationDescriptionTest.*; | ||
32 | + | ||
33 | +public class ApplicationArchiveTest { | ||
34 | + | ||
35 | + static final String ROOT = "/tmp/app-junit"; | ||
36 | + | ||
37 | + private ApplicationArchive aar = new ApplicationArchive(); | ||
38 | + | ||
39 | + @Before | ||
40 | + public void setUp() { | ||
41 | + aar.setAppsRoot(ROOT); | ||
42 | + } | ||
43 | + | ||
44 | + private void validate(ApplicationDescription app) { | ||
45 | + assertEquals("incorrect name", APP_NAME, app.name()); | ||
46 | + assertEquals("incorrect version", VER, app.version()); | ||
47 | + assertEquals("incorrect origin", ORIGIN, app.origin()); | ||
48 | + | ||
49 | + assertEquals("incorrect description", DESC, app.description()); | ||
50 | + assertEquals("incorrect features URI", FURL, app.featuresRepo().get()); | ||
51 | + assertEquals("incorrect permissions", PERMS, app.permissions()); | ||
52 | + assertEquals("incorrect features", FEATURES, app.features()); | ||
53 | + } | ||
54 | + | ||
55 | + @Test | ||
56 | + public void saveApp() throws IOException { | ||
57 | + InputStream stream = getClass().getResourceAsStream("app.zip"); | ||
58 | + ApplicationDescription app = aar.saveApplication(stream); | ||
59 | + validate(app); | ||
60 | + } | ||
61 | + | ||
62 | + @Test | ||
63 | + public void loadApp() throws IOException { | ||
64 | + saveApp(); | ||
65 | + ApplicationDescription app = aar.getApplicationDescription(APP_NAME); | ||
66 | + validate(app); | ||
67 | + } | ||
68 | + | ||
69 | + @Test | ||
70 | + public void getAppNames() throws IOException { | ||
71 | + saveApp(); | ||
72 | + Set<String> names = aar.getApplicationNames(); | ||
73 | + assertEquals("incorrect names", ImmutableSet.of(APP_NAME), names); | ||
74 | + } | ||
75 | + | ||
76 | + @Test | ||
77 | + public void purgeApp() throws IOException { | ||
78 | + saveApp(); | ||
79 | + aar.purgeApplication(APP_NAME); | ||
80 | + assertEquals("incorrect names", ImmutableSet.of(), aar.getApplicationNames()); | ||
81 | + } | ||
82 | + | ||
83 | + @Test | ||
84 | + public void getAppStream() throws IOException { | ||
85 | + saveApp(); | ||
86 | + InputStream stream = aar.getApplicationInputStream(APP_NAME); | ||
87 | + byte[] orig = ByteStreams.toByteArray(getClass().getResourceAsStream("app.zip")); | ||
88 | + byte[] loaded = ByteStreams.toByteArray(stream); | ||
89 | + assertArrayEquals("incorrect stream", orig, loaded); | ||
90 | + } | ||
91 | + | ||
92 | + @Test(expected = ApplicationException.class) | ||
93 | + public void getBadAppDesc() throws IOException { | ||
94 | + aar.getApplicationDescription("org.foo.BAD"); | ||
95 | + } | ||
96 | + | ||
97 | + @Test(expected = ApplicationException.class) | ||
98 | + public void getBadAppStream() throws IOException { | ||
99 | + aar.getApplicationInputStream("org.foo.BAD"); | ||
100 | + } | ||
101 | + | ||
102 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +<!-- | ||
2 | + ~ Copyright 2015 Open Networking Laboratory | ||
3 | + ~ | ||
4 | + ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + ~ you may not use this file except in compliance with the License. | ||
6 | + ~ You may obtain a copy of the License at | ||
7 | + ~ | ||
8 | + ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + ~ | ||
10 | + ~ Unless required by applicable law or agreed to in writing, software | ||
11 | + ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + ~ See the License for the specific language governing permissions and | ||
14 | + ~ limitations under the License. | ||
15 | + --> | ||
16 | +<app name="org.foo.app" origin="Circus" version="1.2.a" | ||
17 | + featuresRepo="mvn:org.foo-features/1.2a/xml/features" | ||
18 | + features="foo,bar"> | ||
19 | + <description>Awesome application from Circus, Inc.</description> | ||
20 | +</app> |
No preview for this file type
... | @@ -52,6 +52,14 @@ | ... | @@ -52,6 +52,14 @@ |
52 | </dependency> | 52 | </dependency> |
53 | 53 | ||
54 | <dependency> | 54 | <dependency> |
55 | + <groupId>org.onosproject</groupId> | ||
56 | + <artifactId>onos-core-common</artifactId> | ||
57 | + <version>${project.version}</version> | ||
58 | + <classifier>tests</classifier> | ||
59 | + <scope>test</scope> | ||
60 | + </dependency> | ||
61 | + | ||
62 | + <dependency> | ||
55 | <groupId>org.easymock</groupId> | 63 | <groupId>org.easymock</groupId> |
56 | <artifactId>easymock</artifactId> | 64 | <artifactId>easymock</artifactId> |
57 | <scope>test</scope> | 65 | <scope>test</scope> |
... | @@ -66,6 +74,12 @@ | ... | @@ -66,6 +74,12 @@ |
66 | <groupId>org.apache.felix</groupId> | 74 | <groupId>org.apache.felix</groupId> |
67 | <artifactId>org.apache.felix.scr.annotations</artifactId> | 75 | <artifactId>org.apache.felix.scr.annotations</artifactId> |
68 | </dependency> | 76 | </dependency> |
77 | + | ||
78 | + <dependency> | ||
79 | + <groupId>org.apache.karaf.features</groupId> | ||
80 | + <artifactId>org.apache.karaf.features.core</artifactId> | ||
81 | + <version>3.0.2</version> | ||
82 | + </dependency> | ||
69 | </dependencies> | 83 | </dependencies> |
70 | 84 | ||
71 | <build> | 85 | <build> | ... | ... |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.app.impl; | ||
17 | + | ||
18 | +import org.apache.felix.scr.annotations.Activate; | ||
19 | +import org.apache.felix.scr.annotations.Component; | ||
20 | +import org.apache.felix.scr.annotations.Deactivate; | ||
21 | +import org.apache.felix.scr.annotations.Reference; | ||
22 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
23 | +import org.apache.felix.scr.annotations.Service; | ||
24 | +import org.apache.karaf.features.FeaturesService; | ||
25 | +import org.onosproject.app.ApplicationAdminService; | ||
26 | +import org.onosproject.app.ApplicationEvent; | ||
27 | +import org.onosproject.app.ApplicationListener; | ||
28 | +import org.onosproject.app.ApplicationService; | ||
29 | +import org.onosproject.app.ApplicationState; | ||
30 | +import org.onosproject.app.ApplicationStore; | ||
31 | +import org.onosproject.app.ApplicationStoreDelegate; | ||
32 | +import org.onosproject.core.Application; | ||
33 | +import org.onosproject.core.ApplicationId; | ||
34 | +import org.onosproject.core.Permission; | ||
35 | +import org.onosproject.event.AbstractListenerRegistry; | ||
36 | +import org.onosproject.event.EventDeliveryService; | ||
37 | +import org.slf4j.Logger; | ||
38 | + | ||
39 | +import java.io.InputStream; | ||
40 | +import java.util.Set; | ||
41 | + | ||
42 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
43 | +import static org.onosproject.app.ApplicationEvent.Type.*; | ||
44 | +import static org.slf4j.LoggerFactory.getLogger; | ||
45 | + | ||
46 | +/** | ||
47 | + * Implementation of the application management service. | ||
48 | + */ | ||
49 | +@Component(immediate = true) | ||
50 | +@Service | ||
51 | +public class ApplicationManager implements ApplicationService, ApplicationAdminService { | ||
52 | + | ||
53 | + private final Logger log = getLogger(getClass()); | ||
54 | + | ||
55 | + private static final String APP_ID_NULL = "Application ID cannot be null"; | ||
56 | + | ||
57 | + protected final AbstractListenerRegistry<ApplicationEvent, ApplicationListener> | ||
58 | + listenerRegistry = new AbstractListenerRegistry<>(); | ||
59 | + | ||
60 | + private final ApplicationStoreDelegate delegate = new InternalStoreDelegate(); | ||
61 | + | ||
62 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
63 | + protected ApplicationStore store; | ||
64 | + | ||
65 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
66 | + protected FeaturesService featuresService; | ||
67 | + | ||
68 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
69 | + protected EventDeliveryService eventDispatcher; | ||
70 | + | ||
71 | + @Activate | ||
72 | + public void activate() { | ||
73 | + store.setDelegate(delegate); | ||
74 | + eventDispatcher.addSink(ApplicationEvent.class, listenerRegistry); | ||
75 | + log.info("Started"); | ||
76 | + } | ||
77 | + | ||
78 | + @Deactivate | ||
79 | + public void deactivate() { | ||
80 | + store.unsetDelegate(delegate); | ||
81 | + eventDispatcher.removeSink(ApplicationEvent.class); | ||
82 | + log.info("Stopped"); | ||
83 | + } | ||
84 | + | ||
85 | + @Override | ||
86 | + public Set<Application> getApplications() { | ||
87 | + return store.getApplications(); | ||
88 | + } | ||
89 | + | ||
90 | + @Override | ||
91 | + public ApplicationId getId(String name) { | ||
92 | + checkNotNull(name, "Name cannot be null"); | ||
93 | + return store.getId(name); | ||
94 | + } | ||
95 | + | ||
96 | + @Override | ||
97 | + public Application getApplication(ApplicationId appId) { | ||
98 | + checkNotNull(appId, APP_ID_NULL); | ||
99 | + return store.getApplication(appId); | ||
100 | + } | ||
101 | + | ||
102 | + @Override | ||
103 | + public ApplicationState getState(ApplicationId appId) { | ||
104 | + checkNotNull(appId, APP_ID_NULL); | ||
105 | + return store.getState(appId); | ||
106 | + } | ||
107 | + | ||
108 | + @Override | ||
109 | + public Set<Permission> getPermissions(ApplicationId appId) { | ||
110 | + checkNotNull(appId, APP_ID_NULL); | ||
111 | + return store.getPermissions(appId); | ||
112 | + } | ||
113 | + | ||
114 | + @Override | ||
115 | + public Application install(InputStream appDescStream) { | ||
116 | + checkNotNull(appDescStream, "Application archive stream cannot be null"); | ||
117 | + return store.create(appDescStream); | ||
118 | + } | ||
119 | + | ||
120 | + @Override | ||
121 | + public void uninstall(ApplicationId appId) { | ||
122 | + checkNotNull(appId, APP_ID_NULL); | ||
123 | + try { | ||
124 | + store.remove(appId); | ||
125 | + } catch (Exception e) { | ||
126 | + log.warn("Unable to purge application directory for {}", appId.name()); | ||
127 | + } | ||
128 | + } | ||
129 | + | ||
130 | + @Override | ||
131 | + public void activate(ApplicationId appId) { | ||
132 | + checkNotNull(appId, APP_ID_NULL); | ||
133 | + store.activate(appId); | ||
134 | + } | ||
135 | + | ||
136 | + @Override | ||
137 | + public void deactivate(ApplicationId appId) { | ||
138 | + checkNotNull(appId, APP_ID_NULL); | ||
139 | + store.deactivate(appId); | ||
140 | + } | ||
141 | + | ||
142 | + @Override | ||
143 | + public void setPermissions(ApplicationId appId, Set<Permission> permissions) { | ||
144 | + checkNotNull(appId, APP_ID_NULL); | ||
145 | + checkNotNull(permissions, "Permissions cannot be null"); | ||
146 | + store.setPermissions(appId, permissions); | ||
147 | + } | ||
148 | + | ||
149 | + @Override | ||
150 | + public void addListener(ApplicationListener listener) { | ||
151 | + listenerRegistry.addListener(listener); | ||
152 | + } | ||
153 | + | ||
154 | + @Override | ||
155 | + public void removeListener(ApplicationListener listener) { | ||
156 | + listenerRegistry.removeListener(listener); | ||
157 | + } | ||
158 | + | ||
159 | + private class InternalStoreDelegate implements ApplicationStoreDelegate { | ||
160 | + @Override | ||
161 | + public void notify(ApplicationEvent event) { | ||
162 | + ApplicationEvent.Type type = event.type(); | ||
163 | + Application app = event.subject(); | ||
164 | + try { | ||
165 | + if (type == APP_ACTIVATED) { | ||
166 | + installAppFeatures(app); | ||
167 | + log.info("Application {} has been activated", app.id().name()); | ||
168 | + | ||
169 | + } else if (type == APP_DEACTIVATED) { | ||
170 | + uninstallAppFeatures(app); | ||
171 | + log.info("Application {} has been deactivated", app.id().name()); | ||
172 | + | ||
173 | + } else if (type == APP_INSTALLED) { | ||
174 | + installAppArtifacts(app); | ||
175 | + log.info("Application {} has been installed", app.id().name()); | ||
176 | + | ||
177 | + } else if (type == APP_UNINSTALLED) { | ||
178 | + uninstallAppFeatures(app); | ||
179 | + uninstallAppArtifacts(app); | ||
180 | + log.info("Application {} has been uninstalled", app.id().name()); | ||
181 | + | ||
182 | + } | ||
183 | + eventDispatcher.post(event); | ||
184 | + | ||
185 | + } catch (Exception e) { | ||
186 | + log.warn("Unable to perform operation on application " + app.id().name(), e); | ||
187 | + } | ||
188 | + } | ||
189 | + } | ||
190 | + | ||
191 | + private void installAppArtifacts(Application app) throws Exception { | ||
192 | + if (app.featuresRepo().isPresent()) { | ||
193 | + featuresService.addRepository(app.featuresRepo().get()); | ||
194 | + } | ||
195 | + } | ||
196 | + | ||
197 | + private void uninstallAppArtifacts(Application app) throws Exception { | ||
198 | + if (app.featuresRepo().isPresent()) { | ||
199 | + featuresService.removeRepository(app.featuresRepo().get()); | ||
200 | + } | ||
201 | + } | ||
202 | + | ||
203 | + private void installAppFeatures(Application app) throws Exception { | ||
204 | + for (String name : app.features()) { | ||
205 | + featuresService.installFeature(name); | ||
206 | + } | ||
207 | + } | ||
208 | + | ||
209 | + private void uninstallAppFeatures(Application app) throws Exception { | ||
210 | + for (String name : app.features()) { | ||
211 | + featuresService.uninstallFeature(name); | ||
212 | + } | ||
213 | + } | ||
214 | + | ||
215 | +} |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +/** | ||
18 | + * Subsystem for managing applications. | ||
19 | + */ | ||
20 | +package org.onosproject.app.impl; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.app.impl; | ||
17 | + | ||
18 | +import com.google.common.collect.ImmutableSet; | ||
19 | +import org.junit.After; | ||
20 | +import org.junit.Before; | ||
21 | +import org.junit.Test; | ||
22 | +import org.onosproject.app.ApplicationEvent; | ||
23 | +import org.onosproject.app.ApplicationListener; | ||
24 | +import org.onosproject.app.ApplicationState; | ||
25 | +import org.onosproject.app.ApplicationStoreAdapter; | ||
26 | +import org.onosproject.common.app.ApplicationArchive; | ||
27 | +import org.onosproject.core.Application; | ||
28 | +import org.onosproject.core.ApplicationId; | ||
29 | +import org.onosproject.core.DefaultApplication; | ||
30 | +import org.onosproject.core.DefaultApplicationId; | ||
31 | +import org.onosproject.event.impl.TestEventDispatcher; | ||
32 | + | ||
33 | +import java.io.InputStream; | ||
34 | +import java.net.URI; | ||
35 | +import java.util.HashSet; | ||
36 | +import java.util.Optional; | ||
37 | +import java.util.Set; | ||
38 | + | ||
39 | +import static org.junit.Assert.assertEquals; | ||
40 | +import static org.onosproject.app.ApplicationEvent.Type.*; | ||
41 | +import static org.onosproject.app.ApplicationState.ACTIVE; | ||
42 | +import static org.onosproject.app.ApplicationState.INSTALLED; | ||
43 | +import static org.onosproject.app.DefaultApplicationDescriptionTest.*; | ||
44 | + | ||
45 | +/** | ||
46 | + * Test of the application manager implementation. | ||
47 | + */ | ||
48 | +public class ApplicationManagerTest { | ||
49 | + | ||
50 | + public static final DefaultApplicationId APP_ID = new DefaultApplicationId(1, APP_NAME); | ||
51 | + | ||
52 | + private ApplicationManager mgr = new ApplicationManager(); | ||
53 | + private ApplicationListener listener = new TestListener(); | ||
54 | + | ||
55 | + @Before | ||
56 | + public void setUp() { | ||
57 | + mgr.eventDispatcher = new TestEventDispatcher(); | ||
58 | + mgr.featuresService = new TestFeaturesService(); | ||
59 | + mgr.store = new TestStore(); | ||
60 | + mgr.activate(); | ||
61 | + mgr.addListener(listener); | ||
62 | + } | ||
63 | + | ||
64 | + @After | ||
65 | + public void tearDown() { | ||
66 | + mgr.removeListener(listener); | ||
67 | + mgr.deactivate(); | ||
68 | + } | ||
69 | + | ||
70 | + private void validate(Application app) { | ||
71 | + assertEquals("incorrect name", APP_NAME, app.id().name()); | ||
72 | + assertEquals("incorrect version", VER, app.version()); | ||
73 | + assertEquals("incorrect origin", ORIGIN, app.origin()); | ||
74 | + | ||
75 | + assertEquals("incorrect description", DESC, app.description()); | ||
76 | + assertEquals("incorrect features URI", FURL, app.featuresRepo().get()); | ||
77 | + assertEquals("incorrect features", FEATURES, app.features()); | ||
78 | + } | ||
79 | + | ||
80 | + @Test | ||
81 | + public void install() { | ||
82 | + InputStream stream = ApplicationArchive.class.getResourceAsStream("app.zip"); | ||
83 | + Application app = mgr.install(stream); | ||
84 | + validate(app); | ||
85 | + assertEquals("incorrect features URI used", app.featuresRepo().get(), | ||
86 | + ((TestFeaturesService) mgr.featuresService).uri); | ||
87 | + assertEquals("incorrect app count", 1, mgr.getApplications().size()); | ||
88 | + assertEquals("incorrect app", app, mgr.getApplication(APP_ID)); | ||
89 | + assertEquals("incorrect app state", INSTALLED, mgr.getState(APP_ID)); | ||
90 | + } | ||
91 | + | ||
92 | + @Test | ||
93 | + public void uninstall() { | ||
94 | + install(); | ||
95 | + mgr.uninstall(APP_ID); | ||
96 | + assertEquals("incorrect app count", 0, mgr.getApplications().size()); | ||
97 | + } | ||
98 | + | ||
99 | + @Test | ||
100 | + public void activate() { | ||
101 | + install(); | ||
102 | + mgr.activate(APP_ID); | ||
103 | + assertEquals("incorrect app state", ACTIVE, mgr.getState(APP_ID)); | ||
104 | + } | ||
105 | + | ||
106 | + @Test | ||
107 | + public void deactivate() { | ||
108 | + activate(); | ||
109 | + mgr.deactivate(APP_ID); | ||
110 | + assertEquals("incorrect app state", INSTALLED, mgr.getState(APP_ID)); | ||
111 | + } | ||
112 | + | ||
113 | + | ||
114 | + private class TestListener implements ApplicationListener { | ||
115 | + private ApplicationEvent event; | ||
116 | + | ||
117 | + @Override | ||
118 | + public void event(ApplicationEvent event) { | ||
119 | + this.event = event; | ||
120 | + } | ||
121 | + } | ||
122 | + | ||
123 | + private class TestStore extends ApplicationStoreAdapter { | ||
124 | + | ||
125 | + private Application app; | ||
126 | + private ApplicationState state; | ||
127 | + | ||
128 | + @Override | ||
129 | + public Application create(InputStream appDescStream) { | ||
130 | + app = new DefaultApplication(APP_ID, VER, DESC, ORIGIN, PERMS, | ||
131 | + Optional.of(FURL), FEATURES); | ||
132 | + state = INSTALLED; | ||
133 | + delegate.notify(new ApplicationEvent(APP_INSTALLED, app)); | ||
134 | + return app; | ||
135 | + } | ||
136 | + | ||
137 | + @Override | ||
138 | + public Set<Application> getApplications() { | ||
139 | + return app != null ? ImmutableSet.of(app) : ImmutableSet.of(); | ||
140 | + } | ||
141 | + | ||
142 | + @Override | ||
143 | + public Application getApplication(ApplicationId appId) { | ||
144 | + return app; | ||
145 | + } | ||
146 | + | ||
147 | + @Override | ||
148 | + public void remove(ApplicationId appId) { | ||
149 | + delegate.notify(new ApplicationEvent(APP_UNINSTALLED, app)); | ||
150 | + app = null; | ||
151 | + state = null; | ||
152 | + } | ||
153 | + | ||
154 | + @Override | ||
155 | + public ApplicationState getState(ApplicationId appId) { | ||
156 | + return state; | ||
157 | + } | ||
158 | + | ||
159 | + @Override | ||
160 | + public void activate(ApplicationId appId) { | ||
161 | + state = ApplicationState.ACTIVE; | ||
162 | + delegate.notify(new ApplicationEvent(APP_ACTIVATED, app)); | ||
163 | + } | ||
164 | + | ||
165 | + @Override | ||
166 | + public void deactivate(ApplicationId appId) { | ||
167 | + state = INSTALLED; | ||
168 | + delegate.notify(new ApplicationEvent(APP_DEACTIVATED, app)); | ||
169 | + } | ||
170 | + } | ||
171 | + | ||
172 | + private class TestFeaturesService extends FeaturesServiceAdapter { | ||
173 | + private URI uri; | ||
174 | + private Set<String> features = new HashSet<>(); | ||
175 | + | ||
176 | + @Override | ||
177 | + public void addRepository(URI uri) throws Exception { | ||
178 | + this.uri = uri; | ||
179 | + } | ||
180 | + | ||
181 | + @Override | ||
182 | + public void removeRepository(URI uri) throws Exception { | ||
183 | + this.uri = null; | ||
184 | + } | ||
185 | + | ||
186 | + @Override | ||
187 | + public void installFeature(String name) throws Exception { | ||
188 | + features.add(name); | ||
189 | + } | ||
190 | + | ||
191 | + @Override | ||
192 | + public void uninstallFeature(String name) throws Exception { | ||
193 | + features.remove(name); | ||
194 | + } | ||
195 | + } | ||
196 | + | ||
197 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.app.impl; | ||
17 | + | ||
18 | +import org.apache.karaf.features.Feature; | ||
19 | +import org.apache.karaf.features.Repository; | ||
20 | + | ||
21 | +import java.net.URI; | ||
22 | +import java.util.EnumSet; | ||
23 | +import java.util.Set; | ||
24 | + | ||
25 | +/** | ||
26 | + * Adapter for testing against Apache Karaf feature service. | ||
27 | + */ | ||
28 | +public class FeaturesServiceAdapter implements org.apache.karaf.features.FeaturesService { | ||
29 | + @Override | ||
30 | + public void validateRepository(URI uri) throws Exception { | ||
31 | + | ||
32 | + } | ||
33 | + | ||
34 | + @Override | ||
35 | + public void addRepository(URI uri) throws Exception { | ||
36 | + | ||
37 | + } | ||
38 | + | ||
39 | + @Override | ||
40 | + public void addRepository(URI uri, boolean install) throws Exception { | ||
41 | + | ||
42 | + } | ||
43 | + | ||
44 | + @Override | ||
45 | + public void removeRepository(URI uri) throws Exception { | ||
46 | + | ||
47 | + } | ||
48 | + | ||
49 | + @Override | ||
50 | + public void removeRepository(URI uri, boolean uninstall) throws Exception { | ||
51 | + | ||
52 | + } | ||
53 | + | ||
54 | + @Override | ||
55 | + public void restoreRepository(URI uri) throws Exception { | ||
56 | + | ||
57 | + } | ||
58 | + | ||
59 | + @Override | ||
60 | + public Repository[] listRepositories() { | ||
61 | + return new Repository[0]; | ||
62 | + } | ||
63 | + | ||
64 | + @Override | ||
65 | + public Repository getRepository(String repoName) { | ||
66 | + return null; | ||
67 | + } | ||
68 | + | ||
69 | + @Override | ||
70 | + public void installFeature(String name) throws Exception { | ||
71 | + | ||
72 | + } | ||
73 | + | ||
74 | + @Override | ||
75 | + public void installFeature(String name, EnumSet<Option> options) throws Exception { | ||
76 | + | ||
77 | + } | ||
78 | + | ||
79 | + @Override | ||
80 | + public void installFeature(String name, String version) throws Exception { | ||
81 | + | ||
82 | + } | ||
83 | + | ||
84 | + @Override | ||
85 | + public void installFeature(String name, String version, EnumSet<Option> options) throws Exception { | ||
86 | + | ||
87 | + } | ||
88 | + | ||
89 | + @Override | ||
90 | + public void installFeature(Feature f, EnumSet<Option> options) throws Exception { | ||
91 | + | ||
92 | + } | ||
93 | + | ||
94 | + @Override | ||
95 | + public void installFeatures(Set<Feature> features, EnumSet<Option> options) throws Exception { | ||
96 | + | ||
97 | + } | ||
98 | + | ||
99 | + @Override | ||
100 | + public void uninstallFeature(String name, EnumSet<Option> options) throws Exception { | ||
101 | + | ||
102 | + } | ||
103 | + | ||
104 | + @Override | ||
105 | + public void uninstallFeature(String name) throws Exception { | ||
106 | + | ||
107 | + } | ||
108 | + | ||
109 | + @Override | ||
110 | + public void uninstallFeature(String name, String version, EnumSet<Option> options) throws Exception { | ||
111 | + | ||
112 | + } | ||
113 | + | ||
114 | + @Override | ||
115 | + public void uninstallFeature(String name, String version) throws Exception { | ||
116 | + | ||
117 | + } | ||
118 | + | ||
119 | + @Override | ||
120 | + public Feature[] listFeatures() throws Exception { | ||
121 | + return new Feature[0]; | ||
122 | + } | ||
123 | + | ||
124 | + @Override | ||
125 | + public Feature[] listInstalledFeatures() { | ||
126 | + return new Feature[0]; | ||
127 | + } | ||
128 | + | ||
129 | + @Override | ||
130 | + public boolean isInstalled(Feature f) { | ||
131 | + return false; | ||
132 | + } | ||
133 | + | ||
134 | + @Override | ||
135 | + public Feature getFeature(String name, String version) throws Exception { | ||
136 | + return null; | ||
137 | + } | ||
138 | + | ||
139 | + @Override | ||
140 | + public Feature getFeature(String name) throws Exception { | ||
141 | + return null; | ||
142 | + } | ||
143 | + | ||
144 | + @Override | ||
145 | + public void refreshRepository(URI uri) throws Exception { | ||
146 | + | ||
147 | + } | ||
148 | +} |
... | @@ -110,7 +110,7 @@ public class FlowRuleManagerTest { | ... | @@ -110,7 +110,7 @@ public class FlowRuleManagerTest { |
110 | mgr.addListener(listener); | 110 | mgr.addListener(listener); |
111 | provider = new TestProvider(PID); | 111 | provider = new TestProvider(PID); |
112 | providerService = registry.register(provider); | 112 | providerService = registry.register(provider); |
113 | - appId = new TestApplicationId((short) 0, "FlowRuleManagerTest"); | 113 | + appId = new TestApplicationId(0, "FlowRuleManagerTest"); |
114 | assertTrue("provider should be registered", | 114 | assertTrue("provider should be registered", |
115 | registry.getProviders().contains(provider.id())); | 115 | registry.getProviders().contains(provider.id())); |
116 | } | 116 | } |
... | @@ -639,8 +639,7 @@ public class FlowRuleManagerTest { | ... | @@ -639,8 +639,7 @@ public class FlowRuleManagerTest { |
639 | } | 639 | } |
640 | 640 | ||
641 | public class TestApplicationId extends DefaultApplicationId { | 641 | public class TestApplicationId extends DefaultApplicationId { |
642 | - | 642 | + public TestApplicationId(int id, String name) { |
643 | - public TestApplicationId(short id, String name) { | ||
644 | super(id, name); | 643 | super(id, name); |
645 | } | 644 | } |
646 | } | 645 | } | ... | ... |
... | @@ -33,9 +33,9 @@ | ... | @@ -33,9 +33,9 @@ |
33 | 33 | ||
34 | <modules> | 34 | <modules> |
35 | <module>api</module> | 35 | <module>api</module> |
36 | + <module>common</module> | ||
36 | <module>net</module> | 37 | <module>net</module> |
37 | <module>store</module> | 38 | <module>store</module> |
38 | - <module>json</module> | ||
39 | </modules> | 39 | </modules> |
40 | 40 | ||
41 | <dependencies> | 41 | <dependencies> | ... | ... |
... | @@ -103,6 +103,11 @@ public class DistributedApplicationIdStore | ... | @@ -103,6 +103,11 @@ public class DistributedApplicationIdStore |
103 | return appId; | 103 | return appId; |
104 | } | 104 | } |
105 | 105 | ||
106 | + @Override | ||
107 | + public ApplicationId getAppId(String name) { | ||
108 | + return appIdsByName.get(name); | ||
109 | + } | ||
110 | + | ||
106 | private void primeAppIds() { | 111 | private void primeAppIds() { |
107 | for (DefaultApplicationId appId : appIdsByName.values()) { | 112 | for (DefaultApplicationId appId : appIdsByName.values()) { |
108 | appIds.put(appId.id(), appId); | 113 | appIds.put(appId.id(), appId); |
... | @@ -113,7 +118,7 @@ public class DistributedApplicationIdStore | ... | @@ -113,7 +118,7 @@ public class DistributedApplicationIdStore |
113 | public ApplicationId registerApplication(String name) { | 118 | public ApplicationId registerApplication(String name) { |
114 | DefaultApplicationId appId = appIdsByName.get(name); | 119 | DefaultApplicationId appId = appIdsByName.get(name); |
115 | if (appId == null) { | 120 | if (appId == null) { |
116 | - short id = (short) lastAppId.getAndIncrement(); | 121 | + int id = (int) lastAppId.getAndIncrement(); |
117 | appId = putIfAbsent(appIdsByName, name, | 122 | appId = putIfAbsent(appIdsByName, name, |
118 | new DefaultApplicationId(id, name)); | 123 | new DefaultApplicationId(id, name)); |
119 | } | 124 | } | ... | ... |
... | @@ -44,6 +44,14 @@ | ... | @@ -44,6 +44,14 @@ |
44 | </dependency> | 44 | </dependency> |
45 | 45 | ||
46 | <dependency> | 46 | <dependency> |
47 | + <groupId>org.onosproject</groupId> | ||
48 | + <artifactId>onos-core-common</artifactId> | ||
49 | + <version>${project.version}</version> | ||
50 | + <classifier>tests</classifier> | ||
51 | + <scope>test</scope> | ||
52 | + </dependency> | ||
53 | + | ||
54 | + <dependency> | ||
47 | <groupId>org.apache.felix</groupId> | 55 | <groupId>org.apache.felix</groupId> |
48 | <artifactId>org.apache.felix.scr.annotations</artifactId> | 56 | <artifactId>org.apache.felix.scr.annotations</artifactId> |
49 | </dependency> | 57 | </dependency> | ... | ... |
... | @@ -39,6 +39,11 @@ | ... | @@ -39,6 +39,11 @@ |
39 | 39 | ||
40 | <dependency> | 40 | <dependency> |
41 | <groupId>org.onosproject</groupId> | 41 | <groupId>org.onosproject</groupId> |
42 | + <artifactId>onos-core-common</artifactId> | ||
43 | + </dependency> | ||
44 | + | ||
45 | + <dependency> | ||
46 | + <groupId>org.onosproject</groupId> | ||
42 | <artifactId>onos-api</artifactId> | 47 | <artifactId>onos-api</artifactId> |
43 | <classifier>tests</classifier> | 48 | <classifier>tests</classifier> |
44 | <scope>test</scope> | 49 | <scope>test</scope> | ... | ... |
... | @@ -51,6 +51,11 @@ public class SimpleApplicationIdStore implements ApplicationIdStore { | ... | @@ -51,6 +51,11 @@ public class SimpleApplicationIdStore implements ApplicationIdStore { |
51 | } | 51 | } |
52 | 52 | ||
53 | @Override | 53 | @Override |
54 | + public ApplicationId getAppId(String name) { | ||
55 | + return appIdsByName.get(name); | ||
56 | + } | ||
57 | + | ||
58 | + @Override | ||
54 | public ApplicationId registerApplication(String name) { | 59 | public ApplicationId registerApplication(String name) { |
55 | DefaultApplicationId appId = appIdsByName.get(name); | 60 | DefaultApplicationId appId = appIdsByName.get(name); |
56 | if (appId == null) { | 61 | if (appId == null) { | ... | ... |
core/store/trivial/src/main/java/org/onosproject/store/trivial/impl/SimpleApplicationStore.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.store.trivial.impl; | ||
17 | + | ||
18 | +import com.google.common.collect.ImmutableSet; | ||
19 | +import org.apache.felix.scr.annotations.Activate; | ||
20 | +import org.apache.felix.scr.annotations.Component; | ||
21 | +import org.apache.felix.scr.annotations.Deactivate; | ||
22 | +import org.apache.felix.scr.annotations.Reference; | ||
23 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
24 | +import org.apache.felix.scr.annotations.Service; | ||
25 | +import org.onosproject.app.ApplicationDescription; | ||
26 | +import org.onosproject.app.ApplicationEvent; | ||
27 | +import org.onosproject.app.ApplicationState; | ||
28 | +import org.onosproject.app.ApplicationStore; | ||
29 | +import org.onosproject.common.app.ApplicationArchive; | ||
30 | +import org.onosproject.core.Application; | ||
31 | +import org.onosproject.core.ApplicationId; | ||
32 | +import org.onosproject.core.ApplicationIdStore; | ||
33 | +import org.onosproject.core.DefaultApplication; | ||
34 | +import org.onosproject.core.Permission; | ||
35 | +import org.slf4j.Logger; | ||
36 | + | ||
37 | +import java.io.InputStream; | ||
38 | +import java.util.Set; | ||
39 | +import java.util.concurrent.ConcurrentHashMap; | ||
40 | +import java.util.concurrent.ConcurrentMap; | ||
41 | + | ||
42 | +import static org.onosproject.app.ApplicationEvent.Type.*; | ||
43 | +import static org.onosproject.app.ApplicationState.ACTIVE; | ||
44 | +import static org.onosproject.app.ApplicationState.INSTALLED; | ||
45 | +import static org.slf4j.LoggerFactory.getLogger; | ||
46 | + | ||
47 | +/** | ||
48 | + * Manages inventory of network control applications. | ||
49 | + */ | ||
50 | +@Component(immediate = true) | ||
51 | +@Service | ||
52 | +public class SimpleApplicationStore extends ApplicationArchive implements ApplicationStore { | ||
53 | + | ||
54 | + private final Logger log = getLogger(getClass()); | ||
55 | + | ||
56 | + // App inventory & states | ||
57 | + private final ConcurrentMap<ApplicationId, DefaultApplication> apps = new ConcurrentHashMap<>(); | ||
58 | + private final ConcurrentMap<ApplicationId, ApplicationState> states = new ConcurrentHashMap<>(); | ||
59 | + private final ConcurrentMap<ApplicationId, Set<Permission>> permissions = new ConcurrentHashMap<>(); | ||
60 | + | ||
61 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
62 | + protected ApplicationIdStore idStore; | ||
63 | + | ||
64 | + @Activate | ||
65 | + public void activate() { | ||
66 | + loadFromDisk(); | ||
67 | + log.info("Started"); | ||
68 | + } | ||
69 | + | ||
70 | + private void loadFromDisk() { | ||
71 | + for (String name : getApplicationNames()) { | ||
72 | + ApplicationId appId = idStore.registerApplication(name); | ||
73 | + ApplicationDescription appDesc = getApplicationDescription(name); | ||
74 | + DefaultApplication app = | ||
75 | + new DefaultApplication(appId, appDesc.version(), | ||
76 | + appDesc.description(), appDesc.origin(), | ||
77 | + appDesc.permissions(), | ||
78 | + appDesc.featuresRepo(), appDesc.features()); | ||
79 | + apps.put(appId, app); | ||
80 | + states.put(appId, isActive(name) ? INSTALLED : ACTIVE); | ||
81 | + // load app permissions | ||
82 | + } | ||
83 | + } | ||
84 | + | ||
85 | + @Deactivate | ||
86 | + public void deactivate() { | ||
87 | + apps.clear(); | ||
88 | + states.clear(); | ||
89 | + permissions.clear(); | ||
90 | + log.info("Stopped"); | ||
91 | + } | ||
92 | + | ||
93 | + @Override | ||
94 | + public Set<Application> getApplications() { | ||
95 | + return ImmutableSet.copyOf(apps.values()); | ||
96 | + } | ||
97 | + | ||
98 | + @Override | ||
99 | + public ApplicationId getId(String name) { | ||
100 | + return idStore.getAppId(name); | ||
101 | + } | ||
102 | + | ||
103 | + @Override | ||
104 | + public Application getApplication(ApplicationId appId) { | ||
105 | + return apps.get(appId); | ||
106 | + } | ||
107 | + | ||
108 | + @Override | ||
109 | + public ApplicationState getState(ApplicationId appId) { | ||
110 | + return states.get(appId); | ||
111 | + } | ||
112 | + | ||
113 | + @Override | ||
114 | + public Application create(InputStream appDescStream) { | ||
115 | + ApplicationDescription appDesc = saveApplication(appDescStream); | ||
116 | + ApplicationId appId = idStore.registerApplication(appDesc.name()); | ||
117 | + DefaultApplication app = | ||
118 | + new DefaultApplication(appId, appDesc.version(), appDesc.description(), | ||
119 | + appDesc.origin(), appDesc.permissions(), | ||
120 | + appDesc.featuresRepo(), appDesc.features()); | ||
121 | + apps.put(appId, app); | ||
122 | + states.put(appId, INSTALLED); | ||
123 | + delegate.notify(new ApplicationEvent(APP_INSTALLED, app)); | ||
124 | + return app; | ||
125 | + } | ||
126 | + | ||
127 | + @Override | ||
128 | + public void remove(ApplicationId appId) { | ||
129 | + Application app = apps.remove(appId); | ||
130 | + if (app != null) { | ||
131 | + states.remove(appId); | ||
132 | + delegate.notify(new ApplicationEvent(APP_UNINSTALLED, app)); | ||
133 | + purgeApplication(app.id().name()); | ||
134 | + } | ||
135 | + } | ||
136 | + | ||
137 | + @Override | ||
138 | + public void activate(ApplicationId appId) { | ||
139 | + Application app = apps.get(appId); | ||
140 | + if (app != null) { | ||
141 | + setActive(appId.name()); | ||
142 | + states.put(appId, ACTIVE); | ||
143 | + delegate.notify(new ApplicationEvent(APP_ACTIVATED, app)); | ||
144 | + } | ||
145 | + } | ||
146 | + | ||
147 | + @Override | ||
148 | + public void deactivate(ApplicationId appId) { | ||
149 | + Application app = apps.get(appId); | ||
150 | + if (app != null) { | ||
151 | + clearActive(appId.name()); | ||
152 | + states.put(appId, INSTALLED); | ||
153 | + delegate.notify(new ApplicationEvent(APP_DEACTIVATED, app)); | ||
154 | + } | ||
155 | + } | ||
156 | + | ||
157 | + @Override | ||
158 | + public Set<Permission> getPermissions(ApplicationId appId) { | ||
159 | + return permissions.get(appId); | ||
160 | + } | ||
161 | + | ||
162 | + @Override | ||
163 | + public void setPermissions(ApplicationId appId, Set<Permission> permissions) { | ||
164 | + Application app = getApplication(appId); | ||
165 | + if (app != null) { | ||
166 | + this.permissions.put(appId, permissions); | ||
167 | + delegate.notify(new ApplicationEvent(APP_PERMISSIONS_CHANGED, app)); | ||
168 | + } | ||
169 | + } | ||
170 | +} |
core/store/trivial/src/test/java/org/onosproject/store/trivial/impl/SimpleApplicationStoreTest.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.store.trivial.impl; | ||
17 | + | ||
18 | +import com.google.common.collect.ImmutableSet; | ||
19 | +import org.junit.After; | ||
20 | +import org.junit.Before; | ||
21 | +import org.junit.Test; | ||
22 | +import org.onosproject.app.ApplicationEvent; | ||
23 | +import org.onosproject.app.ApplicationStoreDelegate; | ||
24 | +import org.onosproject.common.app.ApplicationArchive; | ||
25 | +import org.onosproject.core.Application; | ||
26 | +import org.onosproject.core.ApplicationId; | ||
27 | +import org.onosproject.core.ApplicationIdStoreAdapter; | ||
28 | +import org.onosproject.core.DefaultApplicationId; | ||
29 | +import org.onosproject.core.Permission; | ||
30 | + | ||
31 | +import static org.junit.Assert.assertEquals; | ||
32 | +import static org.onosproject.app.ApplicationEvent.Type.*; | ||
33 | +import static org.onosproject.app.ApplicationState.ACTIVE; | ||
34 | +import static org.onosproject.app.ApplicationState.INSTALLED; | ||
35 | + | ||
36 | +/** | ||
37 | + * Test of the trivial application store implementation. | ||
38 | + */ | ||
39 | +public class SimpleApplicationStoreTest { | ||
40 | + | ||
41 | + private SimpleApplicationStore store = new SimpleApplicationStore(); | ||
42 | + private TestDelegate delegate = new TestDelegate(); | ||
43 | + | ||
44 | + @Before | ||
45 | + public void setUp() { | ||
46 | + store.idStore = new TestIdStore(); | ||
47 | + store.setDelegate(delegate); | ||
48 | + store.activate(); | ||
49 | + } | ||
50 | + | ||
51 | + @After | ||
52 | + public void tearDown() { | ||
53 | + store.deactivate(); | ||
54 | + } | ||
55 | + | ||
56 | + private Application createTestApp() { | ||
57 | + return store.create(ApplicationArchive.class.getResourceAsStream("app.zip")); | ||
58 | + } | ||
59 | + | ||
60 | + @Test | ||
61 | + public void create() { | ||
62 | + Application app = createTestApp(); | ||
63 | + assertEquals("incorrect name", "org.foo.app", app.id().name()); | ||
64 | + assertEquals("incorrect app count", 1, store.getApplications().size()); | ||
65 | + assertEquals("incorrect app", app, store.getApplication(app.id())); | ||
66 | + assertEquals("incorrect app state", INSTALLED, store.getState(app.id())); | ||
67 | + assertEquals("incorrect event type", APP_INSTALLED, delegate.event.type()); | ||
68 | + assertEquals("incorrect event app", app, delegate.event.subject()); | ||
69 | + } | ||
70 | + | ||
71 | + @Test | ||
72 | + public void remove() { | ||
73 | + Application app = createTestApp(); | ||
74 | + store.remove(app.id()); | ||
75 | + assertEquals("incorrect app count", 0, store.getApplications().size()); | ||
76 | + assertEquals("incorrect event type", APP_UNINSTALLED, delegate.event.type()); | ||
77 | + assertEquals("incorrect event app", app, delegate.event.subject()); | ||
78 | + } | ||
79 | + | ||
80 | + @Test | ||
81 | + public void activate() { | ||
82 | + Application app = createTestApp(); | ||
83 | + store.activate(app.id()); | ||
84 | + assertEquals("incorrect app count", 1, store.getApplications().size()); | ||
85 | + assertEquals("incorrect app state", ACTIVE, store.getState(app.id())); | ||
86 | + assertEquals("incorrect event type", APP_ACTIVATED, delegate.event.type()); | ||
87 | + assertEquals("incorrect event app", app, delegate.event.subject()); | ||
88 | + } | ||
89 | + | ||
90 | + @Test | ||
91 | + public void deactivate() { | ||
92 | + Application app = createTestApp(); | ||
93 | + store.deactivate(app.id()); | ||
94 | + assertEquals("incorrect app count", 1, store.getApplications().size()); | ||
95 | + assertEquals("incorrect app state", INSTALLED, store.getState(app.id())); | ||
96 | + assertEquals("incorrect event type", APP_DEACTIVATED, delegate.event.type()); | ||
97 | + assertEquals("incorrect event app", app, delegate.event.subject()); | ||
98 | + } | ||
99 | + | ||
100 | + @Test | ||
101 | + public void permissions() { | ||
102 | + Application app = createTestApp(); | ||
103 | + ImmutableSet<Permission> permissions = ImmutableSet.of(new Permission() { | ||
104 | + }); | ||
105 | + store.setPermissions(app.id(), permissions); | ||
106 | + assertEquals("incorrect app perms", 1, store.getPermissions(app.id()).size()); | ||
107 | + assertEquals("incorrect app state", INSTALLED, store.getState(app.id())); | ||
108 | + assertEquals("incorrect event type", APP_PERMISSIONS_CHANGED, delegate.event.type()); | ||
109 | + assertEquals("incorrect event app", app, delegate.event.subject()); | ||
110 | + } | ||
111 | + | ||
112 | + private class TestIdStore extends ApplicationIdStoreAdapter { | ||
113 | + @Override | ||
114 | + public ApplicationId registerApplication(String name) { | ||
115 | + return new DefaultApplicationId(1, name); | ||
116 | + } | ||
117 | + | ||
118 | + @Override | ||
119 | + public ApplicationId getAppId(String name) { | ||
120 | + return new DefaultApplicationId(1, name); | ||
121 | + } | ||
122 | + } | ||
123 | + | ||
124 | + private class TestDelegate implements ApplicationStoreDelegate { | ||
125 | + private ApplicationEvent event; | ||
126 | + | ||
127 | + @Override | ||
128 | + public void notify(ApplicationEvent event) { | ||
129 | + this.event = event; | ||
130 | + } | ||
131 | + } | ||
132 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -49,7 +49,7 @@ | ... | @@ -49,7 +49,7 @@ |
49 | <version>2.10.1</version> | 49 | <version>2.10.1</version> |
50 | <configuration> | 50 | <configuration> |
51 | <show>package</show> | 51 | <show>package</show> |
52 | - <excludePackageNames>org.onlab.thirdparty:*.impl:*.impl.*:org.onosproject.provider.*:org.onosproject.gui:org.onosproject.rest:org.onosproject.cli*:org.onosproject.tvue:org.onosproject.foo:org.onosproject.mobility:org.onosproject.proxyarp:org.onosproject.fwd:org.onosproject.ifwd:org.onosproject.optical:org.onosproject.config:org.onosproject.calendar:org.onosproject.sdnip*:org.onosproject.oecfg:org.onosproject.metrics:org.onosproject.store.*:org.onosproject.openflow.*</excludePackageNames> | 52 | + <excludePackageNames>org.onlab.thirdparty:*.impl:*.impl.*:org.onosproject.provider.*:org.onosproject.gui:org.onosproject.rest:org.onosproject.cli*:org.onosproject.tvue:org.onosproject.foo:org.onosproject.mobility:org.onosproject.proxyarp:org.onosproject.fwd:org.onosproject.ifwd:org.onosproject.optical:org.onosproject.config:org.onosproject.calendar:org.onosproject.sdnip*:org.onosproject.oecfg:org.onosproject.metrics:org.onosproject.store.*:org.onosproject.openflow.*:org.onosproject.common.*</excludePackageNames> |
53 | <docfilessubdirs>true</docfilessubdirs> | 53 | <docfilessubdirs>true</docfilessubdirs> |
54 | <doctitle>ONOS Java API</doctitle> | 54 | <doctitle>ONOS Java API</doctitle> |
55 | <groups> | 55 | <groups> | ... | ... |
... | @@ -61,7 +61,7 @@ | ... | @@ -61,7 +61,7 @@ |
61 | <group> | 61 | <group> |
62 | <title>Core Subsystems</title> | 62 | <title>Core Subsystems</title> |
63 | <packages> | 63 | <packages> |
64 | - org.onosproject.impl:org.onosproject.core.impl:org.onosproject.cluster.impl:org.onosproject.net.device.impl:org.onosproject.net.link.impl:org.onosproject.net.host.impl:org.onosproject.net.topology.impl:org.onosproject.net.packet.impl:org.onosproject.net.flow.impl:org.onosproject.net.*.impl:org.onosproject.event.impl:org.onosproject.net.intent.impl:org.onosproject.net.proxyarp.impl:org.onosproject.mastership.impl:org.onosproject.net.resource.impl:org.onosproject.json:org.onosproject.json.*:org.onosproject.provider.host.impl:org.onosproject.provider.lldp.impl:org.onosproject.net.statistic.impl | 64 | + org.onosproject.impl:org.onosproject.core.impl:org.onosproject.cluster.impl:org.onosproject.net.device.impl:org.onosproject.net.link.impl:org.onosproject.net.host.impl:org.onosproject.net.topology.impl:org.onosproject.net.packet.impl:org.onosproject.net.flow.impl:org.onosproject.net.*.impl:org.onosproject.event.impl:org.onosproject.net.intent.impl:org.onosproject.net.proxyarp.impl:org.onosproject.mastership.impl:org.onosproject.net.resource.impl:org.onosproject.json:org.onosproject.json.*:org.onosproject.provider.host.impl:org.onosproject.provider.lldp.impl:org.onosproject.net.statistic.impl:org.onosproject.app.impl:org.onosproject.common.* |
65 | </packages> | 65 | </packages> |
66 | </group> | 66 | </group> |
67 | <group> | 67 | <group> | ... | ... |
... | @@ -22,6 +22,7 @@ | ... | @@ -22,6 +22,7 @@ |
22 | description="ONOS 3rd party dependencies"> | 22 | description="ONOS 3rd party dependencies"> |
23 | <bundle>mvn:commons-lang/commons-lang/2.6</bundle> | 23 | <bundle>mvn:commons-lang/commons-lang/2.6</bundle> |
24 | <bundle>mvn:org.apache.commons/commons-lang3/3.3.2</bundle> | 24 | <bundle>mvn:org.apache.commons/commons-lang3/3.3.2</bundle> |
25 | + <bundle>mvn:commons-configuration/commons-configuration/1.10</bundle> | ||
25 | <bundle>mvn:com.google.guava/guava/18.0</bundle> | 26 | <bundle>mvn:com.google.guava/guava/18.0</bundle> |
26 | <bundle>mvn:io.netty/netty/3.9.2.Final</bundle> | 27 | <bundle>mvn:io.netty/netty/3.9.2.Final</bundle> |
27 | <bundle>mvn:io.netty/netty-common/4.0.23.Final</bundle> | 28 | <bundle>mvn:io.netty/netty-common/4.0.23.Final</bundle> |
... | @@ -86,6 +87,7 @@ | ... | @@ -86,6 +87,7 @@ |
86 | description="ONOS core components"> | 87 | description="ONOS core components"> |
87 | <feature>onos-api</feature> | 88 | <feature>onos-api</feature> |
88 | <bundle>mvn:org.onosproject/onos-core-net/@ONOS-VERSION</bundle> | 89 | <bundle>mvn:org.onosproject/onos-core-net/@ONOS-VERSION</bundle> |
90 | + <bundle>mvn:org.onosproject/onos-core-common/@ONOS-VERSION</bundle> | ||
89 | <bundle>mvn:org.onosproject/onos-core-dist/@ONOS-VERSION</bundle> | 91 | <bundle>mvn:org.onosproject/onos-core-dist/@ONOS-VERSION</bundle> |
90 | <bundle>mvn:org.onosproject/onos-core-serializers/@ONOS-VERSION</bundle> | 92 | <bundle>mvn:org.onosproject/onos-core-serializers/@ONOS-VERSION</bundle> |
91 | <bundle>mvn:org.onosproject/onlab-netty/@ONOS-VERSION</bundle> | 93 | <bundle>mvn:org.onosproject/onlab-netty/@ONOS-VERSION</bundle> |
... | @@ -95,6 +97,7 @@ | ... | @@ -95,6 +97,7 @@ |
95 | description="ONOS core components"> | 97 | description="ONOS core components"> |
96 | <feature>onos-api</feature> | 98 | <feature>onos-api</feature> |
97 | <bundle>mvn:org.onosproject/onos-core-net/@ONOS-VERSION</bundle> | 99 | <bundle>mvn:org.onosproject/onos-core-net/@ONOS-VERSION</bundle> |
100 | + <bundle>mvn:org.onosproject/onos-core-common/@ONOS-VERSION</bundle> | ||
98 | <bundle>mvn:org.onosproject/onos-core-trivial/@ONOS-VERSION</bundle> | 101 | <bundle>mvn:org.onosproject/onos-core-trivial/@ONOS-VERSION</bundle> |
99 | </feature> | 102 | </feature> |
100 | 103 | ... | ... |
... | @@ -161,6 +161,12 @@ | ... | @@ -161,6 +161,12 @@ |
161 | </dependency> | 161 | </dependency> |
162 | 162 | ||
163 | <dependency> | 163 | <dependency> |
164 | + <groupId>commons-configuration</groupId> | ||
165 | + <artifactId>commons-configuration</artifactId> | ||
166 | + <version>1.10</version> | ||
167 | + </dependency> | ||
168 | + | ||
169 | + <dependency> | ||
164 | <groupId>org.apache.commons</groupId> | 170 | <groupId>org.apache.commons</groupId> |
165 | <artifactId>commons-collections4</artifactId> | 171 | <artifactId>commons-collections4</artifactId> |
166 | <version>4.0</version> | 172 | <version>4.0</version> |
... | @@ -315,6 +321,13 @@ | ... | @@ -315,6 +321,13 @@ |
315 | <scope>test</scope> | 321 | <scope>test</scope> |
316 | </dependency> | 322 | </dependency> |
317 | 323 | ||
324 | + | ||
325 | + <dependency> | ||
326 | + <groupId>org.onosproject</groupId> | ||
327 | + <artifactId>onos-core-common</artifactId> | ||
328 | + <version>${project.version}</version> | ||
329 | + </dependency> | ||
330 | + | ||
318 | <dependency> | 331 | <dependency> |
319 | <groupId>org.onosproject</groupId> | 332 | <groupId>org.onosproject</groupId> |
320 | <artifactId>onos-of-api</artifactId> | 333 | <artifactId>onos-of-api</artifactId> | ... | ... |
... | @@ -133,8 +133,8 @@ public class HostLocationProviderTest { | ... | @@ -133,8 +133,8 @@ public class HostLocationProviderTest { |
133 | private CoreService coreService; | 133 | private CoreService coreService; |
134 | private TestHostProviderService providerService; | 134 | private TestHostProviderService providerService; |
135 | 135 | ||
136 | - private ApplicationId appId = new DefaultApplicationId((short) 100, | 136 | + private ApplicationId appId = |
137 | - "org.onosproject.provider.host"); | 137 | + new DefaultApplicationId(100, "org.onosproject.provider.host"); |
138 | 138 | ||
139 | @Before | 139 | @Before |
140 | public void setUp() { | 140 | public void setUp() { | ... | ... |
... | @@ -97,8 +97,8 @@ public class LLDPLinkProviderTest { | ... | @@ -97,8 +97,8 @@ public class LLDPLinkProviderTest { |
97 | private PacketProcessor testProcessor; | 97 | private PacketProcessor testProcessor; |
98 | private DeviceListener deviceListener; | 98 | private DeviceListener deviceListener; |
99 | 99 | ||
100 | - private ApplicationId appId = new DefaultApplicationId((short) 100, | 100 | + private ApplicationId appId = |
101 | - "org.onosproject.provider.lldp"); | 101 | + new DefaultApplicationId(100, "org.onosproject.provider.lldp"); |
102 | 102 | ||
103 | @Before | 103 | @Before |
104 | public void setUp() { | 104 | public void setUp() { | ... | ... |
tools/test/bin/onos-app
0 → 100755
1 | +#!/bin/bash | ||
2 | +# ----------------------------------------------------------------------------- | ||
3 | +# Tool to manage ONOS applications using REST API. | ||
4 | +# ----------------------------------------------------------------------------- | ||
5 | + | ||
6 | +node=${1:-$OCI} | ||
7 | +cmd=${2:-list} | ||
8 | +app=${3} | ||
9 | + | ||
10 | +export URL=http://$node:8181/onos/v1/applications | ||
11 | +export HDR="-HContent-Type:application/octet-stream" | ||
12 | +export curl="curl -sS" | ||
13 | + | ||
14 | +case $cmd in | ||
15 | + list) $curl -X GET $URL;; | ||
16 | + install) $curl -X POST $HDR $URL --data-binary @$app;; | ||
17 | + uninstall) $curl -X DELETE $URL/$app;; | ||
18 | + activate) $curl -X POST $URL/$app/active;; | ||
19 | + deactivate) $curl -X DELETE $URL/$app/active;; | ||
20 | +esac |
tools/test/topos/chordal.py
0 → 100644
This diff is collapsed. Click to expand it.
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onlab.junit; | ||
17 | + | ||
18 | +import org.junit.Test; | ||
19 | + | ||
20 | +import static org.junit.Assert.assertEquals; | ||
21 | +import static org.junit.Assert.assertSame; | ||
22 | + | ||
23 | +/** | ||
24 | + * Base for exception tests. | ||
25 | + */ | ||
26 | +public abstract class ExceptionTest { | ||
27 | + | ||
28 | + protected static final Throwable CAUSE = new RuntimeException("boom"); | ||
29 | + protected static final String MESSAGE = "Uh oh.... boom"; | ||
30 | + | ||
31 | + protected abstract Exception getDefault(); | ||
32 | + protected abstract Exception getWithMessage(); | ||
33 | + protected abstract Exception getWithMessageAndCause(); | ||
34 | + | ||
35 | + @Test | ||
36 | + public void noMessageNoCause() { | ||
37 | + Exception e = getDefault(); | ||
38 | + assertEquals("incorrect message", null, e.getMessage()); | ||
39 | + assertEquals("incorrect cause", null, e.getCause()); | ||
40 | + } | ||
41 | + | ||
42 | + @Test | ||
43 | + public void withMessage() { | ||
44 | + Exception e = getWithMessage(); | ||
45 | + assertEquals("incorrect message", MESSAGE, e.getMessage()); | ||
46 | + assertEquals("incorrect cause", null, e.getCause()); | ||
47 | + } | ||
48 | + | ||
49 | + @Test | ||
50 | + public void withCause() { | ||
51 | + Exception e = getWithMessageAndCause(); | ||
52 | + assertEquals("incorrect message", MESSAGE, e.getMessage()); | ||
53 | + assertSame("incorrect cause", CAUSE, e.getCause()); | ||
54 | + } | ||
55 | +} |
... | @@ -15,6 +15,14 @@ | ... | @@ -15,6 +15,14 @@ |
15 | */ | 15 | */ |
16 | package org.onlab.junit; | 16 | package org.onlab.junit; |
17 | 17 | ||
18 | +import com.google.common.collect.ImmutableList; | ||
19 | +import com.google.common.io.Files; | ||
20 | + | ||
21 | +import java.io.File; | ||
22 | +import java.io.IOException; | ||
23 | +import java.util.List; | ||
24 | +import java.util.Random; | ||
25 | + | ||
18 | import static com.google.common.base.Preconditions.checkArgument; | 26 | import static com.google.common.base.Preconditions.checkArgument; |
19 | import static org.junit.Assert.fail; | 27 | import static org.junit.Assert.fail; |
20 | 28 | ||
... | @@ -23,6 +31,8 @@ import static org.junit.Assert.fail; | ... | @@ -23,6 +31,8 @@ import static org.junit.Assert.fail; |
23 | */ | 31 | */ |
24 | public final class TestTools { | 32 | public final class TestTools { |
25 | 33 | ||
34 | + private static final Random RANDOM = new Random(); | ||
35 | + | ||
26 | // Prohibit construction | 36 | // Prohibit construction |
27 | private TestTools() { | 37 | private TestTools() { |
28 | } | 38 | } |
... | @@ -109,4 +119,92 @@ public final class TestTools { | ... | @@ -109,4 +119,92 @@ public final class TestTools { |
109 | assertAfter(0, duration, assertions); | 119 | assertAfter(0, duration, assertions); |
110 | } | 120 | } |
111 | 121 | ||
122 | + | ||
123 | + /** | ||
124 | + * Creates a directory tree of test files. To signify creating a directory | ||
125 | + * file path should end with '/'. | ||
126 | + * | ||
127 | + * @param paths list of file paths | ||
128 | + * @return list of created files | ||
129 | + * @throws java.io.IOException if there is an issue | ||
130 | + */ | ||
131 | + public static List<File> createTestFiles(List<String> paths) throws IOException { | ||
132 | + return createTestFiles(paths, 32, 1024); | ||
133 | + } | ||
134 | + | ||
135 | + /** | ||
136 | + * Creates a directory tree of test files. To signify creating a directory | ||
137 | + * file path should end with '/'. | ||
138 | + * | ||
139 | + * @param paths list of file paths | ||
140 | + * @param minSize minimum file size in bytes | ||
141 | + * @param maxSize maximum file size in bytes | ||
142 | + * @return list of created files | ||
143 | + * @throws java.io.IOException if there is an issue | ||
144 | + */ | ||
145 | + public static List<File> createTestFiles(List<String> paths, | ||
146 | + int minSize, int maxSize) throws IOException { | ||
147 | + ImmutableList.Builder<File> files = ImmutableList.builder(); | ||
148 | + for (String p : paths) { | ||
149 | + File f = new File(p); | ||
150 | + if (p.endsWith("/")) { | ||
151 | + if (f.mkdirs()) { | ||
152 | + files.add(f); | ||
153 | + } | ||
154 | + } else { | ||
155 | + Files.createParentDirs(f); | ||
156 | + if (f.createNewFile()) { | ||
157 | + writeRandomFile(f, minSize, maxSize); | ||
158 | + files.add(f); | ||
159 | + } | ||
160 | + } | ||
161 | + } | ||
162 | + return files.build(); | ||
163 | + } | ||
164 | + | ||
165 | + /** | ||
166 | + * Writes random binary content into the specified file. The number of | ||
167 | + * bytes will be random between the given minimum and maximum. | ||
168 | + * | ||
169 | + * @param file file to write data to | ||
170 | + * @param minSize minimum number of bytes to write | ||
171 | + * @param maxSize maximum number of bytes to write | ||
172 | + * @throws IOException if there is an issue | ||
173 | + */ | ||
174 | + public static void writeRandomFile(File file, int minSize, int maxSize) throws IOException { | ||
175 | + int size = minSize + (minSize == maxSize ? 0 : RANDOM.nextInt(maxSize - minSize)); | ||
176 | + byte[] data = new byte[size]; | ||
177 | + tweakBytes(RANDOM, data, size / 4); | ||
178 | + Files.write(data, file); | ||
179 | + } | ||
180 | + | ||
181 | + | ||
182 | + /** | ||
183 | + * Tweaks the given number of bytes in a byte array. | ||
184 | + * | ||
185 | + * @param random random number generator | ||
186 | + * @param data byte array to be tweaked | ||
187 | + * @param count number of bytes to tweak | ||
188 | + */ | ||
189 | + public static void tweakBytes(Random random, byte[] data, int count) { | ||
190 | + tweakBytes(random, data, count, 0, data.length); | ||
191 | + } | ||
192 | + | ||
193 | + /** | ||
194 | + * Tweaks the given number of bytes in the specified range of a byte array. | ||
195 | + * | ||
196 | + * @param random random number generator | ||
197 | + * @param data byte array to be tweaked | ||
198 | + * @param count number of bytes to tweak | ||
199 | + * @param start index at beginning of range (inclusive) | ||
200 | + * @param end index at end of range (exclusive) | ||
201 | + */ | ||
202 | + public static void tweakBytes(Random random, byte[] data, int count, | ||
203 | + int start, int end) { | ||
204 | + int len = end - start; | ||
205 | + for (int i = 0; i < count; i++) { | ||
206 | + data[start + random.nextInt(len)] = (byte) random.nextInt(); | ||
207 | + } | ||
208 | + } | ||
209 | + | ||
112 | } | 210 | } | ... | ... |
... | @@ -15,6 +15,8 @@ | ... | @@ -15,6 +15,8 @@ |
15 | */ | 15 | */ |
16 | package org.onlab.util; | 16 | package org.onlab.util; |
17 | 17 | ||
18 | +import static java.nio.file.Files.delete; | ||
19 | +import static java.nio.file.Files.walkFileTree; | ||
18 | import static org.slf4j.LoggerFactory.getLogger; | 20 | import static org.slf4j.LoggerFactory.getLogger; |
19 | 21 | ||
20 | import java.io.BufferedReader; | 22 | import java.io.BufferedReader; |
... | @@ -24,6 +26,11 @@ import java.io.IOException; | ... | @@ -24,6 +26,11 @@ import java.io.IOException; |
24 | import java.io.InputStreamReader; | 26 | import java.io.InputStreamReader; |
25 | import java.lang.Thread.UncaughtExceptionHandler; | 27 | import java.lang.Thread.UncaughtExceptionHandler; |
26 | import java.nio.charset.StandardCharsets; | 28 | import java.nio.charset.StandardCharsets; |
29 | +import java.nio.file.FileVisitResult; | ||
30 | +import java.nio.file.Path; | ||
31 | +import java.nio.file.Paths; | ||
32 | +import java.nio.file.SimpleFileVisitor; | ||
33 | +import java.nio.file.attribute.BasicFileAttributes; | ||
27 | import java.util.ArrayList; | 34 | import java.util.ArrayList; |
28 | import java.util.List; | 35 | import java.util.List; |
29 | import java.util.concurrent.ThreadFactory; | 36 | import java.util.concurrent.ThreadFactory; |
... | @@ -39,7 +46,7 @@ public abstract class Tools { | ... | @@ -39,7 +46,7 @@ public abstract class Tools { |
39 | private Tools() { | 46 | private Tools() { |
40 | } | 47 | } |
41 | 48 | ||
42 | - private static final Logger TOOLS_LOG = getLogger(Tools.class); | 49 | + private static final Logger log = getLogger(Tools.class); |
43 | 50 | ||
44 | /** | 51 | /** |
45 | * Returns a thread factory that produces threads named according to the | 52 | * Returns a thread factory that produces threads named according to the |
... | @@ -56,7 +63,7 @@ public abstract class Tools { | ... | @@ -56,7 +63,7 @@ public abstract class Tools { |
56 | 63 | ||
57 | @Override | 64 | @Override |
58 | public void uncaughtException(Thread t, Throwable e) { | 65 | public void uncaughtException(Thread t, Throwable e) { |
59 | - TOOLS_LOG.error("Uncaught exception on {}", t.getName(), e); | 66 | + log.error("Uncaught exception on {}", t.getName(), e); |
60 | } | 67 | } |
61 | }).build(); | 68 | }).build(); |
62 | } | 69 | } |
... | @@ -141,4 +148,56 @@ public abstract class Tools { | ... | @@ -141,4 +148,56 @@ public abstract class Tools { |
141 | } | 148 | } |
142 | } | 149 | } |
143 | 150 | ||
151 | + | ||
152 | + /** | ||
153 | + * Purges the specified directory path. Use with great caution since | ||
154 | + * no attempt is made to check for symbolic links, which could result in | ||
155 | + * deletion of unintended files. | ||
156 | + * | ||
157 | + * @param path directory to be removed | ||
158 | + * @throws java.io.IOException if unable to remove contents | ||
159 | + */ | ||
160 | + public static void removeDirectory(String path) throws IOException { | ||
161 | + walkFileTree(Paths.get(path), new DirectoryDeleter()); | ||
162 | + } | ||
163 | + | ||
164 | + /** | ||
165 | + * Purges the specified directory path. Use with great caution since | ||
166 | + * no attempt is made to check for symbolic links, which could result in | ||
167 | + * deletion of unintended files. | ||
168 | + * | ||
169 | + * @param dir directory to be removed | ||
170 | + * @throws java.io.IOException if unable to remove contents | ||
171 | + */ | ||
172 | + public static void removeDirectory(File dir) throws IOException { | ||
173 | + walkFileTree(Paths.get(dir.getAbsolutePath()), new DirectoryDeleter()); | ||
174 | + } | ||
175 | + | ||
176 | + | ||
177 | + private static class DirectoryDeleter extends SimpleFileVisitor<Path> { | ||
178 | + @Override | ||
179 | + public FileVisitResult visitFile(Path file, BasicFileAttributes attributes) | ||
180 | + throws IOException { | ||
181 | + if (attributes.isRegularFile()) { | ||
182 | + delete(file); | ||
183 | + } | ||
184 | + return FileVisitResult.CONTINUE; | ||
185 | + } | ||
186 | + | ||
187 | + @Override | ||
188 | + public FileVisitResult postVisitDirectory(Path directory, IOException ioe) | ||
189 | + throws IOException { | ||
190 | + delete(directory); | ||
191 | + return FileVisitResult.CONTINUE; | ||
192 | + } | ||
193 | + | ||
194 | + @Override | ||
195 | + public FileVisitResult visitFileFailed(Path file, IOException ioe) | ||
196 | + throws IOException { | ||
197 | + log.warn("Unable to delete file {}", file); | ||
198 | + log.warn("Boom", ioe); | ||
199 | + return FileVisitResult.CONTINUE; | ||
200 | + } | ||
201 | + } | ||
202 | + | ||
144 | } | 203 | } | ... | ... |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.codec.impl; | ||
17 | + | ||
18 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
19 | +import org.onosproject.app.ApplicationService; | ||
20 | +import org.onosproject.codec.CodecContext; | ||
21 | +import org.onosproject.codec.JsonCodec; | ||
22 | +import org.onosproject.core.Application; | ||
23 | + | ||
24 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
25 | + | ||
26 | +/** | ||
27 | + * Application JSON codec. | ||
28 | + */ | ||
29 | +public class ApplicationCodec extends JsonCodec<Application> { | ||
30 | + | ||
31 | + @Override | ||
32 | + public ObjectNode encode(Application app, CodecContext context) { | ||
33 | + checkNotNull(app, "Application cannot be null"); | ||
34 | + ApplicationService service = context.get(ApplicationService.class); | ||
35 | + ObjectNode result = context.mapper().createObjectNode() | ||
36 | + .put("name", app.id().name()) | ||
37 | + .put("id", app.id().id()) | ||
38 | + .put("version", app.version().toString()) | ||
39 | + .put("description", app.description()) | ||
40 | + .put("origin", app.origin()) | ||
41 | + .put("permissions", app.permissions().toString()) | ||
42 | + .put("featuresRepo", app.featuresRepo().isPresent() ? | ||
43 | + app.featuresRepo().toString() : "") | ||
44 | + .put("features", app.features().toString()) | ||
45 | + .put("state", service.getState(app.id()).toString()); | ||
46 | + return result; | ||
47 | + } | ||
48 | + | ||
49 | +} |
... | @@ -26,6 +26,7 @@ import org.apache.felix.scr.annotations.Service; | ... | @@ -26,6 +26,7 @@ import org.apache.felix.scr.annotations.Service; |
26 | import org.onlab.packet.Ethernet; | 26 | import org.onlab.packet.Ethernet; |
27 | import org.onosproject.codec.CodecService; | 27 | import org.onosproject.codec.CodecService; |
28 | import org.onosproject.codec.JsonCodec; | 28 | import org.onosproject.codec.JsonCodec; |
29 | +import org.onosproject.core.Application; | ||
29 | import org.onosproject.net.Annotations; | 30 | import org.onosproject.net.Annotations; |
30 | import org.onosproject.net.ConnectPoint; | 31 | import org.onosproject.net.ConnectPoint; |
31 | import org.onosproject.net.Device; | 32 | import org.onosproject.net.Device; |
... | @@ -64,6 +65,7 @@ public class CodecManager implements CodecService { | ... | @@ -64,6 +65,7 @@ public class CodecManager implements CodecService { |
64 | @Activate | 65 | @Activate |
65 | public void activate() { | 66 | public void activate() { |
66 | codecs.clear(); | 67 | codecs.clear(); |
68 | + registerCodec(Application.class, new ApplicationCodec()); | ||
67 | registerCodec(Annotations.class, new AnnotationsCodec()); | 69 | registerCodec(Annotations.class, new AnnotationsCodec()); |
68 | registerCodec(Device.class, new DeviceCodec()); | 70 | registerCodec(Device.class, new DeviceCodec()); |
69 | registerCodec(Port.class, new PortCodec()); | 71 | registerCodec(Port.class, new PortCodec()); | ... | ... |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.rest; | ||
17 | + | ||
18 | +import org.onosproject.app.ApplicationAdminService; | ||
19 | +import org.onosproject.core.Application; | ||
20 | +import org.onosproject.core.ApplicationId; | ||
21 | + | ||
22 | +import javax.ws.rs.Consumes; | ||
23 | +import javax.ws.rs.DELETE; | ||
24 | +import javax.ws.rs.GET; | ||
25 | +import javax.ws.rs.POST; | ||
26 | +import javax.ws.rs.Path; | ||
27 | +import javax.ws.rs.PathParam; | ||
28 | +import javax.ws.rs.Produces; | ||
29 | +import javax.ws.rs.core.MediaType; | ||
30 | +import javax.ws.rs.core.Response; | ||
31 | +import java.io.InputStream; | ||
32 | +import java.util.Set; | ||
33 | + | ||
34 | +/** | ||
35 | + * REST resource for interacting with the inventory of applications. | ||
36 | + */ | ||
37 | +@Path("applications") | ||
38 | +public class ApplicationsWebResource extends AbstractWebResource { | ||
39 | + | ||
40 | + @GET | ||
41 | + public Response getApplications() { | ||
42 | + ApplicationAdminService service = get(ApplicationAdminService.class); | ||
43 | + Set<Application> apps = service.getApplications(); | ||
44 | + return ok(encodeArray(Application.class, "applications", apps)).build(); | ||
45 | + } | ||
46 | + | ||
47 | + @GET | ||
48 | + @Path("{name}") | ||
49 | + public Response getApplication(@PathParam("id") String name) { | ||
50 | + ApplicationAdminService service = get(ApplicationAdminService.class); | ||
51 | + ApplicationId appId = service.getId(name); | ||
52 | + return response(service, appId); | ||
53 | + } | ||
54 | + | ||
55 | + @POST | ||
56 | + @Consumes(MediaType.APPLICATION_OCTET_STREAM) | ||
57 | + @Produces(MediaType.APPLICATION_JSON) | ||
58 | + public Response installApplication(InputStream stream) { | ||
59 | + ApplicationAdminService service = get(ApplicationAdminService.class); | ||
60 | + Application app = service.install(stream); | ||
61 | + return ok(codec(Application.class).encode(app, this)).build(); | ||
62 | + } | ||
63 | + | ||
64 | + @DELETE | ||
65 | + @Produces(MediaType.APPLICATION_JSON) | ||
66 | + @Path("{name}") | ||
67 | + public Response uninstallApplication(@PathParam("name") String name) { | ||
68 | + ApplicationAdminService service = get(ApplicationAdminService.class); | ||
69 | + ApplicationId appId = service.getId(name); | ||
70 | + service.uninstall(appId); | ||
71 | + return Response.ok().build(); | ||
72 | + } | ||
73 | + | ||
74 | + @POST | ||
75 | + @Produces(MediaType.APPLICATION_JSON) | ||
76 | + @Path("{name}/active") | ||
77 | + public Response activateApplication(@PathParam("name") String name) { | ||
78 | + ApplicationAdminService service = get(ApplicationAdminService.class); | ||
79 | + ApplicationId appId = service.getId(name); | ||
80 | + service.activate(appId); | ||
81 | + return response(service, appId); | ||
82 | + } | ||
83 | + | ||
84 | + @DELETE | ||
85 | + @Produces(MediaType.APPLICATION_JSON) | ||
86 | + @Path("{name}/active") | ||
87 | + public Response deactivateApplication(@PathParam("name") String name) { | ||
88 | + ApplicationAdminService service = get(ApplicationAdminService.class); | ||
89 | + ApplicationId appId = service.getId(name); | ||
90 | + service.deactivate(appId); | ||
91 | + return response(service, appId); | ||
92 | + } | ||
93 | + | ||
94 | + private Response response(ApplicationAdminService service, ApplicationId appId) { | ||
95 | + Application app = service.getApplication(appId); | ||
96 | + return ok(codec(Application.class).encode(app, this)).build(); | ||
97 | + } | ||
98 | + | ||
99 | +} |
... | @@ -35,6 +35,7 @@ | ... | @@ -35,6 +35,7 @@ |
35 | org.onosproject.rest.exceptions.ServerErrorMapper, | 35 | org.onosproject.rest.exceptions.ServerErrorMapper, |
36 | org.onosproject.rest.JsonBodyWriter, | 36 | org.onosproject.rest.JsonBodyWriter, |
37 | 37 | ||
38 | + org.onosproject.rest.ApplicationsWebResource, | ||
38 | org.onosproject.rest.DevicesWebResource, | 39 | org.onosproject.rest.DevicesWebResource, |
39 | org.onosproject.rest.LinksWebResource, | 40 | org.onosproject.rest.LinksWebResource, |
40 | org.onosproject.rest.HostsWebResource, | 41 | org.onosproject.rest.HostsWebResource, | ... | ... |
... | @@ -66,8 +66,7 @@ public class IntentCodecTest extends AbstractIntentTest { | ... | @@ -66,8 +66,7 @@ public class IntentCodecTest extends AbstractIntentTest { |
66 | 66 | ||
67 | private final HostId id1 = hid("12:34:56:78:91:ab/1"); | 67 | private final HostId id1 = hid("12:34:56:78:91:ab/1"); |
68 | private final HostId id2 = hid("12:34:56:78:92:ab/1"); | 68 | private final HostId id2 = hid("12:34:56:78:92:ab/1"); |
69 | - private final ApplicationId appId = | 69 | + private final ApplicationId appId = new DefaultApplicationId(3, "test"); |
70 | - new DefaultApplicationId((short) 3, "test"); | ||
71 | final TrafficSelector emptySelector = | 70 | final TrafficSelector emptySelector = |
72 | DefaultTrafficSelector.builder().build(); | 71 | DefaultTrafficSelector.builder().build(); |
73 | final TrafficTreatment emptyTreatment = | 72 | final TrafficTreatment emptyTreatment = | ... | ... |
... | @@ -62,8 +62,7 @@ import static org.junit.Assert.fail; | ... | @@ -62,8 +62,7 @@ import static org.junit.Assert.fail; |
62 | public class IntentsResourceTest extends ResourceTest { | 62 | public class IntentsResourceTest extends ResourceTest { |
63 | final IntentService mockIntentService = createMock(IntentService.class); | 63 | final IntentService mockIntentService = createMock(IntentService.class); |
64 | final HashSet<Intent> intents = new HashSet<>(); | 64 | final HashSet<Intent> intents = new HashSet<>(); |
65 | - private static final ApplicationId APP_ID = | 65 | + private static final ApplicationId APP_ID = new DefaultApplicationId(1, "test"); |
66 | - new DefaultApplicationId((short) 1, "test"); | ||
67 | private IdGenerator mockGenerator; | 66 | private IdGenerator mockGenerator; |
68 | 67 | ||
69 | /** | 68 | /** | ... | ... |
-
Please register or login to post a comment