Package io.keyko.nevermined.manager
Class NeverminedManager
- java.lang.Object
-
- io.keyko.nevermined.manager.BaseManager
-
- io.keyko.nevermined.manager.NeverminedManager
-
public class NeverminedManager extends BaseManager
Handles several operations related with Ocean's flow
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class io.keyko.nevermined.manager.BaseManager
BaseManager.ContractAddresses
-
-
Field Summary
Fields Modifier and Type Field Description private AgreementsManageragreementsManagerprivate static org.apache.logging.log4j.Loggerlogprivate TemplatesManagertemplatesManager-
Fields inherited from class io.keyko.nevermined.manager.BaseManager
accessSecretStoreCondition, agreementStoreManager, computeExecutionCondition, condition, conditionStoreManager, config, contractAddresses, didRegistry, dispenser, escrowAccessSecretStoreTemplate, escrowComputeExecutionTemplate, escrowReward, lockRewardCondition, mainAccount, providerAddress, templateStoreManager, tokenContract
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedNeverminedManager(io.keyko.common.web3.KeeperService keeperService, MetadataApiService metadataApiService)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaccess(String serviceAgreementId, DID did, int serviceIndex, int fileIndex, String basePath)Downloads an Asset previously ordered through a Service Agreementbooleanaccess(String serviceAgreementId, DID did, int serviceIndex, String basePath)Downloads an Asset previously ordered through a Service Agreementprivate Map<String,Object>buildBasicAccessServiceConfiguration(ProviderConfig providerConfig, String price, String creatorAddress)private Map<String,Object>buildBasicComputingServiceConfiguration(ProviderConfig providerConfig, ComputingService.Provider computingProvider, String price, String creatorAddress)private StringbuildDestinationPath(String basePath, DID did, int fileIndex, AssetMetadata.File file)Constructs the final path where the file should be downloadedprivate booleancheckAgreementStatus(String serviceAgreementId)InputStreamconsumeBinary(String serviceAgreementId, DID did, int serviceIndex, int fileIndex)Downloads a single file of an Asset previously ordered through a Service AgreementInputStreamconsumeBinary(String serviceAgreementId, DID did, int serviceIndex, int fileIndex, Boolean isRangeRequest, Integer rangeStart, Integer rangeEnd)Downloads a single file of an Asset previously ordered through a Service Agreement.booleandownloadAssetByOwner(DID did, int serviceIndex, String basePath)Purchases an Asset represented by a DID.booleandownloadAssetByOwner(DID did, int serviceIndex, String basePath, int fileIndex)Purchases an Asset represented by a DID.GatewayService.ServiceExecutionResultexecuteComputeService(String agreementId, DID did, int index, DID workflowDID)Executes a remote service associated with an asset and serviceAgreementIdprivate Map<String,Object>fetchAssetDataBeforeConsume(DID did, int serviceIndex)Gets the data needed to download an assetprivate booleanfulfillEscrowReward(DDO ddo, int serviceIndex, String serviceAgreementId)Executes the fulfill of the EscrowRewardprivate booleanfulfillLockReward(DDO ddo, int serviceIndex, String serviceAgreementId)Executes the fulfill of the LockRewardConditionDIDgenerateDID(DDO ddo)Given a DDO, returns a DID created using the ddoList<byte[]>generateServiceConditionsId(String serviceAgreementId, String consumerAddress, DDO ddo, int serviceIndex)StringgenerateSignature(String message)List<ComputeLogs>getComputeLogs(String serviceAgreementId, String executionId, String consumerAddress, ProviderConfig providerConfig)Generates the service endpoint and signature and calls the gateway to get the logs of a compute jobComputeStatusgetComputeStatus(String serviceAgreementId, String executionId, String consumerAddress, ProviderConfig providerConfig)Generates the service endpoint and signature and calls the gateway to get the status of a compute jobstatic NeverminedManagergetInstance(io.keyko.common.web3.KeeperService keeperService, MetadataApiService metadataApiService)Given the KeeperService and MetadataApiService, returns a new instance of OceanManager using them as attributesOrdergetOrder(String orderId)private booleaninitializeServiceAgreement(DDO ddo, int serviceIndex, String serviceAgreementId)Initialize a new ServiceExecutionAgreement between a publisher and a consumerprotected booleaninitializeServiceAgreementDirect(DDO ddo, int serviceIndex, String serviceAgreementId)Initialize a new ServiceExecutionAgreement between a publisher and a consumerprotected io.reactivex.Flowable<String>initializeServiceAgreementFlowable(DDO ddo, int serviceIndex, String serviceAgreementId)Initialize a new ServiceExecutionAgreement between a publisher and a consumer return a flowable to listen contract initialization eventsbooleanisConditionFulfilled(String serviceAgreementId, Condition.ConditionTypes conditionType)OrderResultpurchaseAssetDirect(DID did)Purchases an Asset represented by a DID.OrderResultpurchaseAssetDirect(DID did, int serviceIndex)Purchases an Asset represented by a DID.OrderResultpurchaseAssetDirect(DID did, int serviceIndex, Service.ServiceTypes serviceType)Purchases an Asset represented by a DID.OrderResultpurchaseAssetDirect(DID did, Service.ServiceTypes serviceType)Purchases an Asset represented by a DID.io.reactivex.Flowable<OrderResult>purchaseAssetFlowable(DID did, int serviceIndex)Purchases an Asset represented by a DID.DDOregisterAccessServiceAsset(AssetMetadata metadata, ProviderConfig providerConfig)Creates a new DDO with an AccessServiceDDOregisterAccessServiceAsset(AssetMetadata metadata, ProviderConfig providerConfig, AuthConfig authConfig)Creates a new DDO with an AccessServiceprivate DDOregisterAsset(AssetMetadata metadata, ProviderConfig providerConfig, Service service, AuthConfig authConfig)Creates a new DDO, registering it on-chain through DidRegistry contract and off-chain in Metadata ApiDDOregisterComputeService(AssetMetadata metadata, ProviderConfig providerConfig, ComputingService.Provider computingProvider)Creates a new DDO with a ComputeServicebooleanregisterDID(DID did, String url, String checksum, List<String> providers)Given a DID and a Metadata API url, register on-chain the DID.List<AssetMetadata>searchOrders()NeverminedManagersetAgreementManager(AgreementsManager agreementManager)NeverminedManagersetTemplatesManager(TemplatesManager templatesManager)-
Methods inherited from class io.keyko.nevermined.manager.BaseManager
buildDDO, getAccessSecretStoreCondition, getComputeExecutionCondition, getContractAddresses, getDecriptedSecretStoreMetadataFiles, getDecriptedSecretStoreMetadataFiles, getEscrowComputeExecutionTemplate, getEscrowReward, getEvmDto, getKeeperService, getLockRewardCondition, getMainAccount, getMetadataApiService, getProviderAddress, getSecretStoreDto, getSecretStoreManager, getTemplateIdByName, resolveDID, setAccessSecretStoreCondition, setAgreementStoreManagerContract, setComputeExecutionCondition, setConditionStoreManagerContract, setDidRegistryContract, setDispenserContract, setEscrowAccessSecretStoreTemplate, setEscrowComputeExecutionTemplate, setEscrowReward, setEvmDto, setKeeperService, setLockRewardCondition, setMainAccount, setMetadataApiService, setProviderAddress, setSecretStoreDto, setSecretStoreManager, setTemplateStoreManagerContract, setTokenContract, tokenApprove, toString
-
-
-
-
Field Detail
-
log
private static final org.apache.logging.log4j.Logger log
-
agreementsManager
private AgreementsManager agreementsManager
-
templatesManager
private TemplatesManager templatesManager
-
-
Constructor Detail
-
NeverminedManager
protected NeverminedManager(io.keyko.common.web3.KeeperService keeperService, MetadataApiService metadataApiService)
-
-
Method Detail
-
getInstance
public static NeverminedManager getInstance(io.keyko.common.web3.KeeperService keeperService, MetadataApiService metadataApiService)
Given the KeeperService and MetadataApiService, returns a new instance of OceanManager using them as attributes- Parameters:
keeperService- Keeper DtometadataApiService- Provider Dto- Returns:
- NeverminedManager
-
setAgreementManager
public NeverminedManager setAgreementManager(AgreementsManager agreementManager)
-
setTemplatesManager
public NeverminedManager setTemplatesManager(TemplatesManager templatesManager)
-
generateDID
public DID generateDID(DDO ddo) throws DIDFormatException
Given a DDO, returns a DID created using the ddo- Parameters:
ddo- the DDO- Returns:
- DID
- Throws:
DIDFormatException- DIDFormatException
-
registerDID
public boolean registerDID(DID did, String url, String checksum, List<String> providers) throws DIDRegisterException
Given a DID and a Metadata API url, register on-chain the DID. It allows to resolve DDO's using DID's as input- Parameters:
did- the didurl- metadata urlchecksum- calculated hash of the metadataproviders- list of providers addresses to give access- Returns:
- boolean success
- Throws:
DIDRegisterException- DIDRegisterException
-
buildBasicAccessServiceConfiguration
private Map<String,Object> buildBasicAccessServiceConfiguration(ProviderConfig providerConfig, String price, String creatorAddress)
-
buildBasicComputingServiceConfiguration
private Map<String,Object> buildBasicComputingServiceConfiguration(ProviderConfig providerConfig, ComputingService.Provider computingProvider, String price, String creatorAddress)
-
registerAccessServiceAsset
public DDO registerAccessServiceAsset(AssetMetadata metadata, ProviderConfig providerConfig) throws DDOException
Creates a new DDO with an AccessService- Parameters:
metadata- the metadataproviderConfig- the service Endpoints- Returns:
- an instance of the DDO created
- Throws:
DDOException- DDOException
-
registerAccessServiceAsset
public DDO registerAccessServiceAsset(AssetMetadata metadata, ProviderConfig providerConfig, AuthConfig authConfig) throws DDOException
Creates a new DDO with an AccessService- Parameters:
metadata- the metadataproviderConfig- the service EndpointsauthConfig- auth configuration- Returns:
- an instance of the DDO created
- Throws:
DDOException- DDOException
-
registerComputeService
public DDO registerComputeService(AssetMetadata metadata, ProviderConfig providerConfig, ComputingService.Provider computingProvider) throws DDOException
Creates a new DDO with a ComputeService- Parameters:
metadata- the metadataproviderConfig- the service EndpointscomputingProvider- the data relative to the provider- Returns:
- an instance of the DDO created
- Throws:
DDOException- DDOException
-
registerAsset
private DDO registerAsset(AssetMetadata metadata, ProviderConfig providerConfig, Service service, AuthConfig authConfig) throws DDOException
Creates a new DDO, registering it on-chain through DidRegistry contract and off-chain in Metadata Api- Parameters:
metadata- the metadataproviderConfig- the service Endpointsservice- the serviceauthConfig- auth configuration- Returns:
- an instance of the DDO created
- Throws:
DDOException- DDOException
-
isConditionFulfilled
public boolean isConditionFulfilled(String serviceAgreementId, Condition.ConditionTypes conditionType) throws Exception
- Throws:
Exception
-
purchaseAssetDirect
public OrderResult purchaseAssetDirect(DID did) throws OrderException, ServiceException, EscrowRewardException
Purchases an Asset represented by a DID. It implies to initialize a Service Agreement between publisher and consumer- Parameters:
did- the did- Returns:
- true if the asset was purchased successfully, if not false
- Throws:
OrderException- OrderExceptionServiceException- ServiceExceptionEscrowRewardException- EscrowRewardException
-
purchaseAssetDirect
public OrderResult purchaseAssetDirect(DID did, int serviceIndex) throws OrderException, ServiceException, EscrowRewardException
Purchases an Asset represented by a DID. It implies to initialize a Service Agreement between publisher and consumer- Parameters:
did- the didserviceIndex- the index of the service- Returns:
- true if the asset was purchased successfully, if not false
- Throws:
OrderException- OrderExceptionServiceException- ServiceExceptionEscrowRewardException- EscrowRewardException
-
purchaseAssetDirect
public OrderResult purchaseAssetDirect(DID did, Service.ServiceTypes serviceType) throws OrderException, ServiceException, EscrowRewardException
Purchases an Asset represented by a DID. It implies to initialize a Service Agreement between publisher and consumer- Parameters:
did- the didserviceType- Service to purchase- Returns:
- true if the asset was purchased successfully, if not false
- Throws:
OrderException- OrderExceptionServiceException- ServiceExceptionEscrowRewardException- EscrowRewardException
-
purchaseAssetDirect
public OrderResult purchaseAssetDirect(DID did, int serviceIndex, Service.ServiceTypes serviceType) throws OrderException, ServiceException, EscrowRewardException
Purchases an Asset represented by a DID. It implies to initialize a Service Agreement between publisher and consumer- Parameters:
did- the didserviceIndex- the index of the serviceserviceType- Service to purchase- Returns:
- true if the asset was purchased successfully, if not false
- Throws:
OrderException- OrderExceptionServiceException- ServiceExceptionEscrowRewardException- EscrowRewardException
-
purchaseAssetFlowable
public io.reactivex.Flowable<OrderResult> purchaseAssetFlowable(DID did, int serviceIndex) throws OrderException
Purchases an Asset represented by a DID. It implies to initialize a Service Agreement between publisher and consumer- Parameters:
did- the didserviceIndex- the index of the service- Returns:
- a Flowable instance over an OrderResult to get the result of the flow in an asynchronous fashion
- Throws:
OrderException- OrderException
-
downloadAssetByOwner
public boolean downloadAssetByOwner(DID did, int serviceIndex, String basePath) throws ServiceException, ConsumeServiceException
Purchases an Asset represented by a DID. It implies to initialize a Service Agreement between publisher and consumer- Parameters:
did- the didserviceIndex- the service index in the ddo to downloadbasePath- path where we want to download the asset files- Returns:
- true if the asset was purchased successfully, if not false
- Throws:
ServiceException- ServiceExceptionConsumeServiceException- ConsumeServiceException
-
downloadAssetByOwner
public boolean downloadAssetByOwner(DID did, int serviceIndex, String basePath, int fileIndex) throws ServiceException, ConsumeServiceException
Purchases an Asset represented by a DID. It implies to initialize a Service Agreement between publisher and consumer- Parameters:
did- the didserviceIndex- the service index in the ddo to downloadbasePath- path where we want to download the asset filesfileIndex- index of the file inside the files definition in metadata- Returns:
- true if the asset was purchased successfully, if not false
- Throws:
ServiceException- ServiceExceptionConsumeServiceException- ConsumeServiceException
-
generateServiceConditionsId
public List<byte[]> generateServiceConditionsId(String serviceAgreementId, String consumerAddress, DDO ddo, int serviceIndex) throws ServiceAgreementException, ServiceException
-
initializeServiceAgreement
private boolean initializeServiceAgreement(DDO ddo, int serviceIndex, String serviceAgreementId) throws ServiceException, ServiceAgreementException
Initialize a new ServiceExecutionAgreement between a publisher and a consumer- Parameters:
ddo- the ddiserviceIndex- the service indexserviceAgreementId- the service agreement id- Returns:
- true if the agreement was initialized correctly, if not false
- Throws:
ServiceException- ServiceExceptionServiceAgreementException- ServiceAgreementException
-
initializeServiceAgreementDirect
protected boolean initializeServiceAgreementDirect(DDO ddo, int serviceIndex, String serviceAgreementId) throws ServiceException, ServiceAgreementException
Initialize a new ServiceExecutionAgreement between a publisher and a consumer- Parameters:
ddo- the ddiserviceIndex- the service indexserviceAgreementId- the service agreement id- Returns:
- true if the agreement was initialized correctly, if not false
- Throws:
ServiceException- ServiceExceptionServiceAgreementException- ServiceAgreementException
-
initializeServiceAgreementFlowable
protected io.reactivex.Flowable<String> initializeServiceAgreementFlowable(DDO ddo, int serviceIndex, String serviceAgreementId) throws ServiceException, ServiceAgreementException
Initialize a new ServiceExecutionAgreement between a publisher and a consumer return a flowable to listen contract initialization events- Parameters:
ddo- the ddiserviceIndex- the service indexserviceAgreementId- the service agreement id- Returns:
- a Flowable over an AgreementInitializedEventResponse
- Throws:
ServiceException- ServiceExceptionServiceAgreementException- ServiceAgreementException
-
checkAgreementStatus
private boolean checkAgreementStatus(String serviceAgreementId) throws ServiceAgreementException
- Throws:
ServiceAgreementException
-
fulfillLockReward
private boolean fulfillLockReward(DDO ddo, int serviceIndex, String serviceAgreementId) throws ServiceException, LockRewardFulfillException
Executes the fulfill of the LockRewardCondition- Parameters:
ddo- the ddoserviceIndex- the index of the serviceserviceAgreementId- service agreement id- Returns:
- a flag that indicates if the function was executed correctly
- Throws:
ServiceException- ServiceExceptionLockRewardFulfillException- LockRewardFulfillException
-
fulfillEscrowReward
private boolean fulfillEscrowReward(DDO ddo, int serviceIndex, String serviceAgreementId) throws ServiceException, EscrowRewardException
Executes the fulfill of the EscrowReward- Parameters:
ddo- the ddoserviceIndex- the index of the serviceserviceAgreementId- service agreement id- Returns:
- a flag that indicates if the function was executed correctly
- Throws:
ServiceException- ServiceExceptionEscrowRewardException- EscrowRewardException
-
fetchAssetDataBeforeConsume
private Map<String,Object> fetchAssetDataBeforeConsume(DID did, int serviceIndex) throws ConsumeServiceException
Gets the data needed to download an asset- Parameters:
did- the didserviceIndex- the id of the service in the DDO- Returns:
- a Map with the data needed to consume the asset
- Throws:
ConsumeServiceException- ConsumeServiceException
-
access
public boolean access(String serviceAgreementId, DID did, int serviceIndex, String basePath) throws ConsumeServiceException
Downloads an Asset previously ordered through a Service Agreement- Parameters:
serviceAgreementId- the service agreement iddid- the didserviceIndex- the service index in the DDObasePath- the path where the asset will be downloaded- Returns:
- a flag that indicates if the consume operation was executed correctly
- Throws:
ConsumeServiceException- ConsumeServiceException
-
access
public boolean access(String serviceAgreementId, DID did, int serviceIndex, int fileIndex, String basePath) throws ConsumeServiceException
Downloads an Asset previously ordered through a Service Agreement- Parameters:
serviceAgreementId- the service agreement iddid- the didserviceIndex- id of the service in the DDOfileIndex- of the file inside the files definition in metadatabasePath- the path where the asset will be downloaded- Returns:
- a flag that indicates if the consume operation was executed correctly
- Throws:
ConsumeServiceException- ConsumeServiceException
-
buildDestinationPath
private String buildDestinationPath(String basePath, DID did, int fileIndex, AssetMetadata.File file)
Constructs the final path where the file should be downloaded- Parameters:
basePath- the path where the asset will be downloadeddid- the didfileIndex- index of the file inside the files definition in metadatafile- the asset metadata file- Returns:
- the destination path to download the file
-
generateSignature
public String generateSignature(String message) throws IOException, org.web3j.crypto.CipherException
- Throws:
IOExceptionorg.web3j.crypto.CipherException
-
consumeBinary
public InputStream consumeBinary(String serviceAgreementId, DID did, int serviceIndex, int fileIndex) throws ConsumeServiceException
Downloads a single file of an Asset previously ordered through a Service Agreement- Parameters:
serviceAgreementId- the service agreement iddid- the didserviceIndex- the id of the service index in the DDOfileIndex- of the file inside the files definition in metadata- Returns:
- an InputStream that represents the binary content
- Throws:
ConsumeServiceException- ConsumeServiceException
-
consumeBinary
public InputStream consumeBinary(String serviceAgreementId, DID did, int serviceIndex, int fileIndex, Boolean isRangeRequest, Integer rangeStart, Integer rangeEnd) throws ConsumeServiceException
Downloads a single file of an Asset previously ordered through a Service Agreement. It could be a request by range of bytes- Parameters:
serviceAgreementId- the service agreement iddid- the didserviceIndex- id of the service in the DDOfileIndex- of the file inside the files definition in metadataisRangeRequest- indicates if is a request by range of bytesrangeStart- the start of the bytes rangerangeEnd- the end of the bytes range- Returns:
- an InputStream that represents the binary content
- Throws:
ConsumeServiceException- ConsumeServiceException
-
executeComputeService
public GatewayService.ServiceExecutionResult executeComputeService(String agreementId, DID did, int index, DID workflowDID) throws ServiceException
Executes a remote service associated with an asset and serviceAgreementId- Parameters:
agreementId- the agreement iddid- the didindex- the index of the serviceworkflowDID- the workflow id- Returns:
- an execution id
- Throws:
ServiceException- ServiceException
-
getComputeLogs
public List<ComputeLogs> getComputeLogs(String serviceAgreementId, String executionId, String consumerAddress, ProviderConfig providerConfig) throws ServiceException
Generates the service endpoint and signature and calls the gateway to get the logs of a compute job- Parameters:
serviceAgreementId- The agreement id for the compute to the dataexecutionId- The id of the compute jobconsumerAddress- The address of the consumer of the compute to the data jobproviderConfig- The configuration of the provider.- Returns:
- A list of log lines.
- Throws:
ServiceException- Service Exception
-
getComputeStatus
public ComputeStatus getComputeStatus(String serviceAgreementId, String executionId, String consumerAddress, ProviderConfig providerConfig) throws ServiceException
Generates the service endpoint and signature and calls the gateway to get the status of a compute job- Parameters:
serviceAgreementId- The agreement id for the compute to the dataexecutionId- The id of the compute jobconsumerAddress- The address of the consumer of the compute to the data jobproviderConfig- The configuration of the provider.- Returns:
- The current status of the compute job.
- Throws:
ServiceException- Service Exception
-
searchOrders
public List<AssetMetadata> searchOrders()
-
-