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

refactor: separate DataPlaneClient and DataPlaneSelector #3641

Merged
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
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
Expand All @@ -8,14 +8,17 @@
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - Initial implementation
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation
*
*/

package org.eclipse.edc.connector.dataplane.selector.core;
package org.eclipse.edc.connector.dataplane.selector;

import org.eclipse.edc.connector.dataplane.selector.spi.store.DataPlaneInstanceStore;
import org.eclipse.edc.connector.dataplane.selector.spi.strategy.RandomSelectionStrategy;
import org.eclipse.edc.connector.dataplane.selector.spi.strategy.SelectionStrategyRegistry;
import org.eclipse.edc.connector.dataplane.selector.store.InMemoryDataPlaneInstanceStore;
import org.eclipse.edc.connector.dataplane.selector.strategy.DefaultSelectionStrategyRegistry;
import org.eclipse.edc.runtime.metamodel.annotation.Extension;
import org.eclipse.edc.runtime.metamodel.annotation.Provider;
import org.eclipse.edc.spi.system.ServiceExtension;
Expand All @@ -37,4 +40,11 @@ public String name() {
public DataPlaneInstanceStore instanceStore() {
return new InMemoryDataPlaneInstanceStore();
}

@Provider(isDefault = true)
public SelectionStrategyRegistry selectionStrategyRegistry() {
var strategy = new DefaultSelectionStrategyRegistry();
strategy.add(new RandomSelectionStrategy());
return strategy;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation
*
*/

package org.eclipse.edc.connector.dataplane.selector;

import org.eclipse.edc.connector.dataplane.selector.service.EmbeddedDataPlaneSelectorService;
import org.eclipse.edc.connector.dataplane.selector.spi.DataPlaneSelectorService;
import org.eclipse.edc.connector.dataplane.selector.spi.store.DataPlaneInstanceStore;
import org.eclipse.edc.connector.dataplane.selector.spi.strategy.SelectionStrategyRegistry;
import org.eclipse.edc.runtime.metamodel.annotation.Extension;
import org.eclipse.edc.runtime.metamodel.annotation.Inject;
import org.eclipse.edc.runtime.metamodel.annotation.Provider;
import org.eclipse.edc.spi.system.ServiceExtension;
import org.eclipse.edc.transaction.spi.TransactionContext;

@Extension(value = "DataPlane core selector")
public class DataPlaneSelectorExtension implements ServiceExtension {

@Inject
private DataPlaneInstanceStore instanceStore;

@Inject
private TransactionContext transactionContext;

@Inject
private SelectionStrategyRegistry selectionStrategyRegistry;

@Provider
public DataPlaneSelectorService dataPlaneSelectorService() {
return new EmbeddedDataPlaneSelectorService(instanceStore, selectionStrategyRegistry, transactionContext);
}

}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020 - 2022 Microsoft Corporation
* Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
Expand All @@ -8,13 +8,12 @@
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Microsoft Corporation - initial API and implementation
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation
*
*/

package org.eclipse.edc.connector.dataplane.selector;
package org.eclipse.edc.connector.dataplane.selector.service;

import org.eclipse.edc.connector.dataplane.selector.spi.DataPlaneSelector;
import org.eclipse.edc.connector.dataplane.selector.spi.DataPlaneSelectorService;
import org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance;
import org.eclipse.edc.connector.dataplane.selector.spi.store.DataPlaneInstanceStore;
Expand All @@ -24,19 +23,16 @@
import org.eclipse.edc.spi.types.domain.DataAddress;
import org.eclipse.edc.transaction.spi.TransactionContext;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

public class DataPlaneSelectorServiceImpl implements DataPlaneSelectorService {
public class EmbeddedDataPlaneSelectorService implements DataPlaneSelectorService {

private final DataPlaneSelector selector;
private final DataPlaneInstanceStore store;
private final SelectionStrategyRegistry selectionStrategyRegistry;
private final TransactionContext transactionContext;

public DataPlaneSelectorServiceImpl(DataPlaneSelector selector, DataPlaneInstanceStore store, SelectionStrategyRegistry selectionStrategyRegistry, TransactionContext transactionContext) {
this.selector = selector;
public EmbeddedDataPlaneSelectorService(DataPlaneInstanceStore store, SelectionStrategyRegistry selectionStrategyRegistry, TransactionContext transactionContext) {
this.store = store;
this.selectionStrategyRegistry = selectionStrategyRegistry;
this.transactionContext = transactionContext;
Expand All @@ -47,23 +43,14 @@ public List<DataPlaneInstance> getAll() {
return store.getAll().collect(Collectors.toList());
}

@Override
public DataPlaneInstance select(DataAddress source, DataAddress destination) {
return selector.select(source, destination);
}

@Override
public DataPlaneInstance select(DataAddress source, DataAddress destination, String selectionStrategy) {
var strategy = selectionStrategyRegistry.find(selectionStrategy);
if (strategy == null) {
throw new IllegalArgumentException("Strategy " + selectionStrategy + " was not found");
}
return selector.select(source, destination, strategy);
}

@Override
public Collection<String> getAllStrategies() {
return selectionStrategyRegistry.getAll();
var dataPlanes = store.getAll().filter(dataPlane -> dataPlane.canHandle(source, destination)).toList();
return strategy.apply(dataPlanes);
}

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

org.eclipse.edc.connector.dataplane.selector.core.DataPlaneSelectorExtension
org.eclipse.edc.connector.dataplane.selector.core.DataPlaneSelectorDefaultServicesExtension
org.eclipse.edc.connector.dataplane.selector.DataPlaneSelectorExtension
org.eclipse.edc.connector.dataplane.selector.DataPlaneSelectorDefaultServicesExtension

This file was deleted.

Loading
Loading