Skip to content

Commit

Permalink
Bug 572353 lease a license for common use
Browse files Browse the repository at this point in the history
improve diagnostic: add more information on condition mining

Signed-off-by: eparovyshnaya <elena.parovyshnaya@gmail.com>
  • Loading branch information
eparovyshnaya committed Mar 27, 2021
1 parent 47d4120 commit fd8f8d4
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 5 deletions.
Expand Up @@ -14,6 +14,7 @@

import java.nio.file.Path;
import java.util.Collection;
import java.util.Collections;
import java.util.Objects;
import java.util.function.Supplier;

Expand All @@ -27,6 +28,8 @@
import org.eclipse.passage.lic.internal.api.conditions.mining.MiningEquipment;
import org.eclipse.passage.lic.internal.api.diagnostic.Trouble;
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.code.NoLicenses;
import org.eclipse.passage.lic.internal.base.diagnostic.code.ServiceFailedOnInfrastructureDenial;
import org.eclipse.passage.lic.internal.base.i18n.ConditionMiningMessages;
import org.eclipse.passage.lic.internal.base.io.FileCollection;
Expand Down Expand Up @@ -67,7 +70,11 @@ public final ConditionMiningTarget id() {
@Override
public final ServiceInvocationResult<Collection<ConditionPack>> all(LicensedProduct product) {
try {
return equipment.tool(product, id).mine(licenses(product));
Collection<Path> licenses = licenses(product);
if (licenses.isEmpty()) {
return noLicenses(product);
}
return equipment.tool(product, id).mine(licenses);
} catch (LicensingException e) {
return new BaseServiceInvocationResult<Collection<ConditionPack>>( //
new Trouble(//
Expand All @@ -77,6 +84,15 @@ public final ServiceInvocationResult<Collection<ConditionPack>> all(LicensedProd
}
}

private ServiceInvocationResult<Collection<ConditionPack>> noLicenses(LicensedProduct product) {
return new BaseServiceInvocationResult<Collection<ConditionPack>>(//
new BaseDiagnostic(//
Collections.emptyList(), //
Collections.singletonList(//
new Trouble(new NoLicenses(), base(product).get().toAbsolutePath().toString()))//
));
}

private Collection<Path> licenses(LicensedProduct product) throws LicensingException {
return new FileCollection(base(product), scope).get();
}
Expand Down
Expand Up @@ -24,13 +24,16 @@
import org.eclipse.passage.lic.internal.api.conditions.ConditionMiningTarget;
import org.eclipse.passage.lic.internal.api.conditions.ConditionPack;
import org.eclipse.passage.lic.internal.api.conditions.mining.ConditionTransport;
import org.eclipse.passage.lic.internal.api.diagnostic.Diagnostic;
import org.eclipse.passage.lic.internal.api.diagnostic.Trouble;
import org.eclipse.passage.lic.internal.api.io.KeyKeeper;
import org.eclipse.passage.lic.internal.api.io.StreamCodec;
import org.eclipse.passage.lic.internal.base.BaseServiceInvocationResult;
import org.eclipse.passage.lic.internal.base.SumOfCollections;
import org.eclipse.passage.lic.internal.base.conditions.BaseConditionOrigin;
import org.eclipse.passage.lic.internal.base.conditions.BaseConditionPack;
import org.eclipse.passage.lic.internal.base.diagnostic.BaseDiagnostic;
import org.eclipse.passage.lic.internal.base.diagnostic.code.NoRelevantConditions;
import org.eclipse.passage.lic.internal.base.diagnostic.code.ServiceFailedOnMorsel;
import org.eclipse.passage.lic.internal.base.i18n.BaseMessages;

Expand All @@ -51,10 +54,14 @@ public ServiceInvocationResult<Collection<ConditionPack>> mine(Collection<Path>

private ServiceInvocationResult<Collection<ConditionPack>> mine(Path source) {
try {
return new BaseServiceInvocationResult<>(Collections.singleton(//
new BaseConditionPack(//
new BaseConditionOrigin(miner, source(source)), //
from(decoded(source)))));
Collection<Condition> conditions = from(decoded(source));
return new BaseServiceInvocationResult<>(//
diagnostic(conditions, source), //
Collections.singleton(//
new BaseConditionPack(//
new BaseConditionOrigin(miner, source(source)), //
conditions)//
));
} catch (IOException | LicensingException e) {
return new BaseServiceInvocationResult<>(//
new Trouble(//
Expand All @@ -71,4 +78,15 @@ private Collection<Condition> from(byte[] decoded) throws IOException {
}
}

private Diagnostic diagnostic(Collection<Condition> conditions, Path source) {
if (conditions.isEmpty()) {
return new BaseDiagnostic(//
Collections.emptyList(), //
Collections.singletonList(//
new Trouble(new NoRelevantConditions(), source.toAbsolutePath().toString()))//
);
}
return new BaseDiagnostic();
}

}
@@ -0,0 +1,24 @@
/*******************************************************************************
* 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.base.diagnostic.code;

import org.eclipse.passage.lic.internal.api.diagnostic.TroubleCode;
import org.eclipse.passage.lic.internal.base.i18n.DiagnosticCodeMessages;

public final class NoLicenses extends TroubleCode {

public NoLicenses() {
super(410, DiagnosticCodeMessages.getString("NoLicenses.explanation")); //$NON-NLS-1$
}

}
@@ -0,0 +1,24 @@
/*******************************************************************************
* 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.base.diagnostic.code;

import org.eclipse.passage.lic.internal.api.diagnostic.TroubleCode;
import org.eclipse.passage.lic.internal.base.i18n.DiagnosticCodeMessages;

public final class NoRelevantConditions extends TroubleCode {

public NoRelevantConditions() {
super(409, DiagnosticCodeMessages.getString("NoRelevantConditions.explanation")); //$NON-NLS-1$
}

}
Expand Up @@ -46,6 +46,8 @@
* conditions found for it), but has not-critical restriction level (for
* instance @{code info}, {@code warning}) and thus can be used without
* license.</li>
* <li>409 - a license source does not provide relevant conditions (info)</li>
* <li>410 - no licenses found in a source directory (info)</li>
* </ul>
* </li>
* <li>5xx - reserved</li>
Expand Down
Expand Up @@ -20,6 +20,8 @@ ServiceCannotOperate.explanation=Access cycle service cannot operate
NoServices.explanation=No services of type [%s] available
NoRequirements.explanation=No licensing requirements registered
NoFramework.explanation=Passage gains no Framework instance and is completely inoperable. It means either severe lack of configuration or sabotage.
NoRelevantConditions.explanation=License does not supply a relevant condition
NoLicenses.explanation=There are no licenses found under the given source dir
SeveralFrameworks.explanation=Passage finds %s Framework implementations, which means either severe configuration errors or sabotage.
ServiceFailedOnMorsel.explanation=Service failed to evaluate a morsel
ServiceFailedOnInfrastructureDenial.explanation=Service failed severely due to an invoked service denial.
Expand Down

0 comments on commit fd8f8d4

Please sign in to comment.