Skip to content

Commit

Permalink
Refactored 'character.encoding' in 'device.management.character.encod…
Browse files Browse the repository at this point in the history
…ing'

Signed-off-by: Alberto Codutti <alberto.codutti@eurotech.com>
  • Loading branch information
Coduz committed Jan 26, 2021
1 parent 0abfc3b commit d99722d
Show file tree
Hide file tree
Showing 16 changed files with 80 additions and 146 deletions.
1 change: 1 addition & 0 deletions assembly/api/docker/Dockerfile
Expand Up @@ -37,6 +37,7 @@ ENV JAVA_OPTS "-Dcommons.db.schema.update=true \
-Dcertificate.jwt.private.key=file:///var/opt/jetty/key.pk8 \
-Dcertificate.jwt.certificate=file:///var/opt/jetty/cert.pem \
-Ddatastore.disable=\${KAPUA_DISABLE_DATASTORE:-false} \
-Ddevice.management.response.stacktrace.show=\${DEVICE_MANAGEMENT_RESPONSE_STACKTRACE_SHOW:-false} \
-Djavax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory"

USER 0
Expand Down
4 changes: 4 additions & 0 deletions assembly/console/entrypoint/run-console
Expand Up @@ -59,6 +59,10 @@ test -n "${MFA_SCRATCH_CODES_NUMBER}" && JAVA_OPTS="${JAVA_OPTS} -Dauthenticatio
test -n "${MFA_CODE_DIGITS_NUMBER}" && JAVA_OPTS="${JAVA_OPTS} -Dauthentication.mfa.code.digits.number=${MFA_CODE_DIGITS_NUMBER}"
test -n "${MFA_TRUST_KEY_DURATION}" && JAVA_OPTS="${JAVA_OPTS} -Dauthentication.mfa.trust.key.duration=${MFA_TRUST_KEY_DURATION}"

# Device Mannagement Configurations
: DEVICE_MANAGEMENT_RESPONSE_STACKTRACE_SHOW=${DEVICE_MANAGEMENT_RESPONSE_STACKTRACE_SHOW:=false }
test -n "${DEVICE_MANAGEMENT_RESPONSE_STACKTRACE_SHOW}" && JAVA_OPTS="${JAVA_OPTS} -Ddevice.management.response.stacktrace.show${DEVICE_MANAGEMENT_RESPONSE_STACKTRACE_SHOW}"

export JAVA_OPTS

# Continue with startup
Expand Down
51 changes: 11 additions & 40 deletions deployment/minishift/README.md
@@ -1,7 +1,6 @@
# Kapua on Minishift

