-
Notifications
You must be signed in to change notification settings - Fork 353
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
Added a /properties endpoint, with the ability to configure which pro… #1471
Merged
p013570
merged 8 commits into
develop
from
gh-1420-Add-a-/properties-endpoint-to-the-REST-API
Oct 31, 2017
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b6da5a0
Added a /properties endpoint, with the ability to configure which pro…
james010101101 b2bed14
Merge branch 'develop' into gh-1420-Add-a-/properties-endpoint-to-the…
t616178 f86aad8
Changing the properties map to store string values and return only te…
james010101101 6d18068
Merge branch 'gh-1420-Add-a-/properties-endpoint-to-the-REST-API' of …
james010101101 5d5c33c
Merge branch 'develop' into gh-1420-Add-a-/properties-endpoint-to-the…
p013570 3ad4c97
Get properties from the internal system.getProperty calls every time …
james010101101 b183119
gh-1420 - minor optimisation to map creation
p013570 1ed0d85
Merge remote-tracking branch 'origin/develop' into gh-1420-Add-a-/pro…
p013570 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...-api/core-rest/src/main/java/uk/gov/gchq/gaffer/rest/service/v2/IPropertiesServiceV2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2016-2017 Crown Copyright | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package uk.gov.gchq.gaffer.rest.service.v2; | ||
|
||
import io.swagger.annotations.Api; | ||
import io.swagger.annotations.ApiOperation; | ||
import io.swagger.annotations.ApiParam; | ||
import io.swagger.annotations.ApiResponse; | ||
import io.swagger.annotations.ApiResponses; | ||
|
||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.Response; | ||
|
||
import java.util.Map; | ||
|
||
import static javax.ws.rs.core.MediaType.APPLICATION_JSON; | ||
import static javax.ws.rs.core.MediaType.TEXT_PLAIN; | ||
import static uk.gov.gchq.gaffer.rest.ServiceConstants.INTERNAL_SERVER_ERROR; | ||
import static uk.gov.gchq.gaffer.rest.ServiceConstants.OK; | ||
import static uk.gov.gchq.gaffer.rest.ServiceConstants.PROPERTY_NOT_FOUND; | ||
|
||
/** | ||
* An {@code IPropertiesServiceV2} has methods to GET a list of configured system properties | ||
*/ | ||
@Path("/properties") | ||
@Produces(APPLICATION_JSON) | ||
@Consumes(APPLICATION_JSON) | ||
@Api(value = "properties") | ||
public interface IPropertiesServiceV2 { | ||
|
||
@GET | ||
@Path("/") | ||
@ApiOperation(value = "Gets all available properties", response = Map.class, produces = APPLICATION_JSON) | ||
@ApiResponses(value = {@ApiResponse(code = 200, message = OK), @ApiResponse(code = 500, message = INTERNAL_SERVER_ERROR)}) | ||
Response getProperties(); | ||
|
||
@GET | ||
@Path("/{propertyName}") | ||
@Produces(TEXT_PLAIN) | ||
@ApiOperation(value = "Gets the property value for the specified property name.", response = String.class, produces = TEXT_PLAIN) | ||
@ApiResponses(value = {@ApiResponse(code = 200, message = OK), | ||
@ApiResponse(code = 404, message = PROPERTY_NOT_FOUND), | ||
@ApiResponse(code = 500, message = INTERNAL_SERVER_ERROR)}) | ||
Response getProperty(@ApiParam(value = "the property name") @PathParam("propertyName") final String propertyName); | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
rest-api/core-rest/src/main/java/uk/gov/gchq/gaffer/rest/service/v2/PropertiesServiceV2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2016-2017 Crown Copyright | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package uk.gov.gchq.gaffer.rest.service.v2; | ||
|
||
import org.apache.commons.lang.StringUtils; | ||
|
||
import uk.gov.gchq.gaffer.rest.ServiceConstants; | ||
|
||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.core.Response.ResponseBuilder; | ||
|
||
import java.util.Collections; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* An implementation of {@link IPropertiesServiceV2} that gets the configured system properties | ||
*/ | ||
public class PropertiesServiceV2 implements IPropertiesServiceV2 { | ||
private static final String PROPERTIES_LIST = "gaffer.properties"; | ||
|
||
@Override | ||
public Response getProperties() { | ||
final Map<String, String> properties; | ||
|
||
final String propertiesList = System.getProperty(PROPERTIES_LIST); | ||
if (null == propertiesList) { | ||
properties = Collections.emptyMap(); | ||
} else { | ||
final String[] props = propertiesList.split(","); | ||
properties = new LinkedHashMap<>(props.length); | ||
for (final String prop : props) { | ||
if (StringUtils.isNotEmpty(prop)) { | ||
properties.put(prop, System.getProperty(prop)); | ||
} | ||
} | ||
} | ||
|
||
return Response.ok(Collections.unmodifiableMap(properties)) | ||
.header(ServiceConstants.GAFFER_MEDIA_TYPE_HEADER, ServiceConstants.GAFFER_MEDIA_TYPE) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public Response getProperty(final String propertyName) { | ||
final String prop = System.getProperty(propertyName); | ||
final ResponseBuilder builder = null == prop ? Response.status(404) : Response.ok(prop); | ||
return builder.header(ServiceConstants.GAFFER_MEDIA_TYPE_HEADER, ServiceConstants.GAFFER_MEDIA_TYPE).build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
rest-api/core-rest/src/test/java/uk/gov/gchq/gaffer/rest/service/v2/PropertyServiceV2IT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package uk.gov.gchq.gaffer.rest.service.v2; | ||
/* | ||
* Copyright 2017 Crown Copyright | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import org.junit.Test; | ||
|
||
import javax.ws.rs.core.Response; | ||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class PropertyServiceV2IT extends AbstractRestApiV2IT { | ||
|
||
@Test | ||
public void shouldThrowErrorOnUnknownPropertyWhenNoneSet() throws IOException { | ||
//Given | ||
|
||
// When | ||
final Response response = getClient().getProperty("UNKNOWN"); | ||
|
||
//Then | ||
assertEquals(404, response.getStatus()); | ||
} | ||
|
||
@Test | ||
public void shouldThrowErrorOnUnknownProperty() throws IOException { | ||
//Given | ||
System.setProperty("gaffer.properties", "gaffer.test1,gaffer.test2"); | ||
System.setProperty("gaffer.test1", "1"); | ||
System.setProperty("gaffer.test2", "3"); | ||
|
||
// When | ||
final Response response = getClient().getProperty("UNKNOWN"); | ||
|
||
//Then | ||
assertEquals(404, response.getStatus()); | ||
} | ||
|
||
@Test | ||
public void shouldGetAllProperties() throws IOException { | ||
//Given | ||
System.setProperty("gaffer.properties", "gaffer.test1,gaffer.test2"); | ||
System.setProperty("gaffer.test1", "1"); | ||
System.setProperty("gaffer.test2", "3"); | ||
// When | ||
final Response response = getClient().getProperties(); | ||
|
||
//Then | ||
assertEquals(200, response.getStatus()); | ||
Map<String, Object> properties = response.readEntity(Map.class); | ||
assertEquals(2, properties.size()); | ||
assertEquals("1", properties.get("gaffer.test1")); | ||
assertEquals("3", properties.get("gaffer.test2")); | ||
} | ||
|
||
@Test | ||
public void shouldGetKnownProperty() throws IOException { | ||
//Given | ||
System.setProperty("gaffer.properties", "gaffer.test1,gaffer.test2"); | ||
System.setProperty("gaffer.test1", "1"); | ||
System.setProperty("gaffer.test2", "3"); | ||
// When | ||
final Response response = getClient().getProperty("gaffer.test1"); | ||
|
||
//Then | ||
assertEquals(200, response.getStatus()); | ||
String property = response.readEntity(String.class); | ||
assertEquals("1", property); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a duplicated line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They look like different lines to me - one is used when a Function isn't found and one is used when a Property is not found.