You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by jl...@apache.org on 2017/07/19 06:42:43 UTC
[2/3] ambari git commit: AMBARI-21467: Json Software Registry
Implementation (jluniya)
http://git-wip-us.apache.org/repos/asf/ambari/blob/4450fd7e/ambari-server/src/main/java/org/apache/ambari/server/controller/RegistryRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/RegistryRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/RegistryRequest.java
index 04f354f..0a38d06 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/RegistryRequest.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/RegistryRequest.java
@@ -19,49 +19,93 @@ package org.apache.ambari.server.controller;
import org.apache.ambari.server.registry.RegistryType;
+/**
+ * Represents a registry request
+ */
public class RegistryRequest {
- private Long registryId;
- private String registryName;
- private RegistryType registryType;
- private String registryUri;
+ private Long registryId;
+ private String registryName;
+ private RegistryType registryType;
+ private String registryUri;
- public RegistryRequest(Long registryId, String registryName, RegistryType registryType, String registryUri) {
- this.registryId = registryId;
- this.registryName = registryName;
- this.registryType = registryType;
- this.registryUri = registryUri;
- }
+ /**
+ * Constructor
+ *
+ * @param registryId registry id
+ * @param registryName registry name
+ * @param registryType registry type
+ * @param registryUri registry uri
+ */
+ public RegistryRequest(Long registryId, String registryName, RegistryType registryType, String registryUri) {
+ this.registryId = registryId;
+ this.registryName = registryName;
+ this.registryType = registryType;
+ this.registryUri = registryUri;
+ }
- public Long getRegistryId() {
- return registryId;
- }
+ /**
+ * Get registry id
+ *
+ * @return
+ */
+ public Long getRegistryId() {
+ return registryId;
+ }
- public void setRegistryId(Long registryId) {
- this.registryId = registryId;
- }
+ /**
+ * Set registry id
+ * @param registryId
+ */
+ public void setRegistryId(Long registryId) {
+ this.registryId = registryId;
+ }
- public String getRegistryName() {
- return registryName;
- }
+ /**
+ * Get registry name
+ * @return
+ */
+ public String getRegistryName() {
+ return registryName;
+ }
- public void setRegistryName(String registryName) {
- this.registryName = registryName;
- }
+ /**
+ * Set registry name
+ * @param registryName
+ */
+ public void setRegistryName(String registryName) {
+ this.registryName = registryName;
+ }
- public RegistryType getRegistryType() {
- return registryType;
- }
+ /**
+ * Get registry type
+ * @return
+ */
+ public RegistryType getRegistryType() {
+ return registryType;
+ }
- public void setRegistryType(RegistryType registryType) {
- this.registryType = registryType;
- }
+ /**
+ * Set registry type
+ * @param registryType
+ */
+ public void setRegistryType(RegistryType registryType) {
+ this.registryType = registryType;
+ }
- public String getRegistryUri() {
- return registryUri;
- }
+ /**
+ * Get registry uri
+ * @return
+ */
+ public String getRegistryUri() {
+ return registryUri;
+ }
- public void setRegistryUri(String registryUri) {
- this.registryUri = registryUri;
- }
+ /**
+ * Set registry uri
+ * @param registryUri
+ */
+ public void setRegistryUri(String registryUri) {
+ this.registryUri = registryUri;
+ }
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/4450fd7e/ambari-server/src/main/java/org/apache/ambari/server/controller/RegistryScenarioRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/RegistryScenarioRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/RegistryScenarioRequest.java
new file mode 100644
index 0000000..964f531
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/RegistryScenarioRequest.java
@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 org.apache.ambari.server.controller;
+
+/**
+ * Represents a registry scenario request
+ */
+public class RegistryScenarioRequest {
+ private Long registryId;
+ private String scenarioName;
+
+ /**
+ * Constructor
+ * @param registryId registry id
+ * @param scenarioName scenario name
+ */
+ public RegistryScenarioRequest(Long registryId, String scenarioName) {
+ this.registryId = registryId;
+ this.scenarioName = scenarioName;
+ }
+
+ /**
+ * Get registry id
+ * @return
+ */
+ public Long getRegistryId() {
+ return registryId;
+ }
+
+ /**
+ * Get registry name
+ * @return
+ */
+ public String getScenarioName() {
+ return scenarioName;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/4450fd7e/ambari-server/src/main/java/org/apache/ambari/server/controller/RegistryScenarioResponse.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/RegistryScenarioResponse.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/RegistryScenarioResponse.java
new file mode 100644
index 0000000..fd8c993
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/RegistryScenarioResponse.java
@@ -0,0 +1,112 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 org.apache.ambari.server.controller;
+
+import java.util.List;
+
+import org.apache.ambari.server.controller.internal.RegistryScenarioResourceProvider;
+import org.apache.ambari.server.registry.RegistryScenarioMpack;
+
+import io.swagger.annotations.ApiModelProperty;
+
+/**
+ * Represents a registry scenario response.
+ */
+public class RegistryScenarioResponse {
+ private Long registryId;
+ private String scenarioName;
+ private String scenarioDescription;
+ private List<? extends RegistryScenarioMpack> scenarioMpacks;
+
+ /**
+ * Constructor
+ * @param registryId registry id
+ * @param scenarioName scenario name
+ * @param scenarioDescription scenario description
+ * @param scenarioMpacks list of scenario mpacks
+ */
+ public RegistryScenarioResponse(
+ Long registryId, String scenarioName, String scenarioDescription, List<? extends RegistryScenarioMpack> scenarioMpacks) {
+ this.registryId = registryId;
+ this.scenarioName = scenarioName;
+ this.scenarioDescription = scenarioDescription;
+ this.scenarioMpacks = scenarioMpacks;
+ }
+
+ /**
+ * Get registry id
+ * @return
+ */
+ public Long getRegistryId() {
+ return registryId;
+ }
+
+ /**
+ * Get scenario name
+ * @return
+ */
+ public String getScenarioName() {
+ return scenarioName;
+ }
+
+ /**
+ * Get scenario description
+ * @return
+ */
+ public String getScenarioDescription() {
+ return scenarioDescription;
+ }
+
+ /**
+ * Get list of scenario
+ * @return
+ */
+ public List<? extends RegistryScenarioMpack> getScenarioMpacks() {
+ return scenarioMpacks;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode() {
+ int result = 1;
+ result = 31 + getRegistryId().hashCode();
+ result = 31 + getScenarioName().hashCode();
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof RegistryScenarioResponse)) {
+ return false;
+ }
+ if (this == obj) {
+ return true;
+ }
+ RegistryScenarioResponse registryScenarioResponse = (RegistryScenarioResponse) obj;
+ return (getRegistryId().equals(registryScenarioResponse.getRegistryId()) &&
+ getScenarioName().equals(registryScenarioResponse.getScenarioName()));
+ }
+
+ public interface RegistryScenarioResponseWrapper extends ApiModel {
+ @ApiModelProperty(name = RegistryScenarioResourceProvider.RESPONSE_KEY)
+ @SuppressWarnings("unused")
+ RegistryScenarioResponse getRegistryScenarioResponse();
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/4450fd7e/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractControllerResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractControllerResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractControllerResourceProvider.java
index 672abc7..5cfcdc7 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractControllerResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractControllerResourceProvider.java
@@ -182,6 +182,12 @@ public abstract class AbstractControllerResourceProvider extends AbstractAuthori
return new StackResourceProvider(propertyIds, keyPropertyIds, managementController);
case Registry:
return new RegistryResourceProvider(managementController);
+ case RegistryScenario:
+ return new RegistryScenarioResourceProvider(managementController);
+ case RegistryMpack:
+ return new RegistryMpackResourceProvider(managementController);
+ case RegistryMpackVersion:
+ return new RegistryMpackVersionResourceProvider(managementController);
case Mpack:
return new MpackResourceProvider(managementController);
case StackVersion:
http://git-wip-us.apache.org/repos/asf/ambari/blob/4450fd7e/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RegistryMpackResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RegistryMpackResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RegistryMpackResourceProvider.java
new file mode 100644
index 0000000..69d3d63
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RegistryMpackResourceProvider.java
@@ -0,0 +1,202 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 org.apache.ambari.server.controller.internal;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.ObjectNotFoundException;
+import org.apache.ambari.server.ParentObjectNotFoundException;
+import org.apache.ambari.server.controller.AmbariManagementController;
+import org.apache.ambari.server.controller.RegistryMpackRequest;
+import org.apache.ambari.server.controller.RegistryMpackResponse;
+import org.apache.ambari.server.controller.spi.NoSuchParentResourceException;
+import org.apache.ambari.server.controller.spi.NoSuchResourceException;
+import org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.spi.Request;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.spi.SystemException;
+import org.apache.ambari.server.controller.spi.UnsupportedPropertyException;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.apache.ambari.server.exceptions.RegistryMpackNotFoundException;
+import org.apache.ambari.server.registry.Registry;
+import org.apache.ambari.server.registry.RegistryMpack;
+
+/**
+ * ResourceProvider for mpacks in software registry
+ */
+public class RegistryMpackResourceProvider extends AbstractControllerResourceProvider {
+ public static final String RESPONSE_KEY = "RegistryMpackInfo";
+ public static final String ALL_PROPERTIES = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "*";
+ public static final String REGISTRY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "registry_id";
+ public static final String REGISTRY_MPACK_NAME = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "mpack_name";
+ public static final String REGISTRY_MPACK_DESC = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "mpack_description";
+ public static final String REGISTRY_MPACK_LOGO_URL = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "mpack_logo_url";
+
+ private static Set<String> pkPropertyIds = new HashSet<>(
+ Arrays.asList(REGISTRY_ID, REGISTRY_MPACK_NAME));
+
+ /**
+ * The property ids for a software registry resource.
+ */
+ private static final Set<String> PROPERTY_IDS = new HashSet<>();
+
+ /**
+ * The key property ids for a software registry resource.
+ */
+ private static final Map<Resource.Type, String> KEY_PROPERTY_IDS = new HashMap<>();
+
+ static {
+ // properties
+ PROPERTY_IDS.add(REGISTRY_ID);
+ PROPERTY_IDS.add(REGISTRY_MPACK_NAME);
+ PROPERTY_IDS.add(REGISTRY_MPACK_DESC);
+ PROPERTY_IDS.add(REGISTRY_MPACK_LOGO_URL);
+
+ // keys
+ KEY_PROPERTY_IDS.put(Resource.Type.Registry, REGISTRY_ID);
+ KEY_PROPERTY_IDS.put(Resource.Type.RegistryMpack, REGISTRY_MPACK_NAME);
+ }
+
+ /**
+ * Create a new resource provider for the given management controller.
+ *
+ * @param managementController the management controller
+ */
+ protected RegistryMpackResourceProvider(final AmbariManagementController managementController) {
+ super(PROPERTY_IDS, KEY_PROPERTY_IDS, managementController);
+ }
+
+ /**
+ * {@inheritDoc}
+ * @return
+ */
+ @Override
+ protected Set<String> getPKPropertyIds() {
+ return pkPropertyIds;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @return
+ */
+ @Override
+ public Set<Resource> getResourcesAuthorized(Request request, Predicate predicate)
+ throws SystemException, UnsupportedPropertyException,
+ NoSuchResourceException, NoSuchParentResourceException {
+
+ final Set<RegistryMpackRequest> requests = new HashSet<>();
+
+ if (predicate == null) {
+ requests.add(getRequest(Collections.<String, Object>emptyMap()));
+ } else {
+ for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) {
+ requests.add(getRequest(propertyMap));
+ }
+ }
+
+ Set<String> requestedIds = getRequestPropertyIds(request, predicate);
+
+ Set<RegistryMpackResponse> responses = getResources(new Command<Set<RegistryMpackResponse>>() {
+ @Override
+ public Set<RegistryMpackResponse> invoke() throws AmbariException {
+ return getRegistryMpacks(requests);
+ }
+ });
+
+ Set<Resource> resources = new HashSet<>();
+ for (RegistryMpackResponse response : responses) {
+ Resource resource = new ResourceImpl(Resource.Type.RegistryMpack);
+ setResourceProperty(resource, REGISTRY_ID, response.getRegistryId(), requestedIds);
+ setResourceProperty(resource, REGISTRY_MPACK_NAME, response.getMpackName(), requestedIds);
+ setResourceProperty(resource, REGISTRY_MPACK_DESC, response.getMpackDescription(), requestedIds);
+ setResourceProperty(resource, REGISTRY_MPACK_LOGO_URL, response.getMpackLogoUrl(), requestedIds);
+ resources.add(resource);
+ }
+ return resources;
+ }
+
+ private RegistryMpackRequest getRequest(Map<String, Object> properties) {
+
+ Long registryId = properties.containsKey(REGISTRY_ID) && properties.get(REGISTRY_ID) != null?
+ Long.valueOf((String) properties.get(REGISTRY_ID)) : null;
+ String mpackName = properties.containsKey(REGISTRY_MPACK_NAME)?
+ (String) properties.get(REGISTRY_MPACK_NAME) : null;
+ RegistryMpackRequest registryMpackRequest = new RegistryMpackRequest(registryId, mpackName);
+ return registryMpackRequest;
+ }
+
+ private Set<RegistryMpackResponse> getRegistryMpacks(Set<RegistryMpackRequest> requests)
+ throws AmbariException {
+ Set<RegistryMpackResponse> responses = new HashSet<>();
+ for (RegistryMpackRequest request : requests) {
+ try {
+ responses.addAll(getRegistryMpacks(request));
+ } catch (RegistryMpackNotFoundException e) {
+ if (requests.size() == 1) {
+ // only throw exception if 1 request.
+ // there will be > 1 request in case of OR predicate
+ throw e;
+ }
+ }
+ }
+ return responses;
+ }
+
+ private Set<RegistryMpackResponse> getRegistryMpacks(RegistryMpackRequest request)
+ throws AmbariException {
+ if (request.getRegistryId() == null) {
+ throw new AmbariException("Invalid arguments, registry id cannot be null");
+ }
+ AmbariManagementController amc = getManagementController();
+ final Registry registry;
+ try {
+ registry = amc.getRegistry(request.getRegistryId());
+ } catch (ObjectNotFoundException e) {
+ throw new ParentObjectNotFoundException("Parent registry resource doesn't exist", e);
+ }
+ Set<RegistryMpackResponse> responses = new HashSet<>();
+
+ if(request.getMpackName() == null) {
+ for (RegistryMpack registryMpack : registry.getRegistryMpacks()) {
+ RegistryMpackResponse response = new RegistryMpackResponse(
+ registry.getRegistryId(),
+ registryMpack.getMpackName(),
+ registryMpack.getMpackDescription(),
+ registryMpack.getMpackLogoUrl());
+ responses.add(response);
+ }
+ } else {
+ RegistryMpack registryMpack = registry.getRegistryMpack(request.getMpackName());
+ if(registryMpack != null) {
+ RegistryMpackResponse response = new RegistryMpackResponse(
+ registry.getRegistryId(),
+ registryMpack.getMpackName(),
+ registryMpack.getMpackDescription(),
+ registryMpack.getMpackLogoUrl());
+ responses.add(response);
+ }
+ }
+ return responses;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/4450fd7e/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RegistryMpackVersionResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RegistryMpackVersionResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RegistryMpackVersionResourceProvider.java
new file mode 100644
index 0000000..32cf234
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RegistryMpackVersionResourceProvider.java
@@ -0,0 +1,235 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 org.apache.ambari.server.controller.internal;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.ObjectNotFoundException;
+import org.apache.ambari.server.ParentObjectNotFoundException;
+import org.apache.ambari.server.controller.AmbariManagementController;
+import org.apache.ambari.server.controller.RegistryMpackVersionRequest;
+import org.apache.ambari.server.controller.RegistryMpackVersionResponse;
+import org.apache.ambari.server.controller.spi.NoSuchParentResourceException;
+import org.apache.ambari.server.controller.spi.NoSuchResourceException;
+import org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.spi.Request;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.spi.SystemException;
+import org.apache.ambari.server.controller.spi.UnsupportedPropertyException;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.apache.ambari.server.exceptions.RegistryMpackNotFoundException;
+import org.apache.ambari.server.registry.Registry;
+import org.apache.ambari.server.registry.RegistryMpack;
+import org.apache.ambari.server.registry.RegistryMpackVersion;
+
+/**
+ * ResourceProvider for mpacks in software registry
+ */
+public class RegistryMpackVersionResourceProvider extends AbstractControllerResourceProvider {
+ public static final String RESPONSE_KEY = "RegistryMpackVersionInfo";
+ public static final String ALL_PROPERTIES = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "*";
+
+ public static final String REGISTRY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "registry_id";
+ public static final String REGISTRY_MPACK_NAME = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "mpack_name";
+ public static final String REGISTRY_MPACK_VERSION = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "mpack_version";
+ public static final String REGISTRY_MPACK_BUILDNUM = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "mpack_buildnum";
+ public static final String REGISTRY_MPACK_URL = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "mpack_url";
+ public static final String REGISTRY_MPACK_DOC_URL = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "mpack_doc_url";
+ public static final String REGISTRY_MPACK_SERVICES = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "services";
+ public static final String REGISTRY_MPACK_COMPATIBLE_MPACKS = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "compatible_mpacks";
+
+ private static Set<String> pkPropertyIds = new HashSet<>(
+ Arrays.asList(REGISTRY_ID, REGISTRY_MPACK_NAME));
+
+ /**
+ * The property ids for a software registry resource.
+ */
+ private static final Set<String> PROPERTY_IDS = new HashSet<>();
+
+ /**
+ * The key property ids for a software registry resource.
+ */
+ private static final Map<Resource.Type, String> KEY_PROPERTY_IDS = new HashMap<>();
+
+ static {
+ // properties
+ PROPERTY_IDS.add(REGISTRY_ID);
+ PROPERTY_IDS.add(REGISTRY_MPACK_NAME);
+ PROPERTY_IDS.add(REGISTRY_MPACK_VERSION);
+ PROPERTY_IDS.add(REGISTRY_MPACK_BUILDNUM);
+ PROPERTY_IDS.add(REGISTRY_MPACK_URL);
+ PROPERTY_IDS.add(REGISTRY_MPACK_DOC_URL);
+ PROPERTY_IDS.add(REGISTRY_MPACK_SERVICES);
+ PROPERTY_IDS.add(REGISTRY_MPACK_COMPATIBLE_MPACKS);
+
+ // keys
+ KEY_PROPERTY_IDS.put(Resource.Type.Registry, REGISTRY_ID);
+ KEY_PROPERTY_IDS.put(Resource.Type.RegistryMpack, REGISTRY_MPACK_NAME);
+ KEY_PROPERTY_IDS.put(Resource.Type.RegistryMpackVersion, REGISTRY_MPACK_VERSION);
+ }
+
+ /**
+ * Create a new resource provider for the given management controller.
+ *
+ * @param managementController the management controller
+ */
+ protected RegistryMpackVersionResourceProvider(final AmbariManagementController managementController) {
+ super(PROPERTY_IDS, KEY_PROPERTY_IDS, managementController);
+ }
+
+ /**
+ * {@inheritDoc}
+ * @return
+ */
+ @Override
+ protected Set<String> getPKPropertyIds() {
+ return pkPropertyIds;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<Resource> getResourcesAuthorized(Request request, Predicate predicate)
+ throws SystemException, UnsupportedPropertyException,
+ NoSuchResourceException, NoSuchParentResourceException {
+
+ final Set<RegistryMpackVersionRequest> requests = new HashSet<>();
+
+ if (predicate == null) {
+ requests.add(getRequest(Collections.<String, Object>emptyMap()));
+ } else {
+ for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) {
+ requests.add(getRequest(propertyMap));
+ }
+ }
+
+ Set<String> requestedIds = getRequestPropertyIds(request, predicate);
+ Set<RegistryMpackVersionResponse> responses = getResources(new Command<Set<RegistryMpackVersionResponse>>() {
+ @Override
+ public Set<RegistryMpackVersionResponse> invoke() throws AmbariException {
+ return getRegistryMpackVersions(requests);
+ }
+ });
+
+ Set<Resource> resources = new HashSet<>();
+ for (RegistryMpackVersionResponse response : responses) {
+ Resource resource = new ResourceImpl(Resource.Type.RegistryMpackVersion);
+ setResourceProperty(resource, REGISTRY_ID, response.getRegistryId(), requestedIds);
+ setResourceProperty(resource, REGISTRY_MPACK_NAME, response.getMpackName(), requestedIds);
+ setResourceProperty(resource, REGISTRY_MPACK_VERSION, response.getMpackVersion(), requestedIds);
+ setResourceProperty(resource, REGISTRY_MPACK_BUILDNUM, response.getMpackBuildNumber(), requestedIds);
+ setResourceProperty(resource, REGISTRY_MPACK_URL, response.getMpackUrl(), requestedIds);
+ setResourceProperty(resource, REGISTRY_MPACK_DOC_URL, response.getMpackDocUrl(), requestedIds);
+ setResourceProperty(resource, REGISTRY_MPACK_SERVICES, response.getMpackServices(), requestedIds);
+ setResourceProperty(resource, REGISTRY_MPACK_COMPATIBLE_MPACKS, response.getCompatibleMpacks(), requestedIds);
+ resources.add(resource);
+ }
+ return resources;
+ }
+
+ private RegistryMpackVersionRequest getRequest(Map<String, Object> properties) {
+
+ Long registryId = properties.containsKey(REGISTRY_ID) && properties.get(REGISTRY_ID) != null?
+ Long.valueOf((String) properties.get(REGISTRY_ID)) : null;
+ String mpackName = properties.containsKey(REGISTRY_MPACK_NAME)?
+ (String) properties.get(REGISTRY_MPACK_NAME) : null;
+ String mpackVersion = properties.containsKey(REGISTRY_MPACK_VERSION)?
+ (String) properties.get(REGISTRY_MPACK_VERSION) : null;
+
+ RegistryMpackVersionRequest registryMpackVersionRequest = new RegistryMpackVersionRequest(
+ registryId, mpackName, mpackVersion);
+ return registryMpackVersionRequest;
+ }
+
+ private Set<RegistryMpackVersionResponse> getRegistryMpackVersions(Set<RegistryMpackVersionRequest> requests)
+ throws AmbariException {
+ Set<RegistryMpackVersionResponse> responses = new HashSet<>();
+ for (RegistryMpackVersionRequest request : requests) {
+ try {
+ responses.addAll(getRegistryMpackVersions(request));
+ } catch (RegistryMpackNotFoundException e) {
+ if (requests.size() == 1) {
+ // only throw exception if 1 request.
+ // there will be > 1 request in case of OR predicate
+ throw e;
+ }
+ }
+ }
+ return responses;
+ }
+
+ private Set<RegistryMpackVersionResponse> getRegistryMpackVersions(RegistryMpackVersionRequest request)
+ throws AmbariException {
+ if (request.getRegistryId() == null || request.getMpackName() == null) {
+ throw new AmbariException("Invalid arguments, registry id and mpack name cannot be null");
+ }
+ AmbariManagementController amc = getManagementController();
+ final Registry registry;
+ try {
+ registry = amc.getRegistry(request.getRegistryId());
+ } catch (ObjectNotFoundException e) {
+ throw new ParentObjectNotFoundException("Parent registry resource doesn't exist", e);
+ }
+
+ final RegistryMpack registryMpack;
+ try {
+ registryMpack = registry.getRegistryMpack(request.getMpackName());
+ } catch (ObjectNotFoundException e) {
+ throw new ParentObjectNotFoundException("Parent registry mpack resource doesn't exist", e);
+ }
+
+ Set<RegistryMpackVersionResponse> responses = new HashSet<>();
+
+ if(request.getMpackVersion() == null) {
+ for (RegistryMpackVersion registryMpackVersion : registryMpack.getMpackVersions()) {
+ RegistryMpackVersionResponse response = new RegistryMpackVersionResponse(
+ registry.getRegistryId(),
+ registryMpack.getMpackName(),
+ registryMpackVersion.getMpackVersion(),
+ registryMpackVersion.getMpackBuildNumber(),
+ registryMpackVersion.getMpackUrl(),
+ registryMpackVersion.getMpackDocUrl(),
+ registryMpackVersion.getMpackServices(),
+ registryMpackVersion.getCompatibleMpacks());
+ responses.add(response);
+ }
+ } else {
+ RegistryMpackVersion registryMpackVersion = registryMpack.getMpackVersion(request.getMpackVersion());
+ if(registryMpackVersion != null) {
+ RegistryMpackVersionResponse response = new RegistryMpackVersionResponse(
+ registry.getRegistryId(),
+ registryMpack.getMpackName(),
+ registryMpackVersion.getMpackVersion(),
+ registryMpackVersion.getMpackBuildNumber(),
+ registryMpackVersion.getMpackUrl(),
+ registryMpackVersion.getMpackDocUrl(),
+ registryMpackVersion.getMpackServices(),
+ registryMpackVersion.getCompatibleMpacks());
+ responses.add(response);
+ }
+ }
+ return responses;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/4450fd7e/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RegistryResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RegistryResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RegistryResourceProvider.java
index 715cd96..7722168 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RegistryResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RegistryResourceProvider.java
@@ -55,7 +55,7 @@ public class RegistryResourceProvider extends AbstractControllerResourceProvider
public static final String REGISTRY_URI = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "registry_uri";
private static Set<String> pkPropertyIds = new HashSet<>(
- Arrays.asList(REGISTRY_ID, REGISTRY_NAME));
+ Arrays.asList(REGISTRY_ID));
/**
* The property ids for a software registry resource.
@@ -188,7 +188,7 @@ public class RegistryResourceProvider extends AbstractControllerResourceProvider
*
* @param requests software registry requests
*/
- private Set<RegistryResponse> addRegistries(Set<RegistryRequest> requests) {
+ private Set<RegistryResponse> addRegistries(Set<RegistryRequest> requests) throws AmbariException {
Set<RegistryResponse> responses = new HashSet<>();
if (requests.isEmpty()) {
LOG.warn("Received an empty requests set");
http://git-wip-us.apache.org/repos/asf/ambari/blob/4450fd7e/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RegistryScenarioResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RegistryScenarioResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RegistryScenarioResourceProvider.java
new file mode 100644
index 0000000..4edff07
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RegistryScenarioResourceProvider.java
@@ -0,0 +1,200 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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 org.apache.ambari.server.controller.internal;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.ObjectNotFoundException;
+import org.apache.ambari.server.ParentObjectNotFoundException;
+import org.apache.ambari.server.controller.AmbariManagementController;
+import org.apache.ambari.server.controller.RegistryScenarioRequest;
+import org.apache.ambari.server.controller.RegistryScenarioResponse;
+import org.apache.ambari.server.controller.spi.NoSuchParentResourceException;
+import org.apache.ambari.server.controller.spi.NoSuchResourceException;
+import org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.spi.Request;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.spi.SystemException;
+import org.apache.ambari.server.controller.spi.UnsupportedPropertyException;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.apache.ambari.server.exceptions.RegistryScenarioNotFoundException;
+import org.apache.ambari.server.registry.Registry;
+import org.apache.ambari.server.registry.RegistryScenario;
+
+/**
+ * ResourceProvider for scenarios in software registry
+ */
+public class RegistryScenarioResourceProvider extends AbstractControllerResourceProvider {
+ public static final String RESPONSE_KEY = "RegistryScenarioInfo";
+ public static final String ALL_PROPERTIES = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "*";
+ public static final String REGISTRY_ID = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "registry_id";
+ public static final String REGISTRY_SCENARIO_NAME = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "scenario_name";
+ public static final String REGISTRY_SCENARIO_DESC = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "scenario_description";
+ public static final String REGISTRY_SCENARIO_MPACKS = RESPONSE_KEY + PropertyHelper.EXTERNAL_PATH_SEP + "scenario_mpacks";
+
+ private static Set<String> pkPropertyIds = new HashSet<>(
+ Arrays.asList(REGISTRY_ID, REGISTRY_SCENARIO_NAME));
+
+ /**
+ * The property ids for a software registry resource.
+ */
+ private static final Set<String> PROPERTY_IDS = new HashSet<>();
+
+ /**
+ * The key property ids for a software registry resource.
+ */
+ private static final Map<Resource.Type, String> KEY_PROPERTY_IDS = new HashMap<>();
+
+ static {
+ // properties
+ PROPERTY_IDS.add(REGISTRY_ID);
+ PROPERTY_IDS.add(REGISTRY_SCENARIO_NAME);
+ PROPERTY_IDS.add(REGISTRY_SCENARIO_DESC);
+ PROPERTY_IDS.add(REGISTRY_SCENARIO_MPACKS);
+
+ // keys
+ KEY_PROPERTY_IDS.put(Resource.Type.Registry, REGISTRY_ID);
+ KEY_PROPERTY_IDS.put(Resource.Type.RegistryScenario, REGISTRY_SCENARIO_NAME);
+ }
+
+ /**
+ * Create a new resource provider for the given management controller.
+ *
+ * @param managementController the management controller
+ */
+ protected RegistryScenarioResourceProvider(final AmbariManagementController managementController) {
+ super(PROPERTY_IDS, KEY_PROPERTY_IDS, managementController);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected Set<String> getPKPropertyIds() {
+ return pkPropertyIds;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<Resource> getResourcesAuthorized(Request request, Predicate predicate)
+ throws SystemException, UnsupportedPropertyException,
+ NoSuchResourceException, NoSuchParentResourceException {
+
+ final Set<RegistryScenarioRequest> requests = new HashSet<>();
+
+ if (predicate == null) {
+ requests.add(getRequest(Collections.<String, Object>emptyMap()));
+ } else {
+ for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) {
+ requests.add(getRequest(propertyMap));
+ }
+ }
+
+ Set<String> requestedIds = getRequestPropertyIds(request, predicate);
+
+ Set<RegistryScenarioResponse> responses = getResources(new Command<Set<RegistryScenarioResponse>>() {
+ @Override
+ public Set<RegistryScenarioResponse> invoke() throws AmbariException {
+ return getRegistryScenarios(requests);
+ }
+ });
+
+ Set<Resource> resources = new HashSet<>();
+ for (RegistryScenarioResponse response : responses) {
+ Resource resource = new ResourceImpl(Resource.Type.RegistryScenario);
+ setResourceProperty(resource, REGISTRY_ID, response.getRegistryId(), requestedIds);
+ setResourceProperty(resource, REGISTRY_SCENARIO_NAME, response.getScenarioName(), requestedIds);
+ setResourceProperty(resource, REGISTRY_SCENARIO_DESC, response.getScenarioDescription(), requestedIds);
+ setResourceProperty(resource, REGISTRY_SCENARIO_MPACKS, response.getScenarioMpacks(), requestedIds);
+ resources.add(resource);
+ }
+ return resources;
+ }
+
+ private RegistryScenarioRequest getRequest(Map<String, Object> properties) {
+
+ Long registryId = properties.containsKey(REGISTRY_ID) && properties.get(REGISTRY_ID) != null?
+ Long.valueOf((String) properties.get(REGISTRY_ID)) : null;
+ String scenarioName = properties.containsKey(REGISTRY_SCENARIO_NAME)?
+ (String) properties.get(REGISTRY_SCENARIO_NAME) : null;
+ RegistryScenarioRequest registryScenarioRequest = new RegistryScenarioRequest(registryId, scenarioName);
+ return registryScenarioRequest;
+ }
+
+ private Set<RegistryScenarioResponse> getRegistryScenarios(Set<RegistryScenarioRequest> requests)
+ throws AmbariException {
+ Set<RegistryScenarioResponse> responses = new HashSet<>();
+ for (RegistryScenarioRequest request : requests) {
+ try {
+ responses.addAll(getRegistryScenarios(request));
+ } catch (RegistryScenarioNotFoundException e) {
+ if (requests.size() == 1) {
+ // only throw exception if 1 request.
+ // there will be > 1 request in case of OR predicate
+ throw e;
+ }
+ }
+ }
+ return responses;
+ }
+
+ private Set<RegistryScenarioResponse> getRegistryScenarios(RegistryScenarioRequest request)
+ throws AmbariException {
+ if (request.getRegistryId() == null) {
+ throw new AmbariException("Invalid arguments, registry id cannot be null");
+ }
+ AmbariManagementController amc = getManagementController();
+ final Registry registry;
+ try {
+ registry = amc.getRegistry(request.getRegistryId());
+ } catch (ObjectNotFoundException e) {
+ throw new ParentObjectNotFoundException("Parent registry resource doesn't exist", e);
+ }
+ Set<RegistryScenarioResponse> responses = new HashSet<>();
+
+ if(request.getScenarioName() == null) {
+ for (RegistryScenario registryScenario : registry.getRegistryScenarios()) {
+ RegistryScenarioResponse response = new RegistryScenarioResponse(
+ registry.getRegistryId(),
+ registryScenario.getScenarioName(),
+ registryScenario.getScenarioDescription(),
+ registryScenario.getScenarioMpacks());
+ responses.add(response);
+ }
+ } else {
+ RegistryScenario registryScenario = registry.getRegistryScenario(request.getScenarioName());
+ if(registryScenario != null) {
+ RegistryScenarioResponse response = new RegistryScenarioResponse(
+ registry.getRegistryId(),
+ registryScenario.getScenarioName(),
+ registryScenario.getScenarioDescription(),
+ registryScenario.getScenarioMpacks());
+ responses.add(response);
+ }
+ }
+ return responses;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/4450fd7e/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/Resource.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/Resource.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/Resource.java
index 3d8af3c..f07ca79 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/Resource.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/spi/Resource.java
@@ -91,6 +91,9 @@ public interface Resource {
Group,
Member,
Registry,
+ RegistryScenario,
+ RegistryMpack,
+ RegistryMpackVersion,
Mpack,
Stack,
StackVersion,
@@ -214,6 +217,9 @@ public interface Resource {
public static final Type Group = InternalType.Group.getType();
public static final Type Member = InternalType.Member.getType();
public static final Type Registry = InternalType.Registry.getType();
+ public static final Type RegistryScenario = InternalType.RegistryScenario.getType();
+ public static final Type RegistryMpack = InternalType.RegistryMpack.getType();
+ public static final Type RegistryMpackVersion = InternalType.RegistryMpackVersion.getType();
public static final Type Mpack = InternalType.Mpack.getType();
public static final Type Stack = InternalType.Stack.getType();
public static final Type StackVersion = InternalType.StackVersion.getType();
http://git-wip-us.apache.org/repos/asf/ambari/blob/4450fd7e/ambari-server/src/main/java/org/apache/ambari/server/exceptions/RegistryMpackNotFoundException.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/exceptions/RegistryMpackNotFoundException.java b/ambari-server/src/main/java/org/apache/ambari/server/exceptions/RegistryMpackNotFoundException.java
new file mode 100644
index 0000000..df4cc40
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/exceptions/RegistryMpackNotFoundException.java
@@ -0,0 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.ambari.server.exceptions;
+
+import org.apache.ambari.server.ObjectNotFoundException;
+
+@SuppressWarnings("serial")
+public class RegistryMpackNotFoundException extends ObjectNotFoundException {
+
+ public RegistryMpackNotFoundException(String registryName, String mpackName) {
+ super("Registry mpack not found, registryName=" + registryName + " mpackName=" + mpackName);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/4450fd7e/ambari-server/src/main/java/org/apache/ambari/server/exceptions/RegistryMpackVersionNotFoundException.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/exceptions/RegistryMpackVersionNotFoundException.java b/ambari-server/src/main/java/org/apache/ambari/server/exceptions/RegistryMpackVersionNotFoundException.java
new file mode 100644
index 0000000..1b8020b
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/exceptions/RegistryMpackVersionNotFoundException.java
@@ -0,0 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.ambari.server.exceptions;
+
+import org.apache.ambari.server.ObjectNotFoundException;
+
+@SuppressWarnings("serial")
+public class RegistryMpackVersionNotFoundException extends ObjectNotFoundException {
+
+ public RegistryMpackVersionNotFoundException(String mpackName, String mpackVersion) {
+ super("Registry mpack version not found, mpackName=" + mpackName + " mpackVersion=" + mpackVersion);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/4450fd7e/ambari-server/src/main/java/org/apache/ambari/server/exceptions/RegistryScenarioNotFoundException.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/exceptions/RegistryScenarioNotFoundException.java b/ambari-server/src/main/java/org/apache/ambari/server/exceptions/RegistryScenarioNotFoundException.java
new file mode 100644
index 0000000..b3b4c99
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/exceptions/RegistryScenarioNotFoundException.java
@@ -0,0 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.ambari.server.exceptions;
+
+import org.apache.ambari.server.ObjectNotFoundException;
+
+@SuppressWarnings("serial")
+public class RegistryScenarioNotFoundException extends ObjectNotFoundException {
+
+ public RegistryScenarioNotFoundException(String registryName, String scenarioName) {
+ super("Registry scenario not found, registryName=" + registryName + " scenarioName=" + scenarioName);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/4450fd7e/ambari-server/src/main/java/org/apache/ambari/server/registry/Registry.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/registry/Registry.java b/ambari-server/src/main/java/org/apache/ambari/server/registry/Registry.java
index bbdc0e2..16061bd 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/registry/Registry.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/registry/Registry.java
@@ -17,8 +17,12 @@
*/
package org.apache.ambari.server.registry;
+import java.util.List;
+
+import org.apache.ambari.server.AmbariException;
+
/**
- *
+ * Represents a single instance of a software registry
*/
public interface Registry {
/**
@@ -44,4 +48,28 @@ public interface Registry {
* @return registry uri
*/
public String getRegistryUri();
+
+ /**
+ * Get list of scenarios defined in the software registry
+ * @return list of {@link RegistryScenario}'s
+ */
+ public List<? extends RegistryScenario> getRegistryScenarios();
+
+ /**
+ *
+ * @return
+ */
+ public RegistryScenario getRegistryScenario(String scenarioName) throws AmbariException;
+
+ /**
+ * Get list of mpacks defined in the software registry
+ * @return list of {@link RegistryMpack}'s
+ */
+ public List<? extends RegistryMpack> getRegistryMpacks();
+
+ /**
+ * Get specific mpack from the software registry
+ * @return {@link RegistryMpack}
+ */
+ public RegistryMpack getRegistryMpack(String mpackName) throws AmbariException;
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/4450fd7e/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryFactory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryFactory.java b/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryFactory.java
index 75a2b2c..16b1704 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryFactory.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryFactory.java
@@ -18,6 +18,7 @@
package org.apache.ambari.server.registry;
+import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.orm.entities.RegistryEntity;
/**
@@ -25,5 +26,11 @@ import org.apache.ambari.server.orm.entities.RegistryEntity;
*/
public interface RegistryFactory {
- Registry create(RegistryEntity registryEntity);
+ /**
+ * Create a new {@link Registry}
+ * @param registryEntity registry entity
+ * @return new {@link Registry}
+ * @throws AmbariException
+ */
+ Registry create(RegistryEntity registryEntity) throws AmbariException;
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/4450fd7e/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryFactoryImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryFactoryImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryFactoryImpl.java
new file mode 100644
index 0000000..fb844f4
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryFactoryImpl.java
@@ -0,0 +1,62 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.ambari.server.registry;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
+import org.apache.ambari.server.orm.entities.RegistryEntity;
+import org.apache.ambari.server.registry.json.JsonRegistry;
+
+import com.google.gson.Gson;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import com.google.inject.Singleton;
+
+/**
+ * Registry Factory implementation
+ */
+@Singleton
+public class RegistryFactoryImpl implements RegistryFactory {
+
+ private Injector injector;
+
+ /**
+ * Constructor
+ * @param injector
+ */
+ @Inject
+ public RegistryFactoryImpl(Injector injector) {
+ this.injector = injector;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Registry create(final RegistryEntity registryEntity) throws AmbariException {
+ RegistryType type = registryEntity.getRegistryType();
+ switch (type) {
+ case JSON:
+ return new JsonRegistry(
+ registryEntity, injector.getInstance(AmbariEventPublisher.class), injector.getInstance(Gson.class));
+ default:
+ throw new AmbariException("Unknown registry type");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/4450fd7e/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryImpl.java
deleted file mode 100644
index 73a3719..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryImpl.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.ambari.server.registry;
-
-import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
-import org.apache.ambari.server.orm.entities.RegistryEntity;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.inject.Inject;
-import com.google.inject.Injector;
-import com.google.inject.assistedinject.Assisted;
-
-/**
- *
- */
-public class RegistryImpl implements Registry {
- private static final Logger LOG = LoggerFactory.getLogger(RegistryImpl.class);
-
- /**
- * The software registry id
- */
- private final Long registryId;
-
- /**
- * The software registry name
- */
- private final String registryName;
-
- /**
- * The software registry type (See {@link RegistryType}
- */
- private final RegistryType registryType;
-
- /**
- * The software registry Uri
- */
- private final String registryUri;
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Long getRegistryId() {
- return registryId;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String getRegistryName() {
- return registryName;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public RegistryType getRegistryType() {
- return registryType;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String getRegistryUri() {
- return registryUri;
- }
-
- @Inject
- public RegistryImpl(@Assisted RegistryEntity registryEntity, Injector injector, AmbariEventPublisher eventPublisher)
- throws AmbariException {
- this.registryId = registryEntity.getRegistryId();
- this.registryName = registryEntity.getRegistryName();
- this.registryType = registryEntity.getRegistryType();
- this.registryUri = registryEntity.getRegistryUri();
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/4450fd7e/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryManager.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryManager.java b/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryManager.java
index 36f4d56..58c00ed 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryManager.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryManager.java
@@ -33,7 +33,8 @@ public interface RegistryManager {
* @param registryType software registry type
* @param registryUri software registry uri
*/
- public Registry addRegistry(String registryName, RegistryType registryType, String registryUri);
+ public Registry addRegistry(String registryName, RegistryType registryType, String registryUri)
+ throws AmbariException;
/**
* Get a software registry given the registry ID
http://git-wip-us.apache.org/repos/asf/ambari/blob/4450fd7e/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryManagerImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryManagerImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryManagerImpl.java
index 72d61fc..00e06b3 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryManagerImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryManagerImpl.java
@@ -24,7 +24,6 @@ import java.util.concurrent.ConcurrentHashMap;
import javax.persistence.EntityManager;
-
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
import org.apache.ambari.server.exceptions.RegistryNotFoundException;
@@ -36,7 +35,6 @@ import org.slf4j.LoggerFactory;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
-import com.google.inject.persist.Transactional;
/**
* Provides high-level access to software registries
@@ -59,6 +57,7 @@ public class RegistryManagerImpl implements RegistryManager {
@Inject
private AmbariEventPublisher eventPublisher;
+
private Map<Long, Registry> registriesById = new ConcurrentHashMap<>();
private Map<String, Registry> registriesByName = new ConcurrentHashMap<>();
@@ -81,8 +80,7 @@ public class RegistryManagerImpl implements RegistryManager {
* instantiated and injected.
*/
@Inject
- @Transactional
- void loadRegistries() {
+ void loadRegistries() throws AmbariException {
for (RegistryEntity registryEntity : registryDAO.findAll()) {
Registry registry = registryFactory.create(registryEntity);
registriesById.put(registryEntity.getRegistryId(), registry);
@@ -94,7 +92,8 @@ public class RegistryManagerImpl implements RegistryManager {
* {@inheritDoc}
*/
@Override
- public synchronized Registry addRegistry(String registryName, RegistryType registryType, String registryUri) {
+ public synchronized Registry addRegistry(String registryName, RegistryType registryType, String registryUri)
+ throws AmbariException {
RegistryEntity registryEntity = new RegistryEntity();
registryEntity.setRegistryName(registryName);
http://git-wip-us.apache.org/repos/asf/ambari/blob/4450fd7e/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryMpack.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryMpack.java b/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryMpack.java
new file mode 100644
index 0000000..dd8004f
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryMpack.java
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.ambari.server.registry;
+
+import java.util.List;
+
+import org.apache.ambari.server.AmbariException;
+
+/**
+ * Represents a single instance of a software registry
+ */
+public interface RegistryMpack {
+ /**
+ * Get mpack name
+ * @return
+ */
+ public String getMpackName();
+
+ /**
+ * Get mpack description
+ * @return
+ */
+ public String getMpackDescription();
+
+ /**
+ * Get mpack logo url
+ * @return
+ */
+ public String getMpackLogoUrl();
+
+ /**
+ * Get list of mpack versions
+ * @return
+ */
+ public List<? extends RegistryMpackVersion> getMpackVersions();
+
+ /**
+ * Get specific mpack version
+ * @return {@link RegistryMpackVersion}
+ */
+ public RegistryMpackVersion getMpackVersion(String mpackVersion) throws AmbariException;
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/4450fd7e/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryMpackCompatiblity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryMpackCompatiblity.java b/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryMpackCompatiblity.java
new file mode 100644
index 0000000..2774e62
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryMpackCompatiblity.java
@@ -0,0 +1,46 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.ambari.server.registry;
+
+import org.codehaus.jackson.annotate.JsonProperty;
+
+/**
+ * Represents a single instance of a software registry
+ */
+public interface RegistryMpackCompatiblity {
+ /**
+ * Get name
+ * @return
+ */
+ @JsonProperty("name")
+ public String getName();
+
+ /**
+ * Get min version
+ * @return
+ */
+ @JsonProperty("minVersion")
+ public String getMinVersion();
+
+ /**
+ * Get max version
+ * @return
+ */
+ @JsonProperty("maxVersion")
+ public String getMaxVersion();
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/4450fd7e/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryMpackService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryMpackService.java b/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryMpackService.java
new file mode 100644
index 0000000..9c3f244
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryMpackService.java
@@ -0,0 +1,41 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.ambari.server.registry;
+
+import org.codehaus.jackson.annotate.JsonProperty;
+
+/**
+ * Represents a single instance of a service in a registry mpack
+ */
+public interface RegistryMpackService {
+
+ /**
+ * Get name
+ * @return
+ */
+ @JsonProperty("name")
+ public String getName();
+
+ /**
+ * Get version
+ * @return
+ */
+ @JsonProperty("version")
+ public String getVersion();
+
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/4450fd7e/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryMpackVersion.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryMpackVersion.java b/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryMpackVersion.java
new file mode 100644
index 0000000..4a4b780
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryMpackVersion.java
@@ -0,0 +1,61 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.ambari.server.registry;
+
+import java.util.List;
+
+/**
+ * Represents a single instance of a registry mpack version
+ */
+public interface RegistryMpackVersion {
+ /**
+ * Get mpack version
+ * @return
+ */
+ public String getMpackVersion();
+
+ /**
+ * Get mpack build number
+ * @return
+ */
+ public String getMpackBuildNumber();
+
+ /**
+ * Get mpack url
+ * @return
+ */
+ public String getMpackUrl();
+
+ /**
+ * Get mpack doc url
+ * @return
+ */
+ public String getMpackDocUrl();
+
+ /**
+ * Get list of services in the mpack version
+ * @return
+ */
+ public List<? extends RegistryMpackService> getMpackServices();
+
+ /**
+ * Get list of compatible mpacks
+ * @return
+ */
+ public List<? extends RegistryMpackCompatiblity> getCompatibleMpacks();
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/4450fd7e/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryScenario.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryScenario.java b/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryScenario.java
new file mode 100644
index 0000000..6fbc1b3
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryScenario.java
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.ambari.server.registry;
+
+import java.util.List;
+
+/**
+ * Represents a single instance of a registry scenario
+ */
+public interface RegistryScenario {
+ /**
+ * Get scenario nmae
+ * @return
+ */
+ public String getScenarioName();
+
+ /**
+ * Get scenario description
+ * @return
+ */
+ public String getScenarioDescription();
+
+ /**
+ * Get mpacks that define this scenario
+ * @return
+ */
+ public List<? extends RegistryScenarioMpack> getScenarioMpacks();
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/4450fd7e/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryScenarioMpack.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryScenarioMpack.java b/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryScenarioMpack.java
new file mode 100644
index 0000000..804a29b
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/registry/RegistryScenarioMpack.java
@@ -0,0 +1,32 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.ambari.server.registry;
+
+import org.codehaus.jackson.annotate.JsonProperty;
+
+/**
+ * Represents a single instance of a registry scenario mpack
+ */
+public interface RegistryScenarioMpack {
+ /**
+ * Get scenario mpack name
+ * @return
+ */
+ @JsonProperty("name")
+ public String getName();
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/4450fd7e/ambari-server/src/main/java/org/apache/ambari/server/registry/json/JsonRegistry.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/registry/json/JsonRegistry.java b/ambari-server/src/main/java/org/apache/ambari/server/registry/json/JsonRegistry.java
new file mode 100644
index 0000000..f92f708
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/registry/json/JsonRegistry.java
@@ -0,0 +1,188 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.ambari.server.registry.json;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.List;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
+import org.apache.ambari.server.exceptions.RegistryMpackNotFoundException;
+import org.apache.ambari.server.exceptions.RegistryScenarioNotFoundException;
+import org.apache.ambari.server.orm.entities.RegistryEntity;
+import org.apache.ambari.server.registry.Registry;
+import org.apache.ambari.server.registry.RegistryMpack;
+import org.apache.ambari.server.registry.RegistryScenario;
+import org.apache.ambari.server.registry.RegistryType;
+
+import org.apache.commons.io.IOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.gson.Gson;
+import com.google.inject.Inject;
+import com.google.inject.assistedinject.Assisted;
+import com.google.inject.assistedinject.AssistedInject;
+
+/**
+ * JSON implementation of a software registry
+ */
+public class JsonRegistry implements Registry {
+ private static final Logger LOG = LoggerFactory.getLogger(JsonRegistry.class);
+
+ @Inject
+ private AmbariEventPublisher eventPublisher;
+
+ @Inject
+ private Gson gson;
+
+ /**
+ * The software registry id
+ */
+ private final Long registryId;
+
+ /**
+ * The software registry name
+ */
+ private final String registryName;
+
+ /**
+ * The software registry type (See {@link RegistryType}
+ */
+ private final RegistryType registryType;
+
+ /**
+ * The software registry Uri
+ */
+ private final String registryUri;
+
+ private final JsonRegistryDefinition registryDefinition;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Long getRegistryId() {
+ return registryId;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getRegistryName() {
+ return registryName;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public RegistryType getRegistryType() {
+ return registryType;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getRegistryUri() {
+ return registryUri;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List<? extends RegistryScenario> getRegistryScenarios() {
+ return registryDefinition.getScenarios();
+ }
+
+ @AssistedInject
+ public JsonRegistry(@Assisted RegistryEntity registryEntity, AmbariEventPublisher eventPublisher, Gson gson)
+ throws AmbariException {
+ this.eventPublisher = eventPublisher;
+ this.gson = gson;
+ this.registryId = registryEntity.getRegistryId();
+ this.registryName = registryEntity.getRegistryName();
+ this.registryType = registryEntity.getRegistryType();
+ this.registryUri = registryEntity.getRegistryUri();
+ try {
+ URI uri = new URI(registryUri);
+ URL url = uri.toURL();
+ String jsonString = IOUtils.toString(url);
+ this.registryDefinition = gson.fromJson(jsonString, JsonRegistryDefinition.class);
+ } catch (MalformedURLException e) {
+ throw new AmbariException(e.getMessage(), e);
+ } catch (IOException e) {
+ throw new AmbariException(e.getMessage(), e);
+ } catch (URISyntaxException e) {
+ throw new AmbariException(e.getMessage(), e);
+ }
+ }
+
+ @Override
+ public RegistryScenario getRegistryScenario(final String scenarioName)
+ throws AmbariException {
+ RegistryScenario registryScenario = null;
+ for (RegistryScenario scenario : getRegistryScenarios()) {
+ if (scenarioName.equals(scenario.getScenarioName())) {
+ registryScenario = scenario;
+ break;
+ }
+ }
+ if(registryScenario == null) {
+ throw new RegistryScenarioNotFoundException(this.registryName, scenarioName);
+ }
+ return registryScenario;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List<? extends RegistryMpack> getRegistryMpacks() {
+ return registryDefinition.getMpacks();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public RegistryMpack getRegistryMpack(final String mpackName)
+ throws AmbariException {
+ RegistryMpack registryMpack = null;
+ if(mpackName == null || mpackName.isEmpty()) {
+ throw new AmbariException(String.format("Registry mpack name cannot be null"));
+ }
+ for (RegistryMpack mpack : getRegistryMpacks()) {
+ if (mpackName.equals(mpack.getMpackName())) {
+ registryMpack = mpack;
+ break;
+ }
+ }
+ if(registryMpack == null) {
+ throw new RegistryMpackNotFoundException(this.registryName, mpackName);
+ }
+ return registryMpack;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/4450fd7e/ambari-server/src/main/java/org/apache/ambari/server/registry/json/JsonRegistryDefinition.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/registry/json/JsonRegistryDefinition.java b/ambari-server/src/main/java/org/apache/ambari/server/registry/json/JsonRegistryDefinition.java
new file mode 100644
index 0000000..634901c
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/registry/json/JsonRegistryDefinition.java
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.ambari.server.registry.json;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ * Json Registry Definition
+ */
+public class JsonRegistryDefinition {
+
+ /**
+ * List of scenarios defined in the software registry
+ */
+ @SerializedName("scenarios")
+ private ArrayList<JsonRegistryScenario> scenarios;
+
+ /**
+ * List of mpacks defined in the software registry
+ */
+ @SerializedName("mpacks")
+ private ArrayList<JsonRegistryMpack> mpacks;
+
+ /**
+ * Get list of scenarios
+ * @return
+ */
+ public List<JsonRegistryScenario> getScenarios() {
+ return scenarios;
+ }
+
+ /**
+ * Get list of mpacks
+ * @return
+ */
+ public List<JsonRegistryMpack> getMpacks() {
+ return mpacks;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/4450fd7e/ambari-server/src/main/java/org/apache/ambari/server/registry/json/JsonRegistryMpack.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/registry/json/JsonRegistryMpack.java b/ambari-server/src/main/java/org/apache/ambari/server/registry/json/JsonRegistryMpack.java
new file mode 100644
index 0000000..2aac1f0
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/registry/json/JsonRegistryMpack.java
@@ -0,0 +1,84 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.ambari.server.registry.json;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.exceptions.RegistryMpackVersionNotFoundException;
+import org.apache.ambari.server.registry.RegistryMpack;
+import org.apache.ambari.server.registry.RegistryMpackVersion;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ * JSON implementation of {@link RegistryMpack}
+ */
+public class JsonRegistryMpack implements RegistryMpack {
+
+ @SerializedName("name")
+ private String name;
+
+ @SerializedName("description")
+ private String description;
+
+ @SerializedName("logoUrl")
+ private String logoUrl;
+
+ @SerializedName("mpackVersions")
+ private ArrayList<JsonRegistryMpackVersion> mpackVersions;
+
+ @Override
+ public String getMpackName() {
+ return name;
+ }
+
+ @Override
+ public String getMpackDescription() {
+ return description;
+ }
+
+ @Override
+ public String getMpackLogoUrl() {
+ return logoUrl;
+ }
+
+ @Override
+ public List<? extends RegistryMpackVersion> getMpackVersions() {
+ return mpackVersions;
+ }
+
+ @Override
+ public RegistryMpackVersion getMpackVersion(String mpackVersion)
+ throws AmbariException {
+ RegistryMpackVersion registryMpackVersion = null;
+ if(mpackVersion == null || mpackVersion.isEmpty()) {
+ throw new AmbariException(String.format("Registry mpack version cannot be null"));
+ }
+ for(RegistryMpackVersion rmv : getMpackVersions()) {
+ if(rmv.getMpackVersion().equals(mpackVersion)) {
+ registryMpackVersion = rmv;
+ }
+ }
+ if(registryMpackVersion == null) {
+ throw new RegistryMpackVersionNotFoundException(getMpackName(), mpackVersion);
+ }
+ return registryMpackVersion;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/4450fd7e/ambari-server/src/main/java/org/apache/ambari/server/registry/json/JsonRegistryMpackCompatibility.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/registry/json/JsonRegistryMpackCompatibility.java b/ambari-server/src/main/java/org/apache/ambari/server/registry/json/JsonRegistryMpackCompatibility.java
new file mode 100644
index 0000000..1934b8a
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/registry/json/JsonRegistryMpackCompatibility.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.ambari.server.registry.json;
+
+import org.apache.ambari.server.registry.RegistryMpackCompatiblity;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ * JSON implementation of {@link RegistryMpackCompatiblity}
+ */
+public class JsonRegistryMpackCompatibility implements RegistryMpackCompatiblity {
+
+ @SerializedName("name")
+ private String name;
+
+ @SerializedName("minVersion")
+ private String minVersion;
+
+ @SerializedName("maxVersion")
+ private String maxVersion;
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String getMinVersion() {
+ return minVersion;
+ }
+
+ @Override
+ public String getMaxVersion() {
+ return maxVersion;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/4450fd7e/ambari-server/src/main/java/org/apache/ambari/server/registry/json/JsonRegistryMpackService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/registry/json/JsonRegistryMpackService.java b/ambari-server/src/main/java/org/apache/ambari/server/registry/json/JsonRegistryMpackService.java
new file mode 100644
index 0000000..9ae45d5
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/registry/json/JsonRegistryMpackService.java
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.ambari.server.registry.json;
+
+import org.apache.ambari.server.registry.RegistryMpackService;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ * JSON implementation of {@link RegistryMpackService}
+ */
+public class JsonRegistryMpackService implements RegistryMpackService {
+
+ @SerializedName("name")
+ private String name;
+
+ @SerializedName("version")
+ private String version;
+
+ @Override public String getName() {
+ return name;
+ }
+
+ @Override public String getVersion() {
+ return version;
+ }
+}