[
https://issues.apache.org/jira/browse/KNOX-2053?focusedWorklogId=329242&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-329242
]
ASF GitHub Bot logged work on KNOX-2053:
----------------------------------------
Author: ASF GitHub Bot
Created on: 16/Oct/19 16:40
Start Date: 16/Oct/19 16:40
Worklog Time Spent: 10m
Work Description: smolnar82 commented on pull request #164: KNOX-2053 -
New REST API to create/read/update/delete service definitions
URL: https://github.com/apache/knox/pull/164#discussion_r335586160
##########
File path:
gateway-server/src/main/java/org/apache/knox/gateway/services/registry/impl/DefaultServiceDefinitionRegistry.java
##########
@@ -82,15 +127,152 @@ public void stop() throws ServiceLifecycleException {
@Override
public ServiceDefEntry getMatchingService(String urlPattern) {
- Matcher<ServiceDefEntry>.Match match = null;
+ readLock.lock();
+ try {
+ Matcher<ServiceDefEntry>.Match match = null;
+ try {
+ match = entries.match(Parser.parseLiteral(urlPattern));
+ } catch (URISyntaxException e) {
+ LOG.failedToParsePath(urlPattern, e);
+ }
+ if (match != null) {
+ return match.getValue();
+ }
+ return null;
+ } finally {
+ readLock.unlock();
+ }
+ }
+
+ @Override
+ public Set<ServiceDefinitionPair> getServiceDefinitions() {
+ readLock.lock();
try {
- match = entries.match(Parser.parseLiteral(urlPattern));
- } catch ( URISyntaxException e ) {
- LOG.failedToParsePath(urlPattern, e);
+ return serviceDefinitions;
+ } finally {
+ readLock.unlock();
+ }
+ }
+
+ @Override
+ public void saveServiceDefinition(ServiceDefinitionPair serviceDefinition)
throws ServiceDefinitionRegistryException {
+ saveOrUpdateServiceDefinition(serviceDefinition, false);
+ }
+
+ @Override
+ public void saveOrUpdateServiceDefinition(ServiceDefinitionPair
serviceDefinition) throws ServiceDefinitionRegistryException {
+ saveOrUpdateServiceDefinition(serviceDefinition, true);
+ }
+
+ public void saveOrUpdateServiceDefinition(ServiceDefinitionPair
serviceDefinition, boolean allowUpdate) throws
ServiceDefinitionRegistryException {
+ final ServiceDefinition service = serviceDefinition.getService();
+ final Optional<ServiceDefinition> persistedServiceDefinition =
findServiceDefinition(service.getName(), service.getRole(),
service.getVersion());
+ if (persistedServiceDefinition.isPresent() && !allowUpdate) {
+ throw new ServiceDefinitionRegistryException("The requested service
definition (" + serviceDefinition.toString() + ") already exists!");
+ } else {
+ writeLock.lock();
+ try {
+ final Path serviceDefinitionFolderPath =
createServiceDefinitionFolders(service.getName(), service.getVersion());
+ writeOutServiceDefinitionFile(service, serviceDefinitionFolderPath);
+ if (serviceDefinition.getRewriteRules() != null) {
+ writeOutRewriteRules(serviceDefinition.getRewriteRules(),
serviceDefinitionFolderPath);
+ }
+ populateServiceDefinitions();
+ } catch (JAXBException | IOException e) {
+ throw new ServiceDefinitionRegistryException("Error while persisting
service definition " + serviceDefinition.toString(), e);
+ } finally {
+ writeLock.unlock();
+ }
+ notifyListeners(service.getName(), service.getRole(),
service.getVersion());
+ }
+ }
+
+ private Path createServiceDefinitionFolders(String name, String version)
throws IOException {
+ final Path serviceDefinitionPath =
Paths.get(gatewayConfig.getGatewayServicesDir(), name, version);
+ return Files.createDirectories(serviceDefinitionPath);
+ }
+
+ private void writeOutServiceDefinitionFile(ServiceDefinition
serviceDefinition, Path serviceDefinitionFolderPath) throws JAXBException,
IOException {
+ final Marshaller marshaller = getJaxbContext().createMarshaller();
+ marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
+ try (BufferedWriter serviceDefinitionXmlFileWriter =
newBufferedWriter(Paths.get(serviceDefinitionFolderPath.toAbsolutePath().toString()
+ "/" + SERVICE_DEFINITION_FILE_NAME),
Review comment:
I'll make this change and submit a new patch
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 329242)
Time Spent: 3h 40m (was: 3.5h)
> Add Service Definition Management to Admin API
> ----------------------------------------------
>
> Key: KNOX-2053
> URL: https://issues.apache.org/jira/browse/KNOX-2053
> Project: Apache Knox
> Issue Type: Improvement
> Components: Server
> Reporter: Larry McCay
> Assignee: Sandor Molnar
> Priority: Major
> Fix For: 1.4.0
>
> Time Spent: 3h 40m
> Remaining Estimate: 0h
>
> Currently, the Admin API allows management and access to topologies,
> descriptors, provider config, etc but does not provide access to the Service
> Definitions for the proxied services.
> Let's expand the API the include to include service defs and allow for
> customization through the API. Changes made via the API will typically
> require a restart and touch of an topology file that is referencing the
> change service def. This may require a separate Jira and effort to address.
> In the meantime, we should be able to change, add and delete service
> definitions including both service and rewrite XML files.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)