Skip to content
This repository was archived by the owner on Jul 12, 2023. It is now read-only.

Resources #23

Merged
merged 1 commit into from
Dec 14, 2016
Merged

Resources #23

merged 1 commit into from
Dec 14, 2016

Conversation

bergman
Copy link
Contributor

@bergman bergman commented Dec 8, 2016

Missing:

  • tests

rc -> proxy("/" + arg("endpoint", rc) + "/" + arg("id", rc), rc)),
Route.async(
"PATCH", BASE + "/<endpoint>/<id>",
rc -> proxy("/" + arg("endpoint", rc) + "/" + arg("id", rc), rc))
Copy link
Member

Choose a reason for hiding this comment

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

You might want to replace these all with just a /<endpoint:path> parameter that will match the rest of the uri. see https://github.com/spotify/apollo/blob/master/apollo-api/docs/routing-engine.md#path-parameters

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, was thinking of that but didn't know how to do it :)

resource = OBJECT_MAPPER.readValue(payload.get().toByteArray(), Resource.class);
} catch (IOException e) {
return Response.forStatus(Status.BAD_REQUEST.withReasonPhrase("Invalid payload."));
}
Copy link
Member

Choose a reason for hiding this comment

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

Use the EntityMiddleware to avoid having to do manual parsing and error handling.

@JsonCreator
public static DataEndpoint create(
@JsonProperty("id") String id,
@JsonProperty("partitioning") Partitioning partitioning,
@JsonProperty("docker_image") Optional<String> dockerImage,
@JsonProperty("docker_args") Optional<List<String>> dockerArgs,
@JsonProperty("secret") Optional<Secret> secret) {
@JsonProperty("secret") Optional<Secret> secret,
@JsonProperty("resources") Optional<List<String>> resources) {
Copy link
Member

Choose a reason for hiding this comment

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

I think jackson can handle parsing a missing key directly into an empty list, without having to wrap it in an optional. For the resources field, a missing key and an empty list should have the same meaning.

public abstract String id();

@JsonProperty
public abstract long concurrency();
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to call it concurrency or limit? "Resource limit" sounds more natural to me than a "Resource concurrency".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The word limit might not convey that it gets replenished after use. Maybe we can look into what wording thread pools use?

json(), "DELETE", BASE + "/<rid>",
rc -> deleteResource(arg("rid", rc))),
Route.with(
json(), "PATCH", BASE + "/<rid>",
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be PUT?

@@ -451,7 +451,8 @@ private TriggerListener trigger(

return (workflow, triggerId, instant) -> {
try {
if (!storage.enabled(workflow.id()) || !storage.globalEnabled()) {
final Set<WorkflowId> enabledWorkflows = storage.enabledWorkflows();
Copy link
Member

Choose a reason for hiding this comment

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

Unrelated change? Why get all the enabled workflows instead of just checking for a specific one?

Copy link
Member

Choose a reason for hiding this comment

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

If it was changed because enabled(WorkflowId) is deprecated, then use storage.workflowState instead.

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!


Resource getResource(String id) {
return entityToResource(
datastore.get(datastore.newKeyFactory().kind(KIND_RESOURCE).newKey(id)));
Copy link
Member

Choose a reason for hiding this comment

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

Potential NPE if the lookup does not find a result.

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!

}

void postResource(Resource resource) {
datastore.put(resourceToEntity(resource));
Copy link
Member

Choose a reason for hiding this comment

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

Wrap in retries?

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!

@@ -20,9 +20,11 @@

package com.spotify.styx.storage;

import com.google.bigtable.repackaged.com.google.common.collect.ImmutableList;
Copy link
Member

Choose a reason for hiding this comment

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

Shaded import

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!

@@ -116,14 +117,14 @@
* @return true if the queried workflow is enabled
*/
@Deprecated
boolean enabled(WorkflowId workflowId) throws IOException;
boolean isWorkflowEnabled(WorkflowId workflowId) throws IOException;
Copy link
Member

Choose a reason for hiding this comment

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

These were named with the argument type in mind, like store(Workflow), delete(WorkflowId), enabled(WorkflowId).

The names are all repetitive now with storeWorkflow(Workflow).

I can see that the last one is be better as isEnabled(WorkflowId), though.

If we want to rename them, then maybe the metric names in MeteredStorage should be aligned too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, forgot about the strings in MeteredStorage. Will have another pass at this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will keep enabledWorkflows and isEnabled but revert the others

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will revert all names :)

@bergman bergman force-pushed the resource branch 2 times, most recently from d688cb8 to 0992ccf Compare December 9, 2016 16:22
return Optional.of(entityToResource(entity));
}

void postResource(Resource resource) throws IOException {
Copy link
Member

Choose a reason for hiding this comment

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

No transaction needed when only doing one operation

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, thanks!

@bergman bergman force-pushed the resource branch 6 times, most recently from 1322c76 to b5df9e3 Compare December 9, 2016 17:11
@rouzwawi
Copy link
Member

@bergman should we wait for cli and tests or are you doing them as separate prs?

@rouzwawi rouzwawi closed this Dec 13, 2016
@rouzwawi rouzwawi reopened this Dec 13, 2016
@bergman
Copy link
Contributor Author

bergman commented Dec 13, 2016

Let's do CLI and tests in a separate PR if you need this now. Just know that this code has never been actually run against datastore (mocked or otherwise).

@rouzwawi
Copy link
Member

Then we should at least do tests in this PR.

@rouzwawi rouzwawi mentioned this pull request Dec 14, 2016
2 tasks
return Api.Version.V1.prefix() + ResourceResource.BASE + path;
}

private Connection setupBigTableMockTable() {
Copy link
Member

Choose a reason for hiding this comment

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

Do we have to set up mocked behaviour for bigtable for this test? I think it would be enough just to send in a plain mock, since none of the paths will interact with bigtable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you're right, will mock instead

awaitResponse(serviceHelper.request("GET", path("")));

assertThat(response, hasStatus(belongsToFamily(StatusType.Family.SUCCESSFUL)));
System.out.println("response.payload().get().utf8() = " + response.payload().get().utf8());
Copy link
Member

Choose a reason for hiding this comment

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

println

Copy link
Contributor Author

Choose a reason for hiding this comment

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

doh!

awaitResponse(serviceHelper.request("PUT", path("/resource2"),
ByteString.encodeUtf8("{\"id\": \"resource2\", \"concurrency\": 3}")));
assertThat(putResponse, hasStatus(belongsToFamily(StatusType.Family.SUCCESSFUL)));
assertJson(putResponse, "id", equalTo("resource2"));
Copy link
Member

Choose a reason for hiding this comment

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

Try not to assert things that are not essential for the test. Checking the put response object is already done in the shouldUpdateResource test case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup, same for first listing i guess, it's the same case as shouldListMultipleResources except that one doesn't POST but uses datastore directly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm, but it makes sense there actually, will keep it

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I was thinking about that but then thought that it makes sense to test that the changes are actually reflected in the api. But checking the put response is not directly related.

@rouzwawi
Copy link
Member

LGTM 👍 :shipit:

@bergman bergman changed the title WIP resource Resources Dec 14, 2016
@bergman bergman merged commit f0e1f70 into master Dec 14, 2016
@bergman bergman deleted the resource branch December 14, 2016 17:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants