Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rest.packages.provider): add deploy/v2 Rest API #4868

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
2375b3e
feat: add sources
mattdibi Sep 20, 2023
dccf5e4
fix: kura.basedir
mattdibi Sep 20, 2023
1f7ff52
fix: MANIFEST
mattdibi Sep 20, 2023
e7d1b66
fix: packages names
mattdibi Sep 20, 2023
d259d65
feat(distrib): add rest.packages bundle
mattdibi Sep 20, 2023
1f5660f
fix: wrong manifest
mattdibi Sep 20, 2023
f67ad4d
test: add org.eclipse.kura.rest.packages.provider.test
mattdibi Sep 20, 2023
4eede92
fix(test): unit tests
mattdibi Sep 20, 2023
78f18a7
fix(test): correct pid
mattdibi Sep 21, 2023
1e7f776
fix(test): fix PID once again
mattdibi Sep 21, 2023
2c1789f
fix(test): request correct component
mattdibi Sep 21, 2023
84f476e
style: add copyright headers
mattdibi Sep 21, 2023
fb63cbb
style(test): fix copyright headers
mattdibi Sep 21, 2023
0830cd2
feat: update URL deploy/v1 -> deploy/v2
mattdibi Sep 21, 2023
f98a5fd
chore: remove files committed by mistake
mattdibi Sep 21, 2023
107aa2a
refactor(test): remove old integration tests
mattdibi Sep 21, 2023
aad0f8a
test: first working version of integration tests
mattdibi Sep 21, 2023
3f1e695
test: remove unnecessary code
mattdibi Sep 21, 2023
9e419a1
refactor: rename ConfigurationRestServiceTest -> PackagesRestServiceTest
mattdibi Sep 21, 2023
f565bc8
test: fix typo
mattdibi Sep 21, 2023
4aec2c8
test: test with existing installed bundles
mattdibi Sep 21, 2023
c66b991
test: add debugging "verify"s
mattdibi Sep 26, 2023
b6acdfd
refactor(test): return mock instaed of building a class
mattdibi Sep 26, 2023
6735a38
fix(test): correctly inject DeploymentAdmin mock
mattdibi Sep 26, 2023
f8af018
test: fix mock reset
mattdibi Sep 26, 2023
05cc7ed
refactor(test): improve readability, remove unnecessary vars
mattdibi Sep 26, 2023
9376b39
refactor(test): use Gerkhin style
mattdibi Sep 26, 2023
4e54924
style: fix copyright header
mattdibi Sep 26, 2023
5a74f5c
refactor: add then* statement
mattdibi Sep 26, 2023
c6ff370
test: add uninstall tests
mattdibi Sep 26, 2023
9befb03
test: add more complete testing
mattdibi Sep 26, 2023
292358f
fix(build): add forgotten entry in test pom
mattdibi Sep 26, 2023
7da9d36
test: remove unused imports
mattdibi Sep 27, 2023
82f382d
fix(test): remove unnecessary throws statements
mattdibi Sep 27, 2023
0d58dfd
style: applied cleanup profile
mattdibi Sep 27, 2023
3d8c591
style: applied cleanup profile
mattdibi Sep 27, 2023
f889335
build: remove unnecessary dependencies
mattdibi Sep 27, 2023
0353075
style: apply cleanup profile
mattdibi Sep 27, 2023
3c9b7e8
build: removed unnecessary dependencies, fixed export
mattdibi Sep 27, 2023
969035a
build: tag api as internal
mattdibi Sep 27, 2023
7318a52
refactor: remove unnecessary resource
mattdibi Sep 27, 2023
f5fb705
style: fix indentations
mattdibi Sep 27, 2023
8a87cf3
test: use mocks instead of... whatever that was
mattdibi Sep 27, 2023
ca7d9d7
style: partial migration to Gerkhin style
mattdibi Sep 27, 2023
9954bfd
style: complete migration to Gerkhin style
mattdibi Sep 27, 2023
54eeef2
refactor: move methods to their section
mattdibi Sep 27, 2023
6331b73
refactor: rename method
mattdibi Sep 27, 2023
5c46f97
refactor: more readable test names
mattdibi Sep 27, 2023
3ffc9f3
style: fix formatting
mattdibi Sep 29, 2023
d674d88
refactor: remove unnecessary unbind methods
mattdibi Sep 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kura/distrib/config/kura.build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ org.eclipse.kura.log.filesystem.provider.version=1.3.0-SNAPSHOT
org.eclipse.kura.rest.configuration.provider.version=1.3.0-SNAPSHOT
org.eclipse.kura.rest.inventory.provider.version=1.0.0-SNAPSHOT
org.eclipse.kura.rest.command.provider.version=1.0.0-SNAPSHOT
org.eclipse.kura.rest.packages.provider.version=1.0.0-SNAPSHOT
org.eclipse.kura.rest.position.provider.version=1.0.0-SNAPSHOT
org.eclipse.kura.rest.security.provider.version=1.0.0-SNAPSHOT
org.eclipse.kura.rest.service.listing.provider.version=1.0.0-SNAPSHOT
Expand Down
7 changes: 7 additions & 0 deletions kura/distrib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,11 @@
<artifactId>org.eclipse.kura.rest.command.provider</artifactId>
<version>${org.eclipse.kura.rest.command.provider.version}</version>
</artifactItem>
<artifactItem>
<groupId>org.eclipse.kura</groupId>
<artifactId>org.eclipse.kura.rest.packages.provider</artifactId>
<version>${org.eclipse.kura.rest.packages.provider.version}</version>
</artifactItem>
<artifactItem>
<groupId>org.eclipse.kura</groupId>
<artifactId>org.eclipse.kura.rest.position.provider</artifactId>
Expand Down Expand Up @@ -820,6 +825,7 @@
<move file="target/plugins/org.eclipse.kura.rest.configuration.provider.jar" tofile="target/plugins/org.eclipse.kura.rest.configuration.provider_${org.eclipse.kura.rest.configuration.provider.version}.jar" />
<move file="target/plugins/org.eclipse.kura.rest.inventory.provider.jar" tofile="target/plugins/org.eclipse.kura.rest.inventory.provider_${org.eclipse.kura.rest.inventory.provider.version}.jar" />
<move file="target/plugins/org.eclipse.kura.rest.command.provider.jar" tofile="target/plugins/org.eclipse.kura.rest.command.provider_${org.eclipse.kura.rest.command.provider.version}.jar" />
<move file="target/plugins/org.eclipse.kura.rest.packages.provider.jar" tofile="target/plugins/org.eclipse.kura.rest.packages.provider_${org.eclipse.kura.rest.packages.provider.version}.jar" />
<move file="target/plugins/org.eclipse.kura.rest.position.provider.jar" tofile="target/plugins/org.eclipse.kura.rest.position.provider_${org.eclipse.kura.rest.position.provider.version}.jar" />
<move file="target/plugins/org.eclipse.kura.rest.security.provider.jar" tofile="target/plugins/org.eclipse.kura.rest.security.provider_${org.eclipse.kura.rest.security.provider.version}.jar" />
<move file="target/plugins/org.eclipse.kura.rest.service.listing.provider.jar" tofile="target/plugins/org.eclipse.kura.rest.service.listing.provider_${org.eclipse.kura.rest.service.listing.provider.version}.jar" />
Expand Down Expand Up @@ -2535,6 +2541,7 @@
<copy file="${project.build.directory}/plugins/org.eclipse.kura.rest.configuration.provider_${org.eclipse.kura.rest.configuration.provider.version}.jar" todir="${project.build.directory}/staging/target-definition/equinox_3.16.0/repository/plugins" />
<copy file="${project.build.directory}/plugins/org.eclipse.kura.rest.inventory.provider_${org.eclipse.kura.rest.inventory.provider.version}.jar" todir="${project.build.directory}/staging/target-definition/equinox_3.16.0/repository/plugins" />
<copy file="${project.build.directory}/plugins/org.eclipse.kura.rest.command.provider_${org.eclipse.kura.rest.command.provider.version}.jar" todir="${project.build.directory}/staging/target-definition/equinox_3.16.0/repository/plugins" />
<copy file="${project.build.directory}/plugins/org.eclipse.kura.rest.packages.provider_${org.eclipse.kura.rest.packages.provider.version}.jar" todir="${project.build.directory}/staging/target-definition/equinox_3.16.0/repository/plugins" />
<copy file="${project.build.directory}/plugins/org.eclipse.kura.rest.position.provider_${org.eclipse.kura.rest.position.provider.version}.jar" todir="${project.build.directory}/staging/target-definition/equinox_3.16.0/repository/plugins" />
<copy file="${project.build.directory}/plugins/org.eclipse.kura.rest.security.provider_${org.eclipse.kura.rest.security.provider.version}.jar" todir="${project.build.directory}/staging/target-definition/equinox_3.16.0/repository/plugins" />
<copy file="${project.build.directory}/plugins/org.eclipse.kura.rest.service.listing.provider_${org.eclipse.kura.rest.service.listing.provider.version}.jar" todir="${project.build.directory}/staging/target-definition/equinox_3.16.0/repository/plugins" />
Expand Down
5 changes: 5 additions & 0 deletions kura/distrib/src/main/ant/build_equinox_distrib.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,8 @@ fi]]>
value=", reference:file:${kura.install.dir}/${kura.symlink}/${plugins.folder}/org.eclipse.kura.rest.inventory.provider_${org.eclipse.kura.rest.inventory.provider.version}.jar@4:start" />
<entry key="osgi.bundles" operation="+"
value=", reference:file:${kura.install.dir}/${kura.symlink}/${plugins.folder}/org.eclipse.kura.rest.command.provider_${org.eclipse.kura.rest.command.provider.version}.jar@4:start" />
<entry key="osgi.bundles" operation="+"
value=", reference:file:${kura.install.dir}/${kura.symlink}/${plugins.folder}/org.eclipse.kura.rest.packages.provider_${org.eclipse.kura.rest.packages.provider.version}.jar@4:start" />
<entry key="osgi.bundles" operation="+"
value=", reference:file:${kura.install.dir}/${kura.symlink}/${plugins.folder}/org.eclipse.kura.rest.position.provider_${org.eclipse.kura.rest.position.provider.version}.jar@4:start" />
<entry key="osgi.bundles" operation="+"
Expand Down Expand Up @@ -1415,6 +1417,9 @@ fi]]>
<zipfileset
file="${project.build.directory}/plugins/org.eclipse.kura.rest.command.provider_${org.eclipse.kura.rest.command.provider.version}.jar"
prefix="${build.output.name}/${plugins.folder}" />
<zipfileset
file="${project.build.directory}/plugins/org.eclipse.kura.rest.packages.provider_${org.eclipse.kura.rest.packages.provider.version}.jar"
prefix="${build.output.name}/${plugins.folder}" />
<zipfileset
file="${project.build.directory}/plugins/org.eclipse.kura.rest.position.provider_${org.eclipse.kura.rest.position.provider.version}.jar"
prefix="${build.output.name}/${plugins.folder}" />
Expand Down
22 changes: 22 additions & 0 deletions kura/org.eclipse.kura.rest.packages.provider/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Kura Deployment Packages Rest Provider
Bundle-SymbolicName: org.eclipse.kura.rest.packages.provider;singleton:=true
Bundle-Version: 1.0.0.qualifier
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))"
Bundle-ClassPath: .
Bundle-ActivationPolicy: lazy
Service-Component: OSGI-INF/*.xml
Import-Package: com.google.gson;version="2.7.0",
javax.annotation.security;version="1.2.0",
javax.ws.rs;version="2.0.1",
javax.ws.rs.core;version="2.0.1",
javax.ws.rs.ext;version="2.0.1",
org.eclipse.kura;version="[1.3,2.0)",
org.eclipse.kura.deployment.agent;version="[1.0,2.0)",
org.osgi.framework;version="1.8.0",
org.osgi.service.component;version="1.3.0",
org.osgi.service.deploymentadmin;version="1.0.0",
org.osgi.service.useradmin;version="1.1.0";resolution:=optional,
org.slf4j;version="1.7.21"
Export-Package: org.eclipse.kura.rest.deployment.agent.api;version="1.0.0";x-internal:=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (c) 2023 Eurotech and/or its affiliates and others

This program and the accompanying materials are made
available under the terms of the Eclipse Public License 2.0
which is available at https://www.eclipse.org/legal/epl-2.0/

SPDX-License-Identifier: EPL-2.0

Contributors:
Eurotech

-->
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.kura.rest.deployment.agent.DeploymentRestService">
<implementation class="org.eclipse.kura.internal.rest.deployment.agent.DeploymentRestService"/>
<property name="kura.service.pid" type="String" value="org.eclipse.kura.rest.deployment.agent.DeploymentRestService"/>
<service>
<provide interface="org.eclipse.kura.internal.rest.deployment.agent.DeploymentRestService"/>
</service>
<reference name="DeploymentAgentService"
cardinality="1..1"
interface="org.eclipse.kura.deployment.agent.DeploymentAgentService"
bind="setDeploymentAgentService"
policy="static"/>
<reference name="DeploymentAdmin"
cardinality="1..1"
interface="org.osgi.service.deploymentadmin.DeploymentAdmin"
bind="setDeploymentAdmin"
policy="static"/>
<reference name="UserAdmin"
cardinality="0..1"
interface="org.osgi.service.useradmin.UserAdmin"
bind="setUserAdmin"
policy="static"/>
</scr:component>
17 changes: 17 additions & 0 deletions kura/org.eclipse.kura.rest.packages.provider/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# Copyright (c) 2023 Eurotech and/or its affiliates and others
#
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Eurotech
#
output.. = target/classes
bin.includes = .,\
META-INF/,\
OSGI-INF/
source.. = src/main/java/
35 changes: 35 additions & 0 deletions kura/org.eclipse.kura.rest.packages.provider/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (c) 2023 Eurotech and/or its affiliates and others

This program and the accompanying materials are made
available under the terms of the Eclipse Public License 2.0
which is available at https://www.eclipse.org/legal/epl-2.0/

SPDX-License-Identifier: EPL-2.0

Contributors:
Eurotech

-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.eclipse.kura</groupId>
<artifactId>kura</artifactId>
<version>5.4.0-SNAPSHOT</version>
</parent>

<properties>
<kura.basedir>${project.basedir}/..</kura.basedir>
<sonar.coverage.jacoco.xmlReportPaths>
${project.basedir}/../test/*/target/site/jacoco-aggregate/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
</properties>

<artifactId>org.eclipse.kura.rest.packages.provider</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*******************************************************************************
* Copyright (c) 2023 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Eurotech
*******************************************************************************/
package org.eclipse.kura.internal.rest.deployment.agent;

public class DeploymentPackageInfo {

private final String name;
private final String version;

public DeploymentPackageInfo(String name, String version) {
this.name = name;
this.version = version;
}

public String getName() {
return this.name;
}

public String getVersion() {
return this.version;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/*******************************************************************************
* Copyright (c) 2023 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Eurotech
*******************************************************************************/
package org.eclipse.kura.internal.rest.deployment.agent;

import static org.eclipse.kura.rest.deployment.agent.api.Validable.validate;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.annotation.security.RolesAllowed;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.eclipse.kura.deployment.agent.DeploymentAgentService;
import org.eclipse.kura.rest.deployment.agent.api.DeploymentRequestStatus;
import org.eclipse.kura.rest.deployment.agent.api.InstallRequest;
import org.osgi.service.deploymentadmin.DeploymentAdmin;
import org.osgi.service.deploymentadmin.DeploymentPackage;
import org.osgi.service.useradmin.Role;
import org.osgi.service.useradmin.UserAdmin;

@Path("/deploy/v2")
public class DeploymentRestService {

private static final String KURA_PERMISSION_REST_DEPLOY_ROLE = "kura.permission.rest.deploy";
private static final String ERROR_INSTALLING_PACKAGE = "Error installing deployment package: ";
private static final String ERROR_UNINSTALLING_PACKAGE = "Error uninstalling deployment package: ";
private static final String BAD_REQUEST_MESSAGE = "Bad request";

private DeploymentAdmin deploymentAdmin;
private DeploymentAgentService deploymentAgentService;
private UserAdmin userAdmin;

public void setUserAdmin(UserAdmin userAdmin) {
this.userAdmin = userAdmin;
this.userAdmin.createRole(KURA_PERMISSION_REST_DEPLOY_ROLE, Role.GROUP);
}

public void setDeploymentAdmin(DeploymentAdmin deploymentAdmin) {
this.deploymentAdmin = deploymentAdmin;
}

public void setDeploymentAgentService(DeploymentAgentService deploymentAgentService) {
this.deploymentAgentService = deploymentAgentService;
}

/**
* GET method.
*
* Provides the list of all the deployment packages installed and tracked by the framework.
*
* @return a list of {@link DeploymentPackageInfo}
*/
@GET
@RolesAllowed("deploy")
@Produces(MediaType.APPLICATION_JSON)
public List<DeploymentPackageInfo> listDeploymentPackages() {

List<DeploymentPackageInfo> deploymentPackageInfos = new ArrayList<>();
List<DeploymentPackage> deploymentPackages = Arrays.asList(this.deploymentAdmin.listDeploymentPackages());

deploymentPackages.forEach(
dp -> deploymentPackageInfos.add(new DeploymentPackageInfo(dp.getName(), dp.getVersion().toString())));

return deploymentPackageInfos;
}

/**
* POST method.
*
* Installs the deployment package specified in the {@link InstallRequest}. If the request was already issued for
* the same {@link InstallRequest}, it returns the status of the installation process.
*
* @param installRequest
* @return a {@link DeploymentRequestStatus} object that represents the status of the installation request
*/
@POST
@RolesAllowed("deploy")
@Path("/_install")
@Produces(MediaType.APPLICATION_JSON)
public DeploymentRequestStatus installDeploymentPackage(InstallRequest installRequest) {
validate(installRequest, BAD_REQUEST_MESSAGE);
String url = installRequest.getUrl();

if (this.deploymentAgentService.isInstallingDeploymentPackage(url)) {
return DeploymentRequestStatus.INSTALLING;
}

try {
this.deploymentAgentService.installDeploymentPackageAsync(url);
} catch (Exception e) {
throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.type(MediaType.TEXT_PLAIN).entity(ERROR_INSTALLING_PACKAGE + url).build());
}

return DeploymentRequestStatus.REQUEST_RECEIVED;
}

/**
* DELETE method.
*
* Uninstalls the deployment package identified by the specified name. If the request was already issued, it reports
* the status of the uninstallation operation.
*
* @param name
* @return a {@link DeploymentRequestStatus} object that represents the status of the uninstallation request
*/
@DELETE
@RolesAllowed("deploy")
@Path("/{name}")
@Produces(MediaType.APPLICATION_JSON)
public DeploymentRequestStatus uninstallDeploymentPackage(@PathParam("name") String name) {
if (this.deploymentAgentService.isUninstallingDeploymentPackage(name)) {
return DeploymentRequestStatus.UNINSTALLING;
}
try {
this.deploymentAgentService.uninstallDeploymentPackageAsync(name);
} catch (Exception e) {
throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.type(MediaType.TEXT_PLAIN).entity(ERROR_UNINSTALLING_PACKAGE + name).build());
}

return DeploymentRequestStatus.REQUEST_RECEIVED;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*******************************************************************************
* Copyright (c) 2023 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Eurotech
*******************************************************************************/
package org.eclipse.kura.rest.deployment.agent.api;

/**
* Enumeration representing the status of the deployment requests received via REST.
*
*/
public enum DeploymentRequestStatus {
REQUEST_RECEIVED,
INSTALLING,
UNINSTALLING;
}
Loading