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

[SCB-926] support invoking 3rd party service #915

Merged
merged 10 commits into from
Sep 28, 2018

Conversation

yhs0092
Copy link
Member

@yhs0092 yhs0092 commented Sep 19, 2018

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a JIRA issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a JIRA issue. Your pull request should address just this issue, without pulling in other changes.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [SCB-XXX] Fixes bug in ApproximateQuantiles, where you replace SCB-XXX with the appropriate JIRA issue.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean install to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

Support invoking 3rd party service just like invoking ServiceComb microservice registered in service-center.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.08%) to 86.194% when pulling f210638 on yhs0092:3rd_party_invocation into c019638 on apache:master.


/**
* @see #registryMicroserviceMapping(String, String, Class, List)
* @param endpoints the endpoints of 3rd party service. Each of endpoints will be treated as a separated instance.
Copy link
Contributor

Choose a reason for hiding this comment

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

add example for endpoint?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, the example is added in the comment of method registerMicroserviceMappingByEndpoints

.computeIfAbsent(microserviceName,
svcName -> new StaticMicroserviceVersions(this.appManager, app, microserviceName, schemaIntfCls));

microserviceVersions.addInstances(version, instances);
Copy link
Contributor

Choose a reason for hiding this comment

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

addInstances should put inside computeIfAbsent?

Copy link
Member Author

Choose a reason for hiding this comment

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

addInstances is put inside computeIfAbsent. Currently only initial instance method is provided. Users cannot re-set instance info of a 3rd party service.

Assert.assertEquals("abc", stringBodyResponse.getBody());
}

@Path("/rest/it-producer/v1/dataTypeJaxrs")
Copy link
Contributor

Choose a reason for hiding this comment

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

for different deploy mode, target microservice name is different.
so "it-producer" can not hard code
based on zhengyangyong's PR, if that one merged first, then this one will failed.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've checked zhengyangyong's commits and test it by rebasing those commits into my branch. There is no problem with the producer's service name because other deploy mode will not trigger this test.
The only problem is the initialization method of GateRestTemplate is changed. And I've changed to use new initialization method in new commit.

@@ -40,6 +41,8 @@ public static CseContext getInstance() {

private ConsumerSchemaFactory consumerSchemaFactory;

private StaticSchemaFactory staticSchemaFactory;
Copy link
Contributor

Choose a reason for hiding this comment

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

CseContext will de Deprecated, use ScbEngine

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

@@ -103,4 +109,12 @@ protected SwaggerGenerator generateSwagger(CONTEXT context) {

return generator;
}

protected String getSwaggerContent(Swagger swagger) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we just use SwaggerUtils?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.


MicroserviceInstance instance = new MicroserviceInstance();
instance.setEndpoints(Collections.singletonList(endpoint));
RegistryUtils.getServiceRegistry()
Copy link
Contributor

@liubao68 liubao68 Sep 20, 2018

Choose a reason for hiding this comment

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

There are two scenarios need to consider:

  1. consumers register producers endpoints and schemas
  2. consumers register only schemas, this is quite common in mesher mode which the service is already registered to service center but schemas are not, and used very widely

Can we provide scenario 2 support?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've asked wujimin's opinion and maybe we can have a new discussion on the scenario that there are microservices registered in sc with only instance info but no schema.
This issue is planned to provide the basic ability to invoke 3rd party service.

@@ -45,6 +48,8 @@
@Inject
protected CompositeSwaggerGeneratorContext compositeSwaggerGeneratorContext;

private ObjectWriter writer = Yaml.pretty();
Copy link
Contributor

Choose a reason for hiding this comment

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

unused code?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, has been fixed.

private MicroserviceMeta microserviceMeta;
MicroserviceMeta microserviceMeta;

MicroserviceVersionMeta(Microservice microservice) {
Copy link
Contributor

@liubao68 liubao68 Sep 26, 2018

Choose a reason for hiding this comment

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

microserviceMeta is not initialized, and getMicroserviceMeta may return null and cause NPE.
From the following code, I think it's better to define the method protected that should be overrided by sub class.
Or remove this constructor and define microserviceMeta to be protected.

Copy link
Member Author

Choose a reason for hiding this comment

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

microserviceMeta in MicroserviceVersionMeta is initialized in constructors and has package access modifier which ensures that the classes out of its package can only get access to it by getter method. So I think NPE can be avoid since users can only get microserviceMeta after it is initialized.

* @param instances the instances of this 3rd party service. Users only need to specify the endpoint information, other
* necessary information will be generate and set in the implementation of this method.
*/
void registerMicroserviceMapping(String microserviceName, String version, Class<?> schemaIntfCls,
Copy link
Contributor

Choose a reason for hiding this comment

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

It's better to put schemaIntfCls as last parameter, since we can extend it to schemaIntfCls... to support several schemas. I think this is quite normal in many scenarios like register a gateway service as a third party service.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I think we should consider multiple schemas in the next step.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

@liubao68 liubao68 merged commit f304598 into apache:master Sep 28, 2018
@yhs0092 yhs0092 deleted the 3rd_party_invocation branch December 14, 2019 02:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants