Skip to content

Commit

Permalink
Merge pull request #546 from eclipse-passage/568632-3
Browse files Browse the repository at this point in the history
Bug 568632 Implement feature grant acquire/release
  • Loading branch information
eparovyshnaya authored Nov 12, 2020
2 parents e38827c + ea3b6ed commit 7219a59
Show file tree
Hide file tree
Showing 12 changed files with 219 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

public interface LicenseAcquisitionService extends Service<ConditionMiningTarget> {

ServiceInvocationResult<Boolean> acquire(LicensedProduct product, String feature);
ServiceInvocationResult<GrantAcqisition> acquire(LicensedProduct product, String feature);

ServiceInvocationResult<Boolean> release(LicensedProduct product, String feature);
ServiceInvocationResult<Boolean> release(LicensedProduct product, GrantAcqisition acquisition);

}
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ public URL url() throws LicensingException {
}
}

protected abstract RequestParameters parameters();

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

protected abstract RequestParameters parameters();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*******************************************************************************
* 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.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.eclipse.passage.lic.floating.model.api.FloatingLicenseAccess;
import org.eclipse.passage.lic.internal.api.ServiceInvocationResult;
import org.eclipse.passage.lic.internal.api.diagnostic.Diagnostic;
import org.eclipse.passage.lic.internal.api.io.KeyKeeperRegistry;
import org.eclipse.passage.lic.internal.api.io.StreamCodecRegistry;
import org.eclipse.passage.lic.internal.base.BaseServiceInvocationResult;
import org.eclipse.passage.lic.internal.base.diagnostic.BaseDiagnostic;
import org.eclipse.passage.lic.internal.base.diagnostic.NoSevereErrors;
import org.eclipse.passage.lic.internal.base.diagnostic.SumOfDiagnostics;

public abstract class ServiceAny<T, D extends RemoteServiceData> extends ServiceRemote<T, D> {

protected ServiceAny(KeyKeeperRegistry keys, StreamCodecRegistry codecs) {
super(keys, codecs);
}

@Override
protected final ServiceInvocationResult<T> withServers(D parameters, Collection<FloatingLicenseAccess> servers) {
List<Diagnostic> diagnostics = new ArrayList<>();
return servers.stream()//
.map(server -> withServer(parameters, server))//
.peek(result -> diagnostics.add(result.diagnostic())) //
.filter(result -> new NoSevereErrors().test(result.diagnostic()))//
.filter(result -> result.data().isPresent())//
.findFirst()//
.orElse(new BaseServiceInvocationResult<>(sum(diagnostics)));
}

private Diagnostic sum(List<Diagnostic> particles) {
return particles.stream()//
.reduce(new SumOfDiagnostics())//
.orElseGet(BaseDiagnostic::new);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*******************************************************************************
* 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.util.Collection;
import java.util.function.BinaryOperator;

import org.eclipse.passage.lic.floating.model.api.FloatingLicenseAccess;
import org.eclipse.passage.lic.internal.api.ServiceInvocationResult;
import org.eclipse.passage.lic.internal.api.io.KeyKeeperRegistry;
import org.eclipse.passage.lic.internal.api.io.StreamCodecRegistry;
import org.eclipse.passage.lic.internal.base.BaseServiceInvocationResult;

public abstract class ServiceEvery<T, D extends RemoteServiceData> extends ServiceRemote<T, D> {

protected ServiceEvery(KeyKeeperRegistry keys, StreamCodecRegistry codecs) {
super(keys, codecs);
}

@Override
protected ServiceInvocationResult<T> withServers(D params, Collection<FloatingLicenseAccess> servers) {
return servers.stream()//
.map(access -> withServer(params, access))//
.reduce(new BaseServiceInvocationResult.Sum<>(sum()))//
.orElse(new BaseServiceInvocationResult<>(noResult()));
}

protected abstract BinaryOperator<T> sum();

protected abstract T noResult();

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,21 @@
import org.eclipse.passage.lic.floating.model.api.FloatingLicenseAccess;
import org.eclipse.passage.lic.internal.api.LicensedProduct;
import org.eclipse.passage.lic.internal.api.ServiceInvocationResult;
import org.eclipse.passage.lic.internal.api.diagnostic.Trouble;
import org.eclipse.passage.lic.internal.api.io.KeyKeeperRegistry;
import org.eclipse.passage.lic.internal.api.io.StreamCodecRegistry;
import org.eclipse.passage.lic.internal.base.BaseServiceInvocationResult;
import org.eclipse.passage.lic.internal.base.diagnostic.NoSevereErrors;
import org.eclipse.passage.lic.internal.base.diagnostic.code.AbsentLicenseAttendantFile;
import org.eclipse.passage.lic.internal.hc.i18n.AccessMessages;
import org.eclipse.passage.lic.internal.hc.remote.ResponseHandler;

public abstract class RemoteService<T, D extends RemoteServiceData> {
public abstract class ServiceRemote<T, D extends RemoteServiceData> {

private final KeyKeeperRegistry keys;
private final StreamCodecRegistry codecs;

protected RemoteService(KeyKeeperRegistry keys, StreamCodecRegistry codecs) {
protected ServiceRemote(KeyKeeperRegistry keys, StreamCodecRegistry codecs) {
this.keys = keys;
this.codecs = codecs;
}
Expand All @@ -37,26 +41,30 @@ public final ServiceInvocationResult<T> request(D parameters) {
if (!new NoSevereErrors().test(accesses.diagnostic())) {
return new BaseServiceInvocationResult<>(accesses.diagnostic());
}
if (accesses.data().get().isEmpty()) {
new BaseServiceInvocationResult<>(noServers());
}
return withServers(parameters, accesses.data().get());
}

protected abstract ServiceInvocationResult<T> withServers(D parameters, Collection<FloatingLicenseAccess> servers);
protected final ServiceInvocationResult<T> withServer(D params, FloatingLicenseAccess access) {
return new HttpClient<T>().request(//
request(params, access), //
handler(access));
}

private Trouble noServers() {
return new Trouble(new AbsentLicenseAttendantFile(), AccessMessages.RemoteService_no_server);
}

private ServiceInvocationResult<Collection<FloatingLicenseAccess>> accesses(LicensedProduct product) {
return new AccessPacks(product, keys, codecs).get();
}

static abstract class Parameters {
private final LicensedProduct product;
protected abstract ServiceInvocationResult<T> withServers(D parameters, Collection<FloatingLicenseAccess> servers);

protected Parameters(LicensedProduct product) {
this.product = product;
}
protected abstract RemoteRequest request(D params, FloatingLicenseAccess access);

LicensedProduct product() {
return product;
}

}
protected abstract ResponseHandler<T> handler(FloatingLicenseAccess access);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*******************************************************************************
* 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 java.util.function.BiFunction;

import org.eclipse.passage.lic.floating.model.api.FloatingLicenseAccess;
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;

final class OfFeatureRequest extends RemoteRequest {

private final OfFeature data;
private final BiFunction<RemoteServiceData.OfFeature, FloatingLicenseAccess, RequestParameters> parameters;

OfFeatureRequest(OfFeature data, FloatingLicenseAccess access,
BiFunction<RemoteServiceData.OfFeature, FloatingLicenseAccess, RequestParameters> parameters) {
super(data.product(), access);
this.data = data;
this.parameters = parameters;
}

@Override
protected RequestParameters parameters() {
return parameters.apply(data, access);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@
package org.eclipse.passage.lic.internal.hc.remote.impl.acquire;

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.ResponseHandler;
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.ServiceAny;

final class RemoteAcquire extends SignRequestService {
final class RemoteAcquire extends ServiceAny<GrantAcqisition, RemoteServiceData.OfFeature> {

RemoteAcquire(KeyKeeperRegistry keys, StreamCodecRegistry codecs) {
super(keys, codecs);
Expand All @@ -33,18 +38,27 @@ protected RemoteRequest request(OfFeature params, FloatingLicenseAccess access)
}

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

private static final class Response implements ResponseHandler<Boolean> {
private final static class AcquireResponseHandler 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) {
this.delegate = delegate;
}

@Override
public Boolean read(byte[] raw, String contentType) throws LicensingException {
// TODO parse the bytes to E-'acquire response'-Object and read boolean result
return null;
public GrantAcqisition read(byte[] raw, String contentType) throws LicensingException {
return apiGrant(delegate.read(raw, contentType));
}

}
private GrantAcqisition apiGrant(org.eclipse.passage.lic.floating.model.api.GrantAcqisition source) {
return new PGrantAcquisition(source).get();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import org.eclipse.passage.lic.internal.api.LicensedProduct;
import org.eclipse.passage.lic.internal.api.ServiceInvocationResult;
import org.eclipse.passage.lic.internal.api.acquire.GrantAcqisition;
import org.eclipse.passage.lic.internal.api.acquire.LicenseAcquisitionService;
import org.eclipse.passage.lic.internal.api.conditions.mining.ConditionMiningTarget;
import org.eclipse.passage.lic.internal.api.io.KeyKeeperRegistry;
Expand All @@ -37,13 +38,13 @@ public ConditionMiningTarget id() {
}

@Override
public ServiceInvocationResult<Boolean> acquire(LicensedProduct product, String feature) {
public ServiceInvocationResult<GrantAcqisition> acquire(LicensedProduct product, String feature) {
return new RemoteAcquire(keys, codecs).request(new RemoteServiceData.OfFeature(product, feature));
}

@Override
public ServiceInvocationResult<Boolean> release(LicensedProduct product, String feature) {
return new RemoteRelease(keys, codecs).request(new RemoteServiceData.OfFeature(product, feature));
public ServiceInvocationResult<Boolean> release(LicensedProduct product, GrantAcqisition acquisition) {
return null; // TODO: YTBD
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,34 @@
import org.eclipse.passage.lic.internal.api.io.StreamCodecRegistry;
import org.eclipse.passage.lic.internal.hc.remote.ResponseHandler;
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.ServiceAny;

final class RemoteRelease extends SignRequestService {
/**
* FIXME: release is a 'post' request with XML Input and without Output. Both
* RemoteRequest and ResponseHandler interfaces must be revised for the purpose
*/
final class RemoteRelease extends ServiceAny<Boolean, RemoteServiceData.OfFeature> {

RemoteRelease(KeyKeeperRegistry keys, StreamCodecRegistry codecs) {
super(keys, codecs);
}

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

@Override
protected ResponseHandler<Boolean> handler() {
return new Response();
protected ResponseHandler<Boolean> handler(FloatingLicenseAccess access) {
return new ReleaseResponseHandler();
}

private static final class Response implements ResponseHandler<Boolean> {
private static final class ReleaseResponseHandler implements ResponseHandler<Boolean> {

@Override
public Boolean read(byte[] raw, String contentType) throws LicensingException {
// TODO parse the bytes to E-'release response'-Object and read boolean result
return null;
}

Expand Down
Loading

0 comments on commit 7219a59

Please sign in to comment.