Skip to content

Commit

Permalink
Merge pull request #684 from eclipse-passage/572325
Browse files Browse the repository at this point in the history
Bug 572325 FLS must check license on startup
  • Loading branch information
eparovyshnaya authored Mar 26, 2021
2 parents c908fcd + 0f4df6a commit 74290ca
Show file tree
Hide file tree
Showing 26 changed files with 551 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
###############################################################################
Bundle-Name = Passage LBC Base
Bundle-Vendor = Eclipse Passage
Bundle-Copyright = Copyright (c) 2018, 2020 ArSysOp and others.\n\
Bundle-Copyright = Copyright (c) 2018, 2021 ArSysOp and others.\n\
\n\
This program and the accompanying materials are made\n\
available under the terms of the Eclipse Public License 2.0\n\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
###############################################################################
Bundle-Name = Passage LBC Jetty
Bundle-Vendor = Eclipse Passage
Bundle-Copyright = Copyright (c) 2018, 2020 ArSysOp and others.\n\
Bundle-Copyright = Copyright (c) 2018, 2021 ArSysOp and others.\n\
\n\
This program and the accompanying materials are made\n\
available under the terms of the Eclipse Public License 2.0\n\
Expand Down
29 changes: 21 additions & 8 deletions bundles/org.eclipse.passage.lbc.jetty/config/log4j2.xml
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 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
-->

<Configuration status="DEBUG"
packages="org.eclipse.passage.lbc.internal.base,org.eclipse.passage.lbc.internal.jetty,org.eclipse.passage.lic.internal.jetty,org.eclipse.passage.lic.internal.net">
packages="org.eclipse.passage.lbc.internal.base,org.eclipse.passage.lbc.internal.jetty,org.eclipse.passage.lic.internal.jetty,org.eclipse.passage.lic.internal.net,org.apache.logging.log4j2,org.eclipse">

<Appenders>

<Console name="Console" target="SYSTEM_OUT">
<Console name="ToSysOut" target="SYSTEM_OUT">
<PatternLayout
pattern="%d{HH:mm:ss} [%t] %-5level %logger{36}: %msg%n" />
</Console>

<Routing name="Routing">
<Routing name="ToFile">
<Routes pattern="$${sd:type}">
<Route>
<RollingFile name="logs-FLS"
fileName="logs/fl-server.log" filePattern="fl-server.%i.log.gz">
<PatternLayout>
<pattern>%d{HH:mm:ss} %p %c{3.} [%t] %m%n</pattern>
<pattern>%d{HH:mm:ss} %p %c{1.} [%t] %m%n</pattern>
</PatternLayout>
<SizeBasedTriggeringPolicy size="500000" />
</RollingFile>
</Route>
<Route ref="Console" key="Audit" />
</Routes>
</Routing>

Expand All @@ -29,9 +41,10 @@
<Loggers>

<Root level="debug">
<AppenderRef ref="Routing" />
<AppenderRef ref="ToSysOut" />
<AppenderRef ref="ToFile" />
</Root>

</Loggers>

</Configuration>
</Configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,22 @@
package org.eclipse.passage.lbc.internal.jetty;

import java.nio.file.Path;
import java.util.Optional;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.core.runtime.Platform;
import org.eclipse.passage.lbc.internal.base.EagerFloatingState;
import org.eclipse.passage.lbc.internal.base.FlotingRequestHandled;
import org.eclipse.passage.lbc.internal.base.api.FloatingState;
import org.eclipse.passage.lic.internal.api.LicensedProduct;
import org.eclipse.passage.lic.internal.api.LicensingException;
import org.eclipse.passage.lic.internal.api.ServiceInvocationResult;
import org.eclipse.passage.lic.internal.api.access.GrantLockAttempt;
import org.eclipse.passage.lic.internal.base.diagnostic.DiagnosticExplained;
import org.eclipse.passage.lic.internal.base.logging.Logging;
import org.eclipse.passage.lic.internal.equinox.EquinoxPassage;
import org.eclipse.passage.lic.internal.equinox.LicensedApplication;
import org.eclipse.passage.lic.internal.equinox.io.FileFromBundle;
import org.eclipse.passage.lic.internal.jetty.JettyHandler;
import org.eclipse.passage.lic.internal.jetty.JettyServer;
Expand All @@ -29,23 +39,33 @@
import org.osgi.framework.FrameworkUtil;

