Skip to content

Conversation

MakarovS
Copy link
Contributor

@MakarovS MakarovS commented Nov 28, 2019

Overview

Add service info retrieving.
Targeted into ECR-3860 until it's merged.


See: https://jira.bf.local/browse/ECR-3859

Definition of Done

  • There are no TODOs left in the code
  • Change is covered by automated tests
  • The coding guidelines are followed
  • Public API has Javadoc
  • Method preconditions are checked and documented in the Javadoc of the method
  • Changelog is updated if needed (in case of notable or breaking changes)
  • The continuous integration build passes

*
* @param serviceName the name of a service instance
*/
Optional<ServiceInfo> getServiceInfoByName(String serviceName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we use get or find prefix to highlight it returns an Optional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to findServiceInfoByName

Optional<ServiceInfo> getServiceInfoByName(String serviceName);

/**
* Returns the list of service info of all started service instances.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returns information on/about all started service instances.

@see #getServiceInfoByName

String name;

/**
* Service id.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it must use just as good documentation as com.exonum.binding.core.runtime.ServiceInstanceSpec.

}

@Test
void getServiceInfoByInvalidName() throws InterruptedException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name seems OK in this case, but the service is not found by the name. Unknown name/NotFound.



### Retrieving service info
To build a transaction, service id is needed. It can be obtained with either
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This documentation seems out of place. I think it shall be included in the section on creating a transaction message, saying that the service id, required to create a message, can be obtained, if needed, by the service name:

// Update the code to be correct and compile!
int serviceId =  exonumClient.getServiceInfoByName(serviceName)
    .mapToInt(#getId)
    .orElseThrow(() -> new IllegalStateException("No service with the given name found: " + serviceName);

This section may remain, but rewritten as just the way to get information on active services in the blockchain.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but rewritten as just the way to get information on active services in the blockchain.

It still starts as "To build a transaction, service id is needed."



### Retrieving service info
To build a transaction, service id is needed. It can be obtained with either
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but rewritten as just the way to get information on active services in the blockchain.

It still starts as "To build a transaction, service id is needed."

* @param serviceName the name of a service instance
*/
Optional<ServiceInfo> getServiceInfoByName(String serviceName);
Optional<ServiceInfo> findServiceInfoByName(String serviceName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe drop ByName since it must be clear enough from the parameter list and there are no other String query parameters (i.e., no BySomeOtherStringProperty that won't work with overloads)?


List<ServiceInfo> actual = ExplorerApiHelper.parseServicesResponse(json);
assertThat(actual, contains(expected.toArray()));
int serviceId = Optional.of(serviceInfo1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That must be a draft.

List<ServiceInfo> actual = ExplorerApiHelper.parseServicesResponse(json);
assertThat(actual, contains(expected.toArray()));
int serviceId = Optional.of(serviceInfo1)
.map(ServiceInfo::getId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, either I don't understand what exactly do you propose here or it's something like

    int serviceId = Optional.of(serviceInfo1).stream()
        .mapToInt(ServiceInfo::getId)
        .findFirst()
        .orElseThrow(() -> new IllegalStateException("No service with the given name found: " + serviceName);

which doesn't seem better to me.
Optional doesn't have mapToInt method.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, sorry, I must have missed there is no mapToInt in Optional. It's good then, a stream is certainly inferior.

@dmitry-timofeev
Copy link
Contributor

Why does it target ECR-3860 and not master?

@MakarovS
Copy link
Contributor Author

MakarovS commented Dec 2, 2019

Why does it target ECR-3860 and not master?

Sorry, I expected ECR-3860 to be merged before this one and it was easier to develop based on a working version of LC. I still think it's easier to just merge ECR-3860 first, as it's ready as well.

@dmitry-timofeev dmitry-timofeev changed the base branch from ECR-3860 to master December 4, 2019 14:30
@dmitry-timofeev dmitry-timofeev merged commit 24a8f4b into master Dec 6, 2019
@dmitry-timofeev dmitry-timofeev deleted the ECR-3859 branch December 6, 2019 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants