Skip to content

Commit

Permalink
Bug 568632 Implement feature grant acquire/release
Browse files Browse the repository at this point in the history
Implement license release request

Signed-off-by: eparovyshnaya <[email protected]>
  • Loading branch information
eparovyshnaya committed Nov 12, 2020
1 parent 148b4e5 commit 47b0024
Show file tree
Hide file tree
Showing 10 changed files with 223 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public interface Request<R> {

URL url() throws LicensingException;

Configuration<R> config();
Configuration<R> config() throws LicensingException;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*******************************************************************************
* Copyright (c) 2020 ArSysOp
*
* 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:
* ArSysOp - initial API and implementation
*******************************************************************************/
package org.eclipse.passage.lic.internal.hc.remote.impl;

import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.ProtocolException;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;

import org.eclipse.passage.lic.internal.hc.remote.Configuration;

public abstract class BaseConfiguration implements Configuration<HttpURLConnection> {

private final int timeout;
private final Map<String, String> properties;

protected BaseConfiguration(int timeout, Map<String, String> properties) {
Objects.requireNonNull(properties, "BaseConfiguration::properties"); //$NON-NLS-1$
this.timeout = timeout;
this.properties = properties;
}

protected BaseConfiguration(Map<String, String> properties) {
this(1000, properties);
}

protected BaseConfiguration() {
this(Collections.emptyMap());
}

@Override
public final HttpURLConnection apply(HttpURLConnection connection) throws Exception {
installRequestDemands(connection);
installRequestProperties(connection);
paveRoadForData(connection);
return connection;
}

private void installRequestDemands(HttpURLConnection connection) throws Exception {
connection.setConnectTimeout(timeout);
}

protected abstract void paveRoadForData(HttpURLConnection connection) throws Exception;

private void installRequestProperties(HttpURLConnection connection) {
properties.forEach((k, v) -> connection.addRequestProperty(k, v));
}

public static final class Get extends BaseConfiguration {

public Get(int timeout, Map<String, String> properties) {
super(timeout, properties);
}

public Get(Map<String, String> properties) {
super(properties);
}

public Get() {
super();
}

@Override
protected void paveRoadForData(HttpURLConnection connection) throws ProtocolException {
connection.setRequestMethod("GET"); //$NON-NLS-1$
connection.setDoOutput(true);
}

}

public static final class Post extends BaseConfiguration {

private final byte[] payload;

public Post(int timeout, Map<String, String> properties, byte[] payload) {
super(timeout, properties);
this.payload = payload;
}

public Post(Map<String, String> properties, byte[] payload) {
super(properties);
this.payload = payload;
}

public Post(byte[] payload) {
this.payload = payload;
}

@Override
protected void paveRoadForData(HttpURLConnection connection) throws Exception {
connection.setRequestMethod("PUT"); //$NON-NLS-1$
connection.setDoOutput(false);
connection.setDoInput(true);
try (OutputStream output = connection.getOutputStream()) {
output.write(payload);
}
}

}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;

import org.eclipse.passage.lic.floating.model.api.FloatingLicenseAccess;
import org.eclipse.passage.lic.internal.api.LicensedProduct;
import org.eclipse.passage.lic.internal.api.LicensingException;
import org.eclipse.passage.lic.internal.hc.i18n.HcMessages;
import org.eclipse.passage.lic.internal.hc.remote.Configuration;
import org.eclipse.passage.lic.internal.hc.remote.Request;
import org.eclipse.passage.lic.internal.net.HostPort;

Expand Down Expand Up @@ -61,11 +59,6 @@ public URL url() throws LicensingException {
}
}

@Override
public Configuration<HttpURLConnection> config() {
return new HttpUrlConnectionConfiguration(1000, new HashMap<>());
}

protected abstract RequestParameters parameters();

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final class ReleaseRequestParameters extends RequestParameters {

@Override
protected ConditionAction action() {
return new ConditionAction.Acquire();
return new ConditionAction.Release();
}

@SuppressWarnings("rawtypes")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (c) 2020 ArSysOp
*
* 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:
* ArSysOp - initial API and implementation
*******************************************************************************/
package org.eclipse.passage.lic.internal.hc.remote.impl.acquire;

import org.eclipse.passage.lic.internal.api.LicensedProduct;
import org.eclipse.passage.lic.internal.api.acquire.GrantAcqisition;
import org.eclipse.passage.lic.internal.hc.remote.impl.RemoteServiceData;

final class ReleaseServiceData extends RemoteServiceData {
private GrantAcqisition acqisition;

ReleaseServiceData(LicensedProduct product, GrantAcqisition acqisition) {
super(product);
this.acqisition = acqisition;
}

GrantAcqisition acqisition() {
return acqisition;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,22 @@
*******************************************************************************/
package org.eclipse.passage.lic.internal.hc.remote.impl.acquire;

import java.net.HttpURLConnection;

import org.eclipse.passage.lic.floating.model.api.FloatingLicenseAccess;
import org.eclipse.passage.lic.floating.model.convert.PGrantAcquisition;
import org.eclipse.passage.lic.internal.api.LicensingException;
import org.eclipse.passage.lic.internal.api.acquire.GrantAcqisition;
import org.eclipse.passage.lic.internal.api.io.KeyKeeperRegistry;
import org.eclipse.passage.lic.internal.api.io.StreamCodecRegistry;
import org.eclipse.passage.lic.internal.hc.remote.Configuration;
import org.eclipse.passage.lic.internal.hc.remote.ResponseHandler;
import org.eclipse.passage.lic.internal.hc.remote.impl.BaseConfiguration;
import org.eclipse.passage.lic.internal.hc.remote.impl.EObjectFromXmiResponse;
import org.eclipse.passage.lic.internal.hc.remote.impl.RemoteRequest;
import org.eclipse.passage.lic.internal.hc.remote.impl.RemoteServiceData;
import org.eclipse.passage.lic.internal.hc.remote.impl.RemoteServiceData.OfFeature;
import org.eclipse.passage.lic.internal.hc.remote.impl.RequestParameters;
import org.eclipse.passage.lic.internal.hc.remote.impl.ServiceAny;

final class RemoteAcquire extends ServiceAny<GrantAcqisition, RemoteServiceData.OfFeature> {
Expand All @@ -33,21 +38,20 @@ final class RemoteAcquire extends ServiceAny<GrantAcqisition, RemoteServiceData.

@Override
protected RemoteRequest request(OfFeature params, FloatingLicenseAccess access) {
return new OfFeatureRequest(params, access, //
(data, server) -> new AcquireRequestParameters(data.product(), data.feature(), server));
return new Request(params, access);
}

@Override
protected ResponseHandler<GrantAcqisition> handler(FloatingLicenseAccess access) {
return new AcquireResponseHandler(//
return new Response(
new EObjectFromXmiResponse<>(org.eclipse.passage.lic.floating.model.api.GrantAcqisition.class));
}

private final static class AcquireResponseHandler implements ResponseHandler<GrantAcqisition> {
private final static class Response implements ResponseHandler<GrantAcqisition> {

private final ResponseHandler<org.eclipse.passage.lic.floating.model.api.GrantAcqisition> delegate;

private AcquireResponseHandler(
ResponseHandler<org.eclipse.passage.lic.floating.model.api.GrantAcqisition> delegate) {
private Response(ResponseHandler<org.eclipse.passage.lic.floating.model.api.GrantAcqisition> delegate) {
this.delegate = delegate;
}

Expand All @@ -61,4 +65,26 @@ private GrantAcqisition apiGrant(org.eclipse.passage.lic.floating.model.api.Gran
}

}

private final class Request extends RemoteRequest {

private final OfFeature data;

Request(OfFeature data, FloatingLicenseAccess access) {
super(data.product(), access);
this.data = data;
}

@Override
protected RequestParameters parameters() {
return new AcquireRequestParameters(data.product(), data.feature(), access);
}

@Override
public Configuration<HttpURLConnection> config() {
return new BaseConfiguration.Get();
}

}

}
Loading

0 comments on commit 47b0024

Please sign in to comment.