To learn more on how to run Kapua in Minishift, please
consult [developer manual](https://github.com/eclipse/kapua/blob/develop/docs/developer-guide/en/running.md#minishift).
To learn more on how to run Kapua in Minishift, please consult [developer manual](https://github.com/eclipse/kapua/blob/develop/docs/developer-guide/en/running.md#minishift).

The most recent version of the documentation can be viewed online at:

Expand All @@ -14,122 +13,94 @@ You are required to have _Docker_, _Minishift_ and _VirtualBox_ installed.<br>
VirtualBox will be used as VM driver for Minishift.

### Fetching Docker images

You'll need to have the images on your local Docker registry.<br>
You can pull them from a Docker registry or build them from the code.

If you choose to build them from the code please go
to [Building containers from scratch](#Building-containers-from-scratch) section.
If you choose to build them from the code please go to [Building containers from scratch](#Building-containers-from-scratch) section.

If you want to pull them from a Docker registry, run:

```bash
./minishift-pull-images.sh
```

### Running

First, you need the create and start the Minishift VM.<br>
Run:

```bash
./minishift-initialize.sh
```

This script will set _VirtualBox_ as VM driver of Minishift and start a Minishift VM with 6GB of RAM, 3 CPUs and 20GB of
storage.
This script will set _VirtualBox_ as VM driver of Minishift and start a Minishift VM with 6GB of RAM, 3 CPUs and 20GB of storage.

After the Minishift VM has started you can deploy the Kapua components by running:

```bash
./minishift-deploy.sh
```

This script will create new apps for each Kapua component.

### Accessing components

After deployment and startup of containers, they can be accessed at the following endpoints

| Application/Service | Endpoint | User | Password | Others |
|---------------------|--------------------------------------------------|--------------|----------------|-----------------------------------|
| H2 SQL | _None_ | _None_ | _
None_ | This service is not exposed |
| Elasticsearch | _None_ | _None_ | _
None_ | This service is not exposed |
| H2 SQL | _None_ | _None_ | _None_ | This service is not exposed |
| Elasticsearch | _None_ | _None_ | _None_ | This service is not exposed |
| Broker | broker-eclipse-kapua.192.168.99.100.nip.io:31883 | kapua-broker | kapua-password | |
| Admin WEB Console | console-eclipse-kapua.192.168.99.100.nip.io:80 | kapua-sys | kapua-password | |
| REST API endpoint | api-eclipse-kapua.192.168.99.100.nip.io:80 | kapua-sys | kapua-password | API KEY: `12345678kapua-password` |

Please note that endpoints are available only from the host machine.

### Checking

You can check the status of the pods using the OpenShift Client from the command line or accessing the OpenShift Web
Console.
You can check the status of the pods using the OpenShift Client from the command line or accessing the OpenShift Web Console.

To access the OpenShift Web Console you can run:

```bash
minishift dashboard
```

### Tear down

To stop and remove the Eclipse Kapua project from OpenShift, run:

```bash
./minishift-undeploy.sh
```

This command can take a while to be executed. Even if the `Eclipse Kapua` project has disappeared, processing still
going on underneath.
This command can take a while to be executed. Even if the `Eclipse Kapua` project has disappeared, processing still going on underneath.

To destroy the Minishift VM, runL

```bash
./minishift-destroy.sh
```

### Advanced options

#### Setting the Kapua version

Other than the default deployment it is possible to run other versions of Kapua.

By default the `latest` version of Kapua will be brought up. You can change the version of Kapua by exporting the
environment variable `IMAGE_VERSION`.
By default the `latest` version of Kapua will be brought up.
You can change the version of Kapua by exporting the environment variable `IMAGE_VERSION`.

Example:

```bash
export IMAGE_VERSION=1.0.0
```

#### Passing additional JAVA_OPTS

If you want to pass to the JVM additional optional parameters you can set the `JAVA_OPTS_EXTRA` environment
variable.<br>
If you want to pass to the JVM additional optional parameters you can set the `JAVA_OPTS_EXTRA` environment variable.<br>
Example:

```bash
export JAVA_OPTS_EXTRA="-Ddevice.management.request.timeout=60000"
```

#### Building containers from scratch

If you want to build containers from the code, you'll need to build the whole Kapua Project.

From the project root directory, run:

```bash
mvn clean install -Pdocker
```

To build also the Admin Web Console container, which is excluded by default, add the `console` profile:

```bash
mvn clean install -Pconsole,docker
```

After the build has completed follow the steps from the [Running](#Running) section.
After the build has completed follow the steps from the [Running](#Running) section.
41 changes: 9 additions & 32 deletions deployment/openshift/README.md
@@ -1,7 +1,6 @@
# Kapua on OpenShift

To learn more on how to run Kapua in Openshift, please
consult [developer manual](https://github.com/eclipse/kapua/blob/develop/docs/developer-guide/en/running.md#openshift).
To learn more on how to run Kapua in Openshift, please consult [developer manual](https://github.com/eclipse/kapua/blob/develop/docs/developer-guide/en/running.md#openshift).

The most recent version of the documentation can be viewed online at:

Expand All @@ -11,104 +10,82 @@ The most recent version of the documentation can be viewed online at:
## How to run Kapua on OpenShift.

You are required to have OpenShift Origin installed.<br>
If you are running on MacOS or Windows machine, please go to the _Minishift_ deployment. OpenShift Origin is supported
only on Linux OSs.
If you are running on MacOS or Windows machine, please go to the _Minishift_ deployment.
OpenShift Origin is supported only on Linux OSs.

### Running

First, you need the OpenShift client and a OpenShift Origin cluster running.<br>
Just run:

```bash
./openshift-start.sh
```

This script will download the OpenShift Client and start the OpenShift cluster.

Then you need to initialize the OpenShift Cluster by running:

```bash
./openshift-initialize.sh
```

This script will create a new project into OpenShift.

Final step of the deployment, is the deployment of the Docker images themself.<br>
Run:

```bash
./openshift-deploy.sh
```

This script will create new apps for each Kapua component.

### Accessing components

After deployment and startup of containers, they can be accessed at the following endpoints

| Application/Service | Endpoint | User | Password | Others |
|---------------------|-------------------------------------------------------|--------------|----------------|-----------------------------------|
| H2 SQL | _None_ | _None_ | _
None_ | This service is not exposed |
| Elasticsearch | _None_ | _None_ | _
None_ | This service is not exposed |
| H2 SQL | _None_ | _None_ | _None_ | This service is not exposed |
| Elasticsearch | _None_ | _None_ | _None_ | This service is not exposed |
| Broker | broker-eclipse-kapua.<openshift-default-domain>:31883 | kapua-broker | kapua-password | |
| Admin WEB Console | console-eclipse-kapua.<openshift-default-domain>:80 | kapua-sys | kapua-password | |
| REST API endpoint | api-eclipse-kapua.<openshift-default-domain>:80 | kapua-sys | kapua-password | API KEY: `12345678kapua-password` |

### Checking
You can check the status of the pods using the OpenShift Client from the command line or accessing the OpenShift Web Console.

You can check the status of the pods using the OpenShift Client from the command line or accessing the OpenShift Web
Console.

### Tear down

To stop and remove the Eclipse Kapua project from OpenShift, run:

```bash
./openshift-destroy.sh
```

After this command, you'll need to run again `./openshift-initialize.sh` if you want to deploy again Kapua.

### Advanced options

#### Setting the Kapua version

Other than the default deployment it is possible to run other versions of Kapua.

By default the `latest` version of Kapua will be brought up. You can change the version of Kapua by exporting the
environment variable `IMAGE_VERSION`.
By default the `latest` version of Kapua will be brought up.
You can change the version of Kapua by exporting the environment variable `IMAGE_VERSION`.

Example:

```bash
export IMAGE_VERSION=1.0.0
```

#### Passing additional JAVA_OPTS

If you want to pass to the JVM additional optional parameters you can set the `JAVA_OPTS_EXTRA` environment
variable.<br>
If you want to pass to the JVM additional optional parameters you can set the `JAVA_OPTS_EXTRA` environment variable.<br>
Example:

```bash
export JAVA_OPTS_EXTRA="-Ddevice.management.request.timeout=60000"
```

#### Building containers from scratch

If you want to build containers from the code, you'll need to build the whole Kapua Project.

From the project root directory, run:

```bash
mvn clean install -f external/pom.xml
mvn clean install -Pdocker
```

To build also the Admin Web Console container, which is excluded by default, add the `console` profile:

```bash
mvn clean install -f external/pom.xml
mvn clean install -Pconsole,docker
Expand Down
Expand Up @@ -26,7 +26,7 @@ public enum DeviceManagementSettingKey implements SettingKey {
*
* @since 1.0.0
*/
CHAR_ENCODING("character.encoding"),
CHAR_ENCODING("device.management.character.encoding"),

/**
* Request timeout.
Expand Down
Expand Up @@ -11,7 +11,7 @@
# Eurotech - initial API and implementation
#
###############################################################################
character.encoding=UTF-8
device.management.character.encoding=UTF-8

device.management.request.timeout=30000

Expand Down
Expand Up @@ -35,8 +35,8 @@
public class AssetRequestPayload extends KapuaPayloadImpl implements KapuaRequestPayload {

private static final DeviceAssetFactory DEVICE_ASSET_FACTORY = KapuaLocator.getInstance().getFactory(DeviceAssetFactory.class);
private static final DeviceManagementSetting CONFIG = DeviceManagementSetting.getInstance();
private static final String CHAR_ENCODING = CONFIG.getString(DeviceManagementSettingKey.CHAR_ENCODING);

private static final String CHAR_ENCODING = DeviceManagementSetting.getInstance().getString(DeviceManagementSettingKey.CHAR_ENCODING);

public DeviceAssets getDeviceAssets() throws JAXBException, XMLStreamException, FactoryConfigurationError, SAXException, UnsupportedEncodingException {
DeviceAssets deviceAssets = DEVICE_ASSET_FACTORY.newAssetListResult();
Expand Down
Expand Up @@ -35,8 +35,8 @@
public class AssetResponsePayload extends KapuaResponsePayloadImpl implements KapuaResponsePayload {

private static final DeviceAssetFactory DEVICE_ASSET_FACTORY = KapuaLocator.getInstance().getFactory(DeviceAssetFactory.class);
private static final DeviceManagementSetting CONFIG = DeviceManagementSetting.getInstance();
private static final String CHAR_ENCODING = CONFIG.getString(DeviceManagementSettingKey.CHAR_ENCODING);

private static final String CHAR_ENCODING = DeviceManagementSetting.getInstance().getString(DeviceManagementSettingKey.CHAR_ENCODING);

public DeviceAssets getDeviceAssets() throws JAXBException, XMLStreamException, FactoryConfigurationError, SAXException, UnsupportedEncodingException {
DeviceAssets deviceAssets = DEVICE_ASSET_FACTORY.newAssetListResult();
Expand Down
Expand Up @@ -50,6 +50,8 @@ public class DeviceBundleManagementServiceImpl extends AbstractDeviceManagementS
private static final String SCOPE_ID = "scopeId";
private static final String DEVICE_ID = "deviceId";

private static final String CHAR_ENCODING = DeviceManagementSetting.getInstance().getString(DeviceManagementSettingKey.CHAR_ENCODING);

@Override
public DeviceBundles get(KapuaId scopeId, KapuaId deviceId, Long timeout)
throws KapuaException {
Expand Down Expand Up @@ -92,17 +94,14 @@ public DeviceBundles get(KapuaId scopeId, KapuaId deviceId, Long timeout)
if (responseMessage.getResponseCode().isAccepted()) {
BundleResponsePayload responsePayload = responseMessage.getPayload();

DeviceManagementSetting config = DeviceManagementSetting.getInstance();
String charEncoding = config.getString(DeviceManagementSettingKey.CHAR_ENCODING);

String body = null;
String body;
try {
body = new String(responsePayload.getBody(), charEncoding);
body = new String(responsePayload.getBody(), CHAR_ENCODING);
} catch (Exception e) {
throw new DeviceManagementResponseException(e, responsePayload.getBody());
}

DeviceBundles deviceBundleList = null;
DeviceBundles deviceBundleList;
try {
deviceBundleList = XmlUtil.unmarshal(body, DeviceBundlesImpl.class);
} catch (Exception e) {
Expand Down

0 comments on commit d99722d

Please sign in to comment.