Search in sources :

Example 1 with ImmutableStorageProvider

use of org.eclipse.winery.accountability.storage.ImmutableStorageProvider in project winery by eclipse.

the class AccountabilityManagerImplTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    BlockchainAccess blockchainAccess = BlockchainFactory.getBlockchainAccess(BlockchainFactory.AvailableBlockchains.TEST, null);
    ImmutableStorageProvider storageProvider = ImmutableStorageProviderFactory.getStorageProvider(ImmutableStorageProviderFactory.AvailableImmutableStorages.TEST, null);
    this.provenance = new AccountabilityManagerImpl(blockchainAccess, storageProvider);
}
Also used : BlockchainAccess(org.eclipse.winery.accountability.blockchain.BlockchainAccess) ImmutableStorageProvider(org.eclipse.winery.accountability.storage.ImmutableStorageProvider) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with ImmutableStorageProvider

use of org.eclipse.winery.accountability.storage.ImmutableStorageProvider in project winery by eclipse.

the class AccountabilityManagerImplIntegrationTest method setUp.

@BeforeEach
public void setUp() {
    AccountabilityConfigurationManager.getInstance().setDefaultKeystore();
    Environments.getInstance().getAccountabilityConfig().setEthereumPassword("winery");
    Environments.getInstance().getAccountabilityConfig().setGethUrl("http://127.0.0.1:8545");
    Environments.getInstance().getAccountabilityConfig().setSwarmGatewayUrl("https://swarm-gateways.net/");
    // deploy smart contracts to (a new address in) the blockchain
    try {
        ContractDeployer deployer = new ContractDeployer(Environments.getInstance().getAccountabilityConfig());
        Environments.getInstance().getAccountabilityConfig().setEthereumProvenanceSmartContractAddress(deployer.deployProvenance());
        Environments.getInstance().getAccountabilityConfig().setEthereumAuthorizationSmartContractAddress(deployer.deployAuthorization());
        // reset the contents of the accountability layer so older, possibly incompatible instances are nullified.
        BlockchainFactory.reset();
        ImmutableStorageProviderFactory.reset();
        // create new instances
        BlockchainAccess blockchainAccess = BlockchainFactory.getBlockchainAccess(BlockchainFactory.AvailableBlockchains.ETHEREUM, Environments.getInstance().getAccountabilityConfig());
        ImmutableStorageProvider storageProvider = ImmutableStorageProviderFactory.getStorageProvider(ImmutableStorageProviderFactory.AvailableImmutableStorages.SWARM, Environments.getInstance().getAccountabilityConfig());
        this.accountabilityManager = new AccountabilityManagerImpl(blockchainAccess, storageProvider);
    } catch (Exception e) {
        Preconditions.condition(false, e.getMessage());
    }
}
Also used : BlockchainAccess(org.eclipse.winery.accountability.blockchain.BlockchainAccess) ImmutableStorageProvider(org.eclipse.winery.accountability.storage.ImmutableStorageProvider) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with ImmutableStorageProvider

use of org.eclipse.winery.accountability.storage.ImmutableStorageProvider in project winery by eclipse.

the class AccountabilityManagerFactory method getAccountabilityManager.

public static AccountabilityManager getAccountabilityManager() throws AccountabilityException {
    if (Objects.isNull(accountabilityManager)) {
        try {
            AccountabilityConfigurationObject properties = Environments.getInstance().getAccountabilityConfig();
            Environments.getInstance().addConfigurationChangeListener(() -> {
                BlockchainFactory.reset();
                ImmutableStorageProviderFactory.reset();
            });
            BlockchainAccess blockchain = BlockchainFactory.getBlockchainAccess(BlockchainFactory.AvailableBlockchains.ETHEREUM, properties);
            ImmutableStorageProvider storageProvider = ImmutableStorageProviderFactory.getStorageProvider(ImmutableStorageProviderFactory.AvailableImmutableStorages.SWARM, properties);
            accountabilityManager = new AccountabilityManagerImpl(blockchain, storageProvider);
        } catch (BlockchainException e) {
            String msg = "Could not instantiate accountability layer: " + e.getMessage();
            LOGGER.error(msg, e);
            throw new AccountabilityException(msg, e);
        }
    }
    return accountabilityManager;
}
Also used : BlockchainException(org.eclipse.winery.accountability.exceptions.BlockchainException) AccountabilityException(org.eclipse.winery.accountability.exceptions.AccountabilityException) BlockchainAccess(org.eclipse.winery.accountability.blockchain.BlockchainAccess) ImmutableStorageProvider(org.eclipse.winery.accountability.storage.ImmutableStorageProvider) AccountabilityConfigurationObject(org.eclipse.winery.common.configuration.AccountabilityConfigurationObject)

Example 4 with ImmutableStorageProvider

use of org.eclipse.winery.accountability.storage.ImmutableStorageProvider in project winery by eclipse.

the class SwarmProviderTest method testStorageAndRetrieval.

@Test
public void testStorageAndRetrieval() throws ExecutionException, InterruptedException {
    final String dataToStore = "This a string intended for testing!";
    ImmutableStorageProviderFactory.reset();
    ImmutableStorageProvider swarm = ImmutableStorageProviderFactory.getStorageProvider(ImmutableStorageProviderFactory.AvailableImmutableStorages.TEST, null);
    assertNotNull(swarm);
    swarm.store(new ByteArrayInputStream(dataToStore.getBytes(StandardCharsets.UTF_8))).thenCompose((hash) -> {
        LOGGER.debug("retrieved hash is: {}", hash);
        return swarm.retrieve(hash);
    }).thenAccept((bytes) -> {
        try {
            String receivedMsg = IOUtils.toString(bytes, StandardCharsets.UTF_8);
            LOGGER.debug("retrieved msg is: {}", receivedMsg);
            assertEquals(dataToStore, receivedMsg);
        } catch (IOException e) {
            throw new CompletionException(e);
        }
    }).get();
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Logger(org.slf4j.Logger) ImmutableStorageProvider(org.eclipse.winery.accountability.storage.ImmutableStorageProvider) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) CompletionException(java.util.concurrent.CompletionException) Disabled(org.junit.jupiter.api.Disabled) StandardCharsets(java.nio.charset.StandardCharsets) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test) IOUtils(org.apache.commons.io.IOUtils) ByteArrayInputStream(java.io.ByteArrayInputStream) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ImmutableStorageProviderFactory(org.eclipse.winery.accountability.storage.ImmutableStorageProviderFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) ImmutableStorageProvider(org.eclipse.winery.accountability.storage.ImmutableStorageProvider) CompletionException(java.util.concurrent.CompletionException) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Aggregations

ImmutableStorageProvider (org.eclipse.winery.accountability.storage.ImmutableStorageProvider)4 BlockchainAccess (org.eclipse.winery.accountability.blockchain.BlockchainAccess)3 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 StandardCharsets (java.nio.charset.StandardCharsets)1 CompletionException (java.util.concurrent.CompletionException)1 ExecutionException (java.util.concurrent.ExecutionException)1 IOUtils (org.apache.commons.io.IOUtils)1 AccountabilityException (org.eclipse.winery.accountability.exceptions.AccountabilityException)1 BlockchainException (org.eclipse.winery.accountability.exceptions.BlockchainException)1 ImmutableStorageProviderFactory (org.eclipse.winery.accountability.storage.ImmutableStorageProviderFactory)1 AccountabilityConfigurationObject (org.eclipse.winery.common.configuration.AccountabilityConfigurationObject)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)1 Disabled (org.junit.jupiter.api.Disabled)1 Test (org.junit.jupiter.api.Test)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1