public final class JettyActivator implements BundleActivator {

private final Logger log;
private final JettyServer jetty;
private final FloatingState state;
private Optional<GrantLockAttempt> lock = Optional.empty();

public JettyActivator() {
configureLogging();
this.log = LogManager.getLogger(getClass());
this.jetty = new JettyServer(this::handler);
this.state = new EagerFloatingState();
}

@Override
public void start(BundleContext context) throws Exception {
lock = acquireLicense();
if (!lock.isPresent()) {
return;
}
if (!lock.get().successful()) {
return;
}
jetty.launch(new Port(Platform.getApplicationArgs(), 8090));
}

@Override
public void stop(BundleContext context) throws Exception {
lock.ifPresent(acq -> new EquinoxPassage().releaseLicense(acq));
jetty.terminate();
}

Expand All @@ -62,4 +82,33 @@ private Path logConfig() throws Exception {
return new FileFromBundle(bundle, "config/log4j2.xml").get(); //$NON-NLS-1$
}

private Optional<GrantLockAttempt> acquireLicense() {
return product().flatMap(this::acquireLicense);
}

private Optional<LicensedProduct> product() {
try {
return Optional.of(new LicensedApplication().product());
} catch (LicensingException e) {
log.error("Failed to read product credentials", e); //$NON-NLS-1$
return Optional.empty();
}
}

private Optional<GrantLockAttempt> acquireLicense(LicensedProduct product) {
ServiceInvocationResult<GrantLockAttempt> response = new EquinoxPassage().acquireLicense(product.identifier());
if (!successful(response)) {
log.error(String.format(//
"Failed to acquire license \nfor product %s:\n%s\n", //$NON-NLS-1$
product, //
new DiagnosticExplained(response.diagnostic()).get()));
return Optional.empty();
}
return Optional.of(response.data().get());
}

private boolean successful(ServiceInvocationResult<GrantLockAttempt> response) {
return response.data().map(GrantLockAttempt::successful).orElse(Boolean.FALSE);
}

}
7 changes: 7 additions & 0 deletions bundles/org.eclipse.passage.lbc.seal/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull
org.eclipse.jdt.core.compiler.annotation.nonnull.secondary=
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary=
org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
org.eclipse.jdt.core.compiler.problem.APILeak=warning
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
org.eclipse.jdt.core.compiler.problem.deadCode=warning
org.eclipse.jdt.core.compiler.problem.deprecation=warning
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore
org.eclipse.jdt.core.compiler.problem.fallthroughCase=warning
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
org.eclipse.jdt.core.compiler.problem.fieldHiding=warning
org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled
org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning
org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
org.eclipse.jdt.core.compiler.problem.localVariableHiding=warning
org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
org.eclipse.jdt.core.compiler.problem.missingDefaultCase=warning
org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=warning
org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled
org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=warning
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=warning
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=error
org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning
org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning
org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error
org.eclipse.jdt.core.compiler.problem.nullReference=warning
org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error
org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
org.eclipse.jdt.core.compiler.problem.parameterAssignment=warning
org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning
org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning
org.eclipse.jdt.core.compiler.problem.potentialNullReference=warning
org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=warning
org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning
org.eclipse.jdt.core.compiler.problem.redundantNullCheck=warning
org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore
org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
org.eclipse.jdt.core.compiler.problem.terminalDeprecation=warning
org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled
org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning
org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType=warning
org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict=disabled
org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType=info
org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
org.eclipse.jdt.core.compiler.problem.unstableAutoModuleName=warning
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedImport=warning
org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore
org.eclipse.jdt.core.compiler.problem.unusedParameter=warning
org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=warning
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
Loading

0 comments on commit 74290ca

Please sign in to comment.