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

Bug 571179 - [PAssage][LA] design and implement core request dispatching #654

Merged
merged 3 commits into from
Feb 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
import org.eclipse.passage.lbc.internal.base.api.RawRequest;
import org.eclipse.passage.lic.internal.api.LicensingException;
import org.eclipse.passage.lic.internal.net.api.handle.NetResponse;
import org.eclipse.passage.lic.internal.net.handle.ProductUserRequest;

final class Acquire extends ChoreDraft<RawRequest> {
final class Acquire extends AuthentifiedChoreDraft {

Acquire(RawRequest data) {
super(data);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*******************************************************************************
* Copyright (c) 2020, 2021 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.lbc.internal.base;

import java.util.Optional;

import org.eclipse.passage.lbc.internal.base.api.RawRequest;
import org.eclipse.passage.lic.internal.api.EvaluationInstructions;
import org.eclipse.passage.lic.internal.net.api.handle.NetResponse;
import org.eclipse.passage.lic.internal.net.handle.ChoreDraft;
import org.eclipse.passage.lic.internal.net.handle.Failure;

abstract class AuthentifiedChoreDraft extends ChoreDraft<RawRequest> {

protected AuthentifiedChoreDraft(RawRequest request) {
super(request);
}

@Override
protected Optional<NetResponse> invalid() {
Optional<EvaluationInstructions> instructions = new ServerAuthenticationInstructions(data).get();
if (!instructions.isPresent()) {
return Optional.of(new Failure.BadRequestInvalidServerAuthInstructions());
}
try {
new ServerAuthentication(instructions.get()).evaluate();
} catch (Exception e) {
log.error("failed: ", e); //$NON-NLS-1$
return Optional.of(new Failure.ForeignServer(e.getMessage()));
}
return Optional.empty();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
import org.eclipse.passage.lbc.internal.base.api.RawRequest;
import org.eclipse.passage.lbc.internal.base.mine.Conditions;
import org.eclipse.passage.lic.internal.net.api.handle.NetResponse;
import org.eclipse.passage.lic.internal.net.handle.ProductUserRequest;

final class Mine extends ChoreDraft<RawRequest> {
final class Mine extends AuthentifiedChoreDraft {

Mine(RawRequest data) {
super(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
import org.eclipse.passage.lbc.internal.base.api.RawRequest;
import org.eclipse.passage.lic.internal.api.LicensingException;
import org.eclipse.passage.lic.internal.net.api.handle.NetResponse;
import org.eclipse.passage.lic.internal.net.handle.ProductUserRequest;

final class Release extends ChoreDraft<RawRequest> {
final class Release extends AuthentifiedChoreDraft {

Release(RawRequest data) {
super(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.apache.logging.log4j.Logger;
import org.eclipse.passage.lbc.internal.base.EObjectTransfer;
import org.eclipse.passage.lbc.internal.base.PlainSuceess;
import org.eclipse.passage.lbc.internal.base.ProductUserRequest;
import org.eclipse.passage.lbc.internal.base.api.Grants;
import org.eclipse.passage.lbc.internal.base.api.RawRequest;
import org.eclipse.passage.lic.floating.model.api.GrantAcqisition;
Expand All @@ -32,6 +31,7 @@
import org.eclipse.passage.lic.internal.emf.EObjectFromBytes;
import org.eclipse.passage.lic.internal.net.api.handle.NetResponse;
import org.eclipse.passage.lic.internal.net.handle.Failure;
import org.eclipse.passage.lic.internal.net.handle.ProductUserRequest;

public final class Acquisition {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public final class BaseMessages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.passage.lbc.internal.base.i18n.BaseMessages"; //$NON-NLS-1$

public static String AssembledConditions_validity_period_type_unknown;
public static String DecodedParam_decode_failed;
public static String ReassemblingMiningTool_path_failed;

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@
###############################################################################

AssembledConditions_validity_period_type_unknown=validity period of type %s is not supported
DecodedParam_decode_failed=Failed to decode url param value [%s]
ReassemblingMiningTool_path_failed=Error on gathering collection pack from %s
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.passage.lbc.internal.base.EObjectTransfer;
import org.eclipse.passage.lbc.internal.base.ProductUserRequest;
import org.eclipse.passage.lbc.internal.base.api.RawRequest;
import org.eclipse.passage.lic.floating.FloatingFileExtensions;
import org.eclipse.passage.lic.internal.api.LicensedProduct;
Expand All @@ -36,6 +35,7 @@
import org.eclipse.passage.lic.internal.base.io.UserHomePath;
import org.eclipse.passage.lic.internal.net.api.handle.NetResponse;
import org.eclipse.passage.lic.internal.net.handle.Failure;
import org.eclipse.passage.lic.internal.net.handle.ProductUserRequest;
import org.eclipse.passage.lic.licenses.model.api.LicensePack;

public final class Conditions implements Supplier<NetResponse> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ final class ReassemblingMiningTool extends ArmedMiningTool {
super(//
new PathKeyKeeper(product, base), //
new BcStreamCodec(() -> product), //
new XmiConditionTransport(), //
new XmiConditionTransport(), // is not used
miner);
this.product = product;
this.user = user;
Expand Down Expand Up @@ -98,8 +98,11 @@ private boolean productFits(ProductRef ref) {
}

private FloatingLicensePack pack(Path source) throws LicensingException {
return new EObjectFromBytes<>(decoded(source), FloatingLicensePack.class).get(//
Collections.singletonMap(FloatingPackage.eNAME, FloatingPackage.eINSTANCE));
return new EObjectFromBytes<>(//
decoded(source), //
FloatingLicensePack.class).get(//
Collections.singletonMap(FloatingPackage.eNAME, FloatingPackage.eINSTANCE)//
);
}

private BaseConditionPack noConditions(Path license) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,18 @@
* Contributors:
* ArSysOp - initial API and implementation
*******************************************************************************/
package org.eclipse.passage.lbc.internal.base;
package org.eclipse.passage.lic.internal.net.handle;

import java.util.Optional;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.passage.lic.internal.api.EvaluationInstructions;
import org.eclipse.passage.lic.internal.api.LicensingException;
import org.eclipse.passage.lic.internal.net.api.handle.Chore;
import org.eclipse.passage.lic.internal.net.api.handle.NetRequest;
import org.eclipse.passage.lic.internal.net.api.handle.NetResponse;
import org.eclipse.passage.lic.internal.net.handle.Failure;

abstract class ChoreDraft<R extends NetRequest> implements Chore {
public abstract class ChoreDraft<R extends NetRequest> implements Chore {

protected final R data;
protected final Logger log = LogManager.getLogger(getClass());
Expand All @@ -34,19 +32,13 @@ protected ChoreDraft(R request) {

@Override
public final NetResponse getDone() {
Optional<EvaluationInstructions> instructions = new ServerAuthenticationInstructions(data).get();
if (!instructions.isPresent()) {
return new Failure.BadRequestInvalidServerAuthInstructions();
}
try {
new ServerAuthentication(instructions.get()).evaluate();
} catch (Exception e) {
log.error("failed: ", e); //$NON-NLS-1$
return new Failure.ForeignServer(e.getMessage());
Optional<NetResponse> error = invalid();
if (error.isPresent()) {
return error.get();
}
ProductUserRequest<R> request;
try {
request = new ProductUserRequest<R>(data);
request = new ProductUserRequest<>(data);
} catch (LicensingException e) {
log.error("failed: ", e); //$NON-NLS-1$ ;
return failed(e.getMessage());
Expand All @@ -65,6 +57,8 @@ public final NetResponse getDone() {
}
}

protected abstract Optional<NetResponse> invalid();

protected abstract NetResponse withProductUser(ProductUserRequest<R> request) throws LicensingException;

protected final NetResponse failed(String details) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
* Contributors:
* ArSysOp - initial API and implementation
*******************************************************************************/
package org.eclipse.passage.lbc.internal.base;
package org.eclipse.passage.lic.internal.net.handle;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

import org.eclipse.passage.lbc.internal.base.i18n.BaseMessages;
import org.eclipse.passage.lic.internal.api.LicensingException;
import org.eclipse.passage.lic.internal.net.i18n.NetMessages;

final class DecodedParam {

Expand All @@ -30,7 +30,8 @@ String get() throws LicensingException {
try {
return URLDecoder.decode(raw, "UTF-8"); //$NON-NLS-1$
} catch (UnsupportedEncodingException e) {
throw new LicensingException(String.format(BaseMessages.DecodedParam_decode_failed, raw), e);
throw new LicensingException(
String.format(NetMessages.getString("DecodedParam.DecodedParam_decode_failed"), raw), e); //$NON-NLS-1$
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Contributors:
* ArSysOp - initial API and implementation
*******************************************************************************/
package org.eclipse.passage.lbc.internal.base;
package org.eclipse.passage.lic.internal.net.handle;

import java.util.Optional;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
import java.util.List;

import org.eclipse.emf.common.util.EList;
import org.eclipse.passage.lbc.internal.base.ProductUserRequest;
import org.eclipse.passage.lbc.internal.base.mine.Conditions;
import org.eclipse.passage.lic.internal.api.LicensingException;
import org.eclipse.passage.lic.internal.base.ProductIdentifier;
import org.eclipse.passage.lic.internal.base.ProductVersion;
import org.eclipse.passage.lic.internal.net.LicenseUser;
import org.eclipse.passage.lic.internal.net.api.handle.NetResponse;
import org.eclipse.passage.lic.internal.net.handle.ProductUserRequest;
import org.eclipse.passage.lic.licenses.model.api.LicenseGrant;
import org.junit.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
import java.util.stream.IntStream;

import org.eclipse.passage.lbc.internal.base.EagerFloatingState;
import org.eclipse.passage.lbc.internal.base.ProductUserRequest;
import org.eclipse.passage.lbc.internal.base.acquire.Acquisition;
import org.eclipse.passage.lbc.internal.base.acquire.NoGrantsAvailable;
import org.eclipse.passage.lbc.internal.base.api.FloatingState;
import org.eclipse.passage.lic.internal.api.LicensingException;
import org.eclipse.passage.lic.internal.api.PassageAction;
import org.eclipse.passage.lic.internal.net.api.handle.NetResponse;
import org.eclipse.passage.lic.internal.net.handle.ProductUserRequest;
import org.junit.Test;

public final class ExtensiveAcquiringTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.util.stream.IntStream;

import org.eclipse.passage.lbc.internal.base.EagerFloatingState;
import org.eclipse.passage.lbc.internal.base.ProductUserRequest;
import org.eclipse.passage.lbc.internal.base.acquire.Acquisition;
import org.eclipse.passage.lbc.internal.base.acquire.NoGrantsAvailable;
import org.eclipse.passage.lbc.internal.base.api.FloatingState;
Expand All @@ -40,6 +39,7 @@
import org.eclipse.passage.lic.internal.api.PassageAction;
import org.eclipse.passage.lic.internal.emf.EObjectFromBytes;
import org.eclipse.passage.lic.internal.net.api.handle.NetResponse;
import org.eclipse.passage.lic.internal.net.handle.ProductUserRequest;
import org.junit.Test;

public final class ExtensiveReleaseTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import org.eclipse.passage.lbc.base.tests.TestData;
import org.eclipse.passage.lbc.internal.base.EagerFloatingState;
import org.eclipse.passage.lbc.internal.base.ProductUserRequest;
import org.eclipse.passage.lbc.internal.base.acquire.Acquisition;
import org.eclipse.passage.lbc.internal.base.api.FloatingState;
import org.eclipse.passage.lbc.internal.base.api.RawRequest;
Expand All @@ -34,6 +33,7 @@
import org.eclipse.passage.lic.internal.hc.remote.Client;
import org.eclipse.passage.lic.internal.hc.remote.impl.acquire.RemoteAcquisitionService;
import org.eclipse.passage.lic.internal.net.api.handle.NetResponse;
import org.eclipse.passage.lic.internal.net.handle.ProductUserRequest;
import org.junit.Test;

@SuppressWarnings("restriction")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import org.eclipse.passage.lbc.base.tests.TestData;
import org.eclipse.passage.lbc.internal.base.EagerFloatingState;
import org.eclipse.passage.lbc.internal.base.ProductUserRequest;
import org.eclipse.passage.lbc.internal.base.api.FloatingState;
import org.eclipse.passage.lbc.internal.base.api.RawRequest;
import org.eclipse.passage.lbc.internal.base.mine.Conditions;
Expand All @@ -38,6 +37,7 @@
import org.eclipse.passage.lic.internal.hc.remote.impl.mine.RemoteConditions;
import org.eclipse.passage.lic.internal.licenses.migration.tobemoved.XmiConditionTransport;
import org.eclipse.passage.lic.internal.net.api.handle.NetResponse;
import org.eclipse.passage.lic.internal.net.handle.ProductUserRequest;
import org.junit.Test;

@SuppressWarnings("restriction")
Expand Down