-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rest.packages.provider): add
deploy/v2
Rest API (#4868)
* feat: add sources WARNING: Build is still broken * fix: kura.basedir WARNING: build still broken * fix: MANIFEST * fix: packages names * feat(distrib): add rest.packages bundle * fix: wrong manifest * test: add org.eclipse.kura.rest.packages.provider.test WARNING: Failing * fix(test): unit tests * fix(test): correct pid * fix(test): fix PID once again * fix(test): request correct component * style: add copyright headers * style(test): fix copyright headers * feat: update URL deploy/v1 -> deploy/v2 * chore: remove files committed by mistake * refactor(test): remove old integration tests * test: first working version of integration tests * test: remove unnecessary code * refactor: rename ConfigurationRestServiceTest -> PackagesRestServiceTest * test: fix typo * test: test with existing installed bundles WARNING: Passing even if it shouldn't * test: add debugging "verify"s * refactor(test): return mock instaed of building a class * fix(test): correctly inject DeploymentAdmin mock * test: fix mock reset * refactor(test): improve readability, remove unnecessary vars * refactor(test): use Gerkhin style * style: fix copyright header * refactor: add then* statement * test: add uninstall tests * test: add more complete testing * fix(build): add forgotten entry in test pom * test: remove unused imports * fix(test): remove unnecessary throws statements * style: applied cleanup profile * style: applied cleanup profile * build: remove unnecessary dependencies * style: apply cleanup profile * build: removed unnecessary dependencies, fixed export * build: tag api as internal * refactor: remove unnecessary resource * style: fix indentations * test: use mocks instead of... whatever that was * style: partial migration to Gerkhin style * style: complete migration to Gerkhin style * refactor: move methods to their section * refactor: rename method * refactor: more readable test names * style: fix formatting * refactor: remove unnecessary unbind methods
- Loading branch information
Showing
19 changed files
with
1,045 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
kura/org.eclipse.kura.rest.packages.provider/META-INF/MANIFEST.MF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
37 changes: 37 additions & 0 deletions
37
kura/org.eclipse.kura.rest.packages.provider/OSGI-INF/deployment_rest_service.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
17
kura/org.eclipse.kura.rest.packages.provider/build.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
33 changes: 33 additions & 0 deletions
33
.../src/main/java/org/eclipse/kura/internal/rest/deployment/agent/DeploymentPackageInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
143 changes: 143 additions & 0 deletions
143
.../src/main/java/org/eclipse/kura/internal/rest/deployment/agent/DeploymentRestService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...der/src/main/java/org/eclipse/kura/rest/deployment/agent/api/DeploymentRequestStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.