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 567032 issue floating license configuration wizard #500

Merged
merged 1 commit into from
Oct 27, 2020
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
5 changes: 4 additions & 1 deletion bundles/org.eclipse.passage.lic.api/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ Export-Package: org.eclipse.passage.lic.internal.api;
org.eclipse.passage.lbc.base,
org.eclipse.passage.lic.base,
org.eclipse.passage.lic.json,
org.eclipse.passage.lic.hc",
org.eclipse.passage.lic.hc,
org.eclipse.passage.lic.api,
org.eclipse.passage.loc.api,
org.eclipse.passage.loc.licenses.core",
org.eclipse.passage.lic.internal.api.conditions.evaluation;x-internal:=true,
org.eclipse.passage.lic.internal.api.conditions.mining;
x-friends:="org.eclipse.passage.lbc.api,
Expand Down
6 changes: 5 additions & 1 deletion bundles/org.eclipse.passage.lic.base/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ Export-Package: org.eclipse.passage.lic.internal.base;
org.eclipse.passage.lic.jface,
org.eclipse.passage.lic.base.tests",
org.eclipse.passage.lic.internal.base.access;x-internal:=true,
org.eclipse.passage.lic.internal.base.conditions;x-friends:="org.eclipse.passage.lbc.base,org.eclipse.passage.lic.json,org.eclipse.passage.lic.hc",
org.eclipse.passage.lic.internal.base.conditions;
x-friends:="org.eclipse.passage.lbc.base,
org.eclipse.passage.lic.json,
org.eclipse.passage.lic.hc,
org.eclipse.passage.loc.licenses.core",
org.eclipse.passage.lic.internal.base.conditions.evaluation;x-internal:=true,
org.eclipse.passage.lic.internal.base.conditions.mining;x-friends:="org.eclipse.passage.lic.jface,org.eclipse.passage.lic.hc",
org.eclipse.passage.lic.internal.base.diagnostic;x-friends:="org.eclipse.passage.lic.equinox.tests,org.eclipse.passage.lic.equinox,org.eclipse.passage.loc.dashboard.ui",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="0.0.0";x-installation:=
org.eclipse.emf.ecore;bundle-version="0.0.0";visibility:=reexport,
org.eclipse.passage.lic.emf.meta;bundle-version="0.6.0",
org.eclipse.passage.lic.floating;bundle-version="0.0.0";visibility:=reexport
Export-Package: org.eclipse.passage.lic.floating.model.api;x-friends:="org.eclipse.passage.lic.floating.edit,org.eclipse.passage.loc.dashboard.ui,org.eclipse.passage.loc.api",
Export-Package: org.eclipse.passage.lic.floating.model.api;
x-friends:="org.eclipse.passage.lic.floating.edit,
org.eclipse.passage.loc.dashboard.ui,
org.eclipse.passage.loc.api,
org.eclipse.passage.loc.licenses.core",
org.eclipse.passage.lic.floating.model.impl;x-internal:=true,
org.eclipse.passage.lic.floating.model.meta;x-friends:="org.eclipse.passage.lic.floating.e4.ui,org.eclipse.passage.lic.floating.edit",
org.eclipse.passage.lic.floating.model.meta;x-friends:="org.eclipse.passage.lic.floating.e4.ui,org.eclipse.passage.lic.floating.edit,org.eclipse.passage.loc.licenses.core",
org.eclipse.passage.lic.floating.model.util;x-friends:="org.eclipse.passage.lic.floating.edit",
org.eclipse.passage.lic.internal.floating.model;x-friends:="org.eclipse.passage.loc.dashboard.ui"
Bundle-ClassPath: .
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

import java.util.Collection;

import org.eclipse.passage.lic.internal.api.conditions.EvaluationInstructions;

/**
* Collection of all the data required to issue a floating license pack.
*/
Expand All @@ -26,21 +28,25 @@ public interface FloatingLicenseRequest extends GeneralLicenseRequest {
Collection<String> users();

/**
* Type of licensing condition for a <code>User</code> identified by the given
* {@code user} value.
*/
String conditionType(String user);

/**
* Condition expression for a <code>User</code> identified by the given
* Licensing condition for a <code>User</code> identified by the given
* {@code user} value.
*/
String conditionExpression(String user);
EvaluationInstructions userAuthentication(String user);

/**
* Default capacity for all the <code>FeatureGrant</code>s defined in this
* floating license pack.
*/
int defaultCapacity();

/**
* {@code FloatingServer} is to be authenticated.
*/
EvaluationInstructions serverAuthentication();

/**
* {@code FloatingServer} is to be named for convenience.
*/
String serverName();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*******************************************************************************
* 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.loc.internal.api;

public interface IssuedFloatingLicense {

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.passage.loc.internal.api;

import org.eclipse.passage.lic.floating.model.api.FloatingLicensePack;
import org.eclipse.passage.lic.internal.api.ServiceInvocationResult;
import org.eclipse.passage.lic.licenses.LicensePackDescriptor;

Expand All @@ -23,13 +24,26 @@
public interface OperatorLicenseService {

/**
*
* @param request
* @return the License Pack to be verified and issued
*
* Create new instance of Personal License Pack to be verified and issued
*/
LicensePackDescriptor createLicensePack(PersonalLicenseRequest request);

ServiceInvocationResult<IssuedLicense> issueLicensePack(PersonalLicenseRequest request, LicensePackDescriptor template);
/**
* Physically issue new Personal License Pack according to all the data supplied
* by the given data.
*/
ServiceInvocationResult<IssuedLicense> issueLicensePack(PersonalLicenseRequest request,
LicensePackDescriptor template);

/**
* Create new instance of Floating License Pack to be verified and issued
*/
FloatingLicensePack createFloatingLicensePack(FloatingLicenseRequest request);

/**
* Physically issue new Floating License Pack according to all the data supplied
* by the given data.
*/
ServiceInvocationResult<IssuedFloatingLicense> issueFloatingLicensePack(FloatingLicenseRequest request,
FloatingLicensePack template);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Require-Bundle: org.eclipse.e4.core.di.annotations;bundle-version="0.0.0",
org.eclipse.passage.loc.licenses.core;bundle-version="0.6.0",
org.eclipse.passage.loc.products.ui;bundle-version="0.0.0",
org.eclipse.passage.loc.users.ui;bundle-version="0.0.0",
org.eclipse.passage.loc.licenses.ui;bundle-version="0.0.0"
org.eclipse.passage.loc.licenses.ui;bundle-version="0.0.0",
org.eclipse.passage.lic.floating.model;bundle-version="0.1.0"
Import-Package: javax.annotation;version="1.0.0";resolution:=optional,
javax.inject;version="1.0.0"
Export-Package: org.eclipse.passage.loc.dashboard.ui;x-internal:=true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Require-Bundle: org.eclipse.osgi.services;bundle-version="0.0.0",
org.eclipse.passage.lic.users.model;bundle-version="1.0.0",
org.eclipse.passage.loc.api;bundle-version="0.0.0",
org.eclipse.passage.loc.products.core;bundle-version="0.6.0",
org.eclipse.passage.loc.users.core;bundle-version="1.0.0"
org.eclipse.passage.loc.users.core;bundle-version="1.0.0",
org.eclipse.passage.lic.floating.model;bundle-version="0.1.0"
Export-Package: org.eclipse.passage.loc.internal.licenses;x-friends:="org.eclipse.passage.loc.licenses.emfforms,org.eclipse.passage.loc.licenses.ui,org.eclipse.passage.loc.dashboard.ui",
org.eclipse.passage.loc.internal.licenses.core;x-friends:="org.eclipse.passage.loc.dashboard.ui",
org.eclipse.passage.loc.internal.licenses.core.i18n;x-internal:=true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/*******************************************************************************
* 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.loc.internal.licenses.core;

import java.util.Collection;
import java.util.Date;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import org.eclipse.passage.lic.floating.model.api.EvaluationInstructions;
import org.eclipse.passage.lic.floating.model.api.FeatureGrant;
import org.eclipse.passage.lic.floating.model.api.FloatingLicensePack;
import org.eclipse.passage.lic.floating.model.api.FloatingServer;
import org.eclipse.passage.lic.floating.model.api.LicenseRequisites;
import org.eclipse.passage.lic.floating.model.api.ProductRef;
import org.eclipse.passage.lic.floating.model.api.UserGrant;
import org.eclipse.passage.lic.floating.model.api.ValidityPeriod;
import org.eclipse.passage.lic.floating.model.api.ValidityPeriodClosed;
import org.eclipse.passage.lic.floating.model.api.VersionMatch;
import org.eclipse.passage.lic.floating.model.meta.FloatingFactory;
import org.eclipse.passage.lic.licenses.LicensePlanDescriptor;
import org.eclipse.passage.lic.licenses.LicensePlanFeatureDescriptor;
import org.eclipse.passage.lic.users.UserDescriptor;
import org.eclipse.passage.loc.internal.api.FloatingLicenseRequest;
import org.eclipse.passage.loc.internal.licenses.LicenseRegistry;
import org.eclipse.passage.loc.internal.users.UserRegistry;

final class FloatingLicensePackFromRequest implements Supplier<FloatingLicensePack> {

private final FloatingLicenseRequest request;
private final LicenseRegistry licenses;
private final UserRegistry users;

FloatingLicensePackFromRequest(FloatingLicenseRequest request, LicenseRegistry licenses, UserRegistry users) {
this.request = request;
this.licenses = licenses;
this.users = users;
}

@Override
public FloatingLicensePack get() {
FloatingLicensePack pack = FloatingFactory.eINSTANCE.createFloatingLicensePack();
pack.setLicense(license());
pack.setHost(host());
userGrants().forEach(pack.getUsers()::add);
featureGrants(pack).forEach(pack.getFeatures()::add);
return pack;
}

private FloatingServer host() {
FloatingServer server = FloatingFactory.eINSTANCE.createFloatingServer();
server.setIdentifier(request.serverName());
server.setAuthentication(serverAuthentication());
return server;
}

private EvaluationInstructions serverAuthentication() {
EvaluationInstructions auth = FloatingFactory.eINSTANCE.createEvaluationInstructions();
org.eclipse.passage.lic.internal.api.conditions.EvaluationInstructions requested = //
request.serverAuthentication();
auth.setExpression(requested.expression());
auth.setType(requested.type().identifier());
return auth;
}

private LicenseRequisites license() {
LicenseRequisites license = FloatingFactory.eINSTANCE.createLicenseRequisites();
license.setCompany(company());
license.setIdentifier(request.identifier());
license.setIssueDate(new Date());
license.setPlan(request.plan());
license.setProduct(product());
license.setValid(period());
return license;
}

private String company() {
return users.getUser(request.users().iterator().next()).getUserOrigin().getIdentifier();
}

private ValidityPeriod period() {
ValidityPeriodClosed period = FloatingFactory.eINSTANCE.createValidityPeriodClosed();
period.setFrom(request.validFrom());
period.setUntil(request.validUntil());
return period;
}

private ProductRef product() {
ProductRef product = FloatingFactory.eINSTANCE.createProductRef();
product.setProduct(request.productIdentifier());
product.setVersion(request.productVersion());
return product;
}

private Collection<UserGrant> userGrants() {
return request.users().stream()//
.map(users::getUser)//
.map(this::userGrant)//
.collect(Collectors.toSet());
}

private UserGrant userGrant(UserDescriptor user) {
UserGrant grant = FloatingFactory.eINSTANCE.createUserGrant();
grant.setAuthentication(userAuthentication(user));
grant.setUser(user.getIdentifier());
return grant;
}

private EvaluationInstructions userAuthentication(UserDescriptor user) {
EvaluationInstructions auth = FloatingFactory.eINSTANCE.createEvaluationInstructions();
auth.setExpression(user.getPreferredConditionExpression());
auth.setType(user.getPreferredConditionType());
return auth;
}

private Collection<FeatureGrant> featureGrants(FloatingLicensePack pack) {
LicensePlanDescriptor plan = licenses.getLicensePlan(request.plan());
AtomicInteger counter = new AtomicInteger(0);
return StreamSupport.stream(plan.getLicensePlanFeatures().spliterator(), false)//
.map(feature -> featureGrant(feature, pack, counter.getAndIncrement())) //
.collect(Collectors.toSet());
}

private FeatureGrant featureGrant(LicensePlanFeatureDescriptor feature, FloatingLicensePack pack, int no) {
FeatureGrant grant = FloatingFactory.eINSTANCE.createFeatureGrant();
grant.setFeature(feature.getFeatureIdentifier());
grant.setCapacity(request.defaultCapacity());
grant.setIdentifier(String.format("%s#%d", request.identifier(), no)); //$NON-NLS-1$
grant.setPack(pack);
grant.setValid(period());
grant.setVersion(version(feature));
return grant;
}

private VersionMatch version(LicensePlanFeatureDescriptor feature) {
VersionMatch version = FloatingFactory.eINSTANCE.createVersionMatch();
version.setVersion(feature.getMatchVersion());
version.setRule(feature.getMatchRule());
return version;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
import java.util.function.Supplier;

import org.eclipse.osgi.service.environment.EnvironmentInfo;
import org.eclipse.passage.lic.floating.model.api.FloatingLicensePack;
import org.eclipse.passage.lic.internal.api.ServiceInvocationResult;
import org.eclipse.passage.lic.licenses.LicensePackDescriptor;
import org.eclipse.passage.lic.licenses.model.api.LicensePack;
import org.eclipse.passage.loc.internal.api.FloatingLicenseRequest;
import org.eclipse.passage.loc.internal.api.IssuedFloatingLicense;
import org.eclipse.passage.loc.internal.api.IssuedLicense;
import org.eclipse.passage.loc.internal.api.OperatorLicenseService;
import org.eclipse.passage.loc.internal.api.OperatorProductService;
Expand Down Expand Up @@ -107,6 +110,11 @@ public void unbindProductOperatorService(OperatorProductService productService)
}
}

@Override
public LicensePack createLicensePack(PersonalLicenseRequest request) {
return new PersonalLicensePackFromRequest(request, licenseRegistry).get();
}

@Override
public ServiceInvocationResult<IssuedLicense> issueLicensePack(PersonalLicenseRequest request,
LicensePackDescriptor template) {
Expand All @@ -120,8 +128,15 @@ public ServiceInvocationResult<IssuedLicense> issueLicensePack(PersonalLicenseRe
}

@Override
public LicensePack createLicensePack(PersonalLicenseRequest request) {
return new PersonalLicensePackFromRequest(request, licenseRegistry).get();
public FloatingLicensePack createFloatingLicensePack(FloatingLicenseRequest request) {
return new FloatingLicensePackFromRequest(request, licenseRegistry, userRegistry).get();
}

@Override
public ServiceInvocationResult<IssuedFloatingLicense> issueFloatingLicensePack(FloatingLicenseRequest request,
FloatingLicensePack template) {
// TODO YTBD
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
import org.eclipse.passage.loc.internal.licenses.LicenseRegistry;

final class PersonalLicensePackFromRequest implements Supplier<LicensePack> {

private final PersonalLicenseRequest request;
private final LicenseRegistry registry;
private final LicenseRegistry licenses;

PersonalLicensePackFromRequest(PersonalLicenseRequest request, LicenseRegistry registry) {
PersonalLicensePackFromRequest(PersonalLicenseRequest request, LicenseRegistry licesnses) {
this.request = request;
this.registry = registry;
this.licenses = licesnses;
}

@Override
Expand All @@ -43,7 +44,7 @@ public LicensePack get() {
pack.setProductVersion(request.productVersion());
String planIdentifier = request.plan();
pack.setPlanIdentifier(planIdentifier);
LicensePlanDescriptor plan = registry.getLicensePlan(planIdentifier);
LicensePlanDescriptor plan = licenses.getLicensePlan(planIdentifier);
if (plan == null) {
return pack; // FIXME: ServiceInvocationResult<LicensePack> should probably be used
}
Expand Down
Loading