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

AMBARI-21008 Integrate AlertTargetService and subresources with swagger #619

Merged

Conversation

g-boros
Copy link
Contributor

@g-boros g-boros commented Mar 10, 2018

Change-Id: Icdbc0221f7d66fc27c051b0cacf04534f3875ae4

What changes were proposed in this pull request?

Add swagger documentation to AlertTarget API endpoints

How was this patch tested?

Generate swagger docs by

test -Drat.skip -Dcheckstyle.skip -DskipTests -Dgenerate.swagger.resources

then manually checking Swagger output at ambari-server/docs/api/generated/index.html

checkstyle using:

clean checkstyle:checkstyle -pl ambari-server

API endpoint calls at api/v1/alert_targets have also been tested manually

please review @Jetly-Jaimin @adoroszlai @benyoka

Change-Id: Icdbc0221f7d66fc27c051b0cacf04534f3875ae4
@asfgit
Copy link

asfgit commented Mar 10, 2018

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/Ambari-Github-PullRequest-Builder/1091/
Test PASSed.

Copy link
Contributor

@adoroszlai adoroszlai left a comment

Choose a reason for hiding this comment

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

Nice, only some minor changes requested.

* @param ui uri info
* @return alert target resource representation
*/
@GET @ApiIgnore // documented below
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 /alert_targets and /alert_targets/{targetId} should be documented separately, since they have a few differences.

@Path("{targetId}")
@Produces("text/plain")
@ApiOperation(value = "Returns a single alert target", response = AlertTargetSwagger.class, responseContainer = "List")
Copy link
Contributor

Choose a reason for hiding this comment

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

List container is appropriate only for the "all targets" endpoint.

* Request / response schema for AlertTarget API Swagger documentation generation. The interface only serves documentation
* generation purposes, it is not meant to be implemented.
*/
public interface AlertTargetSwagger extends ApiModel {
Copy link
Contributor

Choose a reason for hiding this comment

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

To more accurately reflect the JSON document, the outer AlertTarget map should be modelled, too.

"AlertTarget" : {
    "name" : "asdf",
    "notification_type" : "test",
    ...
}

Example:

public interface QuickLinksResponse extends ApiModel {
@ApiModelProperty(name = "QuickLinkInfo")
public QuickLinksResponseInfo getQuickLinksResponseInfo();
public interface QuickLinksResponseInfo {
@ApiModelProperty(name = "file_name")
String getFileName();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@ApiModelProperty(name = AlertGroupResourceProvider.ID_PROPERTY_ID)
Long getId();

@ApiModelProperty(name = "cluster_id")
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use ClusterResourceProvider.CLUSTER_ID.

@ApiResponse(code = HttpStatus.SC_FORBIDDEN, message = MSG_PERMISSION_DENIED),
@ApiResponse(code = HttpStatus.SC_INTERNAL_SERVER_ERROR, message = MSG_SERVER_ERROR),
@ApiResponse(code = HttpStatus.SC_BAD_REQUEST, message = MSG_INVALID_ARGUMENTS),
})
public Response getTargets(@Context HttpHeaders headers,
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally this method should be getTarget, since it returns a single item. If you want to keep the existing name to avoid mixing documentation and refactoring, you can provide a nickname for Swagger.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed to getTarget

Change-Id: I255a77bae1c5239ded10793e2c997bb4ea0783e2
@g-boros
Copy link
Contributor Author

g-boros commented Mar 12, 2018

applied the requested changes, thanks for the suggestions

@asfgit
Copy link

asfgit commented Mar 12, 2018

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/Ambari-Github-PullRequest-Builder/1097/
Test FAILed.
Test FAILured.

@g-boros
Copy link
Contributor Author

g-boros commented Mar 19, 2018

retest this please

@asfgit
Copy link

asfgit commented Mar 19, 2018

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/Ambari-Github-PullRequest-Builder/1235/
Test FAILed.
Test FAILured.

@adoroszlai
Copy link
Contributor

@benyoka Can you please review?

Copy link
Contributor

@benyoka benyoka left a comment

Choose a reason for hiding this comment

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

one minor change


/**
* The {@link AlertTargetService} handles CRUD operation requests for alert
* targets.
*/
@Path("/alert_targets/")
@Api(value = "/alerts", description = "Endpoint for alert specific operations")
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 @Api value should be "Alerts"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks @benyoka. fixed by 0ad81d7

swagger API resource values are not consistently capitalised, probably that confused me. thanks for checking.

ambari-server/docs/api/generated/swagger.json:

{
    "name" : "User Authentication Sources",
    "description" : "Endpoint for user specific authentication source operations"
  }, {
    "name" : "Users",
    "description" : "Endpoint for User specific operations"
  }, {
    "name" : "Views"
  }, {
    "name" : "clusters",
    "description" : "Endpoint for cluster-specific operations"
  }, {
    "name" : "hosts",
    "description" : "Endpoint for host-specific operations"
  },

Change-Id: Ie4ffc4d30eec202f179a147c4a7f93cdca28df7e
@@ -54,7 +54,7 @@
* targets.
*/
@Path("/alert_targets/")
@Api(value = "/alerts", description = "Endpoint for alert specific operations")
@Api(value = "/Alerts", description = "Endpoint for alert specific operations")
public class AlertTargetService extends BaseService {
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 the leading slash is also not needed, so it should be just "Alerts" (other @Api declarations don't use slashes).

Change-Id: I800427c0fd04ea6c10ad96bbd15b52faa5c4e4c1
@adoroszlai adoroszlai merged commit ee0784a into apache:trunk Mar 20, 2018
@asfgit
Copy link

asfgit commented Mar 20, 2018

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/Ambari-Github-PullRequest-Builder/1253/
Test FAILed.
Test FAILured.

@asfgit
Copy link

asfgit commented Mar 20, 2018

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/Ambari-Github-PullRequest-Builder/1259/
Test FAILed.
Test FAILured.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants