http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/ganglia/GangliaReportPropertyProvider.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/ganglia/GangliaReportPropertyProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/ganglia/GangliaReportPropertyProvider.java index f15615b..02ea9f3 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/ganglia/GangliaReportPropertyProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/ganglia/GangliaReportPropertyProvider.java @@ -49,7 +49,7 @@ import org.slf4j.LoggerFactory; public class GangliaReportPropertyProvider extends MetricsReportPropertyProvider { // ----- Constants -------------------------------------------------------- - protected final static Logger LOG = + private static final Logger LOG = LoggerFactory.getLogger(GangliaReportPropertyProvider.class);
http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProvider.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProvider.java index f6e50c9..e137477 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProvider.java @@ -66,10 +66,13 @@ import org.apache.commons.lang.StringUtils; import org.apache.hadoop.metrics2.sink.timeline.TimelineMetric; import org.apache.hadoop.metrics2.sink.timeline.TimelineMetrics; import org.apache.http.client.utils.URIBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.google.common.collect.Sets; public abstract class AMSPropertyProvider extends MetricsPropertyProvider { + private static final Logger LOG = LoggerFactory.getLogger(AMSPropertyProvider.class); private static final String METRIC_REGEXP_PATTERN = "\\([^)]*\\)"; private static final int COLLECTOR_DEFAULT_PORT = 6188; private final TimelineMetricCache metricCache; http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/AMSReportPropertyProvider.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/AMSReportPropertyProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/AMSReportPropertyProvider.java index 74df3a7..d86a671 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/AMSReportPropertyProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/AMSReportPropertyProvider.java @@ -51,8 +51,11 @@ import org.apache.ambari.server.events.publishers.AmbariEventPublisher; import org.apache.hadoop.metrics2.sink.timeline.TimelineMetric; import org.apache.hadoop.metrics2.sink.timeline.TimelineMetrics; import org.apache.http.client.utils.URIBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class AMSReportPropertyProvider extends MetricsReportPropertyProvider { + private static final Logger LOG = LoggerFactory.getLogger(AMSReportPropertyProvider.class); private MetricsPaddingMethod metricsPaddingMethod; private final TimelineMetricCache metricCache; MetricsRequestHelper requestHelper; http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/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 64ea97b..b713a6e 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 @@ -123,6 +123,7 @@ public interface Resource { TaskAttempt, RootService, RootServiceComponent, + RootServiceComponentConfiguration, RootServiceHostComponent, View, ViewURL, @@ -173,8 +174,7 @@ public interface Resource { VersionDefinition, ClusterKerberosDescriptor, LoggingQuery, - RemoteCluster, - AmbariConfiguration; + RemoteCluster; /** * Get the {@link Type} that corresponds to this InternalType. @@ -258,6 +258,7 @@ public interface Resource { public static final Type TaskAttempt = InternalType.TaskAttempt.getType(); public static final Type RootService = InternalType.RootService.getType(); public static final Type RootServiceComponent = InternalType.RootServiceComponent.getType(); + public static final Type RootServiceComponentConfiguration = InternalType.RootServiceComponentConfiguration.getType(); public static final Type RootServiceHostComponent = InternalType.RootServiceHostComponent.getType(); public static final Type View = InternalType.View.getType(); public static final Type ViewURL = InternalType.ViewURL.getType(); @@ -309,7 +310,6 @@ public interface Resource { public static final Type ClusterKerberosDescriptor = InternalType.ClusterKerberosDescriptor.getType(); public static final Type LoggingQuery = InternalType.LoggingQuery.getType(); public static final Type RemoteCluster = InternalType.RemoteCluster.getType(); - public static final Type AmbariConfiguration = InternalType.AmbariConfiguration.getType(); /** http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/DatabaseChecker.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/DatabaseChecker.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/DatabaseChecker.java index 2620f38..c49b2c6 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/DatabaseChecker.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/DatabaseChecker.java @@ -58,7 +58,7 @@ import com.google.inject.Injector; * now we will use DatabaseConsistencyChecker*/ public class DatabaseChecker { - static Logger LOG = LoggerFactory.getLogger(DatabaseChecker.class); + private static final Logger LOG = LoggerFactory.getLogger(DatabaseChecker.class); @Inject static Injector injector; http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/DefaultServiceCalculatedState.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/DefaultServiceCalculatedState.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/DefaultServiceCalculatedState.java index 70871d0..9045230 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/DefaultServiceCalculatedState.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/DefaultServiceCalculatedState.java @@ -55,7 +55,7 @@ import com.google.inject.Provider; @StaticallyInject public class DefaultServiceCalculatedState implements ServiceCalculatedState { - protected final static Logger LOG = LoggerFactory.getLogger(DefaultServiceCalculatedState.class); + private static final Logger LOG = LoggerFactory.getLogger(DefaultServiceCalculatedState.class); @Inject protected static Provider<Clusters> clustersProvider = null; http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/FlumeServiceCalculatedState.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/FlumeServiceCalculatedState.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/FlumeServiceCalculatedState.java index 604fa42..b34b926 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/FlumeServiceCalculatedState.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/FlumeServiceCalculatedState.java @@ -28,6 +28,8 @@ import org.apache.ambari.server.controller.ServiceComponentHostResponse; import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.Service; import org.apache.ambari.server.state.State; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Determines the service status for Flume. Generically, this means that @@ -41,6 +43,8 @@ import org.apache.ambari.server.state.State; public final class FlumeServiceCalculatedState extends DefaultServiceCalculatedState implements ServiceCalculatedState { + private static final Logger LOG = LoggerFactory.getLogger(FlumeServiceCalculatedState.class); + @Override public State getState(String clusterName, String serviceName) { try { http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HBaseServiceCalculatedState.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HBaseServiceCalculatedState.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HBaseServiceCalculatedState.java index dd15461..63456e8 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HBaseServiceCalculatedState.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HBaseServiceCalculatedState.java @@ -32,6 +32,8 @@ import org.apache.ambari.server.state.ComponentInfo; import org.apache.ambari.server.state.Service; import org.apache.ambari.server.state.StackId; import org.apache.ambari.server.state.State; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Calculator of HBase service state. @@ -40,6 +42,8 @@ import org.apache.ambari.server.state.State; public final class HBaseServiceCalculatedState extends DefaultServiceCalculatedState implements ServiceCalculatedState { + private static final Logger LOG = LoggerFactory.getLogger(HBaseServiceCalculatedState.class); + @Override public State getState(String clusterName, String serviceName) { try { http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HDFSServiceCalculatedState.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HDFSServiceCalculatedState.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HDFSServiceCalculatedState.java index ce8b98c..05e8904 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HDFSServiceCalculatedState.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HDFSServiceCalculatedState.java @@ -32,6 +32,8 @@ import org.apache.ambari.server.state.ComponentInfo; import org.apache.ambari.server.state.Service; import org.apache.ambari.server.state.StackId; import org.apache.ambari.server.state.State; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Calculator of HDFS service state. @@ -40,6 +42,8 @@ import org.apache.ambari.server.state.State; public final class HDFSServiceCalculatedState extends DefaultServiceCalculatedState implements ServiceCalculatedState { + private static final Logger LOG = LoggerFactory.getLogger(HDFSServiceCalculatedState.class); + @Override public State getState(String clusterName, String serviceName) { try { http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HiveServiceCalculatedState.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HiveServiceCalculatedState.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HiveServiceCalculatedState.java index 440dd53..83d26f0 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HiveServiceCalculatedState.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/HiveServiceCalculatedState.java @@ -32,6 +32,8 @@ import org.apache.ambari.server.state.ComponentInfo; import org.apache.ambari.server.state.Service; import org.apache.ambari.server.state.StackId; import org.apache.ambari.server.state.State; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Calculator of HIVE service state. @@ -40,6 +42,8 @@ import org.apache.ambari.server.state.State; public final class HiveServiceCalculatedState extends DefaultServiceCalculatedState implements ServiceCalculatedState { + private static final Logger LOG = LoggerFactory.getLogger(HiveServiceCalculatedState.class); + @Override public State getState(String clusterName, String serviceName) { try { http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/OozieServiceCalculatedState.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/OozieServiceCalculatedState.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/OozieServiceCalculatedState.java index 2d9356c..5cd0319 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/OozieServiceCalculatedState.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/OozieServiceCalculatedState.java @@ -32,6 +32,8 @@ import org.apache.ambari.server.state.ComponentInfo; import org.apache.ambari.server.state.Service; import org.apache.ambari.server.state.StackId; import org.apache.ambari.server.state.State; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Calculator of Oozie service state. @@ -40,6 +42,8 @@ import org.apache.ambari.server.state.State; public final class OozieServiceCalculatedState extends DefaultServiceCalculatedState implements ServiceCalculatedState { + private static final Logger LOG = LoggerFactory.getLogger(DefaultServiceCalculatedState.class); + @Override public State getState(String clusterName, String serviceName) { try { http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/YARNServiceCalculatedState.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/YARNServiceCalculatedState.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/YARNServiceCalculatedState.java index b7a14b5..2530068 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/YARNServiceCalculatedState.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/utilities/state/YARNServiceCalculatedState.java @@ -32,6 +32,8 @@ import org.apache.ambari.server.state.ComponentInfo; import org.apache.ambari.server.state.Service; import org.apache.ambari.server.state.StackId; import org.apache.ambari.server.state.State; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Calculator of YARN service state. @@ -40,6 +42,8 @@ import org.apache.ambari.server.state.State; public final class YARNServiceCalculatedState extends DefaultServiceCalculatedState implements ServiceCalculatedState { + private static final Logger LOG = LoggerFactory.getLogger(YARNServiceCalculatedState.class); + @Override public State getState(String clusterName, String serviceName) { try { http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariConfigurationChangedEvent.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariConfigurationChangedEvent.java b/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariConfigurationChangedEvent.java new file mode 100644 index 0000000..69a15b4 --- /dev/null +++ b/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariConfigurationChangedEvent.java @@ -0,0 +1,36 @@ +/* + * 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 org.apache.ambari.server.events; + +/** + * Event signaling the creation or changing of an Ambari configuration entry. + */ +public class AmbariConfigurationChangedEvent extends AmbariEvent { + + private final String categoryName; + + /** + * Constructor. + * + */ + public AmbariConfigurationChangedEvent(String categoryName) { + super(AmbariEventType.AMBARI_CONFIGURATION_CHANGED); + this.categoryName = categoryName; + } + + public String getCategoryName() { + return categoryName; + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariEvent.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariEvent.java b/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariEvent.java index c88c514..5936edd 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariEvent.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariEvent.java @@ -153,9 +153,9 @@ public abstract class AmbariEvent { USER_CREATED, /** - * LDAP config changed event; + * Ambari configuration changed event; */ - LDAP_CONFIG_CHANGED; + AMBARI_CONFIGURATION_CHANGED; } http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariLdapConfigChangedEvent.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariLdapConfigChangedEvent.java b/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariLdapConfigChangedEvent.java deleted file mode 100644 index 48799d7..0000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariLdapConfigChangedEvent.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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 org.apache.ambari.server.events; - -/** - * Event signaling the creation or changing of an LDAP configuration entry. - */ -public class AmbariLdapConfigChangedEvent extends AmbariEvent { - - private Long configurationId; - - /** - * Constructor. - * - * @param eventType the type of event (not {@code null}). - */ - public AmbariLdapConfigChangedEvent(AmbariEventType eventType, Long configurationId) { - super(eventType); - this.configurationId = configurationId; - } - - public Long getConfigurationId() { - return configurationId; - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/events/ServiceComponentUninstalledEvent.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/ServiceComponentUninstalledEvent.java b/ambari-server/src/main/java/org/apache/ambari/server/events/ServiceComponentUninstalledEvent.java index 2ad2940..18b1d70 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/events/ServiceComponentUninstalledEvent.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/events/ServiceComponentUninstalledEvent.java @@ -27,6 +27,7 @@ public class ServiceComponentUninstalledEvent extends ServiceEvent { private final String m_componentName; private final String m_hostName; private final boolean m_recoveryEnabled; + private final Long m_hostId; /** * Constructor. @@ -40,13 +41,15 @@ public class ServiceComponentUninstalledEvent extends ServiceEvent { */ public ServiceComponentUninstalledEvent(long clusterId, String stackName, String stackVersion, String serviceName, String serviceType, String serviceGroupName, String componentName, - String hostName, boolean recoveryEnabled) { + String hostName, boolean recoveryEnabled, Long hostId) { + super(AmbariEventType.SERVICE_COMPONENT_UNINSTALLED_SUCCESS, clusterId, stackName, stackVersion, serviceName, serviceType, serviceGroupName); m_componentName = componentName; m_hostName = hostName; m_recoveryEnabled = recoveryEnabled; + m_hostId = hostId; } /** @@ -70,6 +73,10 @@ public class ServiceComponentUninstalledEvent extends ServiceEvent { return m_recoveryEnabled; } + public Long getHostId() { + return m_hostId; + } + /** * {@inheritDoc} */ @@ -85,11 +92,12 @@ public class ServiceComponentUninstalledEvent extends ServiceEvent { buffer.append(", componentName=").append(m_componentName); buffer.append(", hostName=").append(m_hostName); buffer.append(", recoveryEnabled=").append(m_recoveryEnabled); + buffer.append(", hostId=").append(m_hostId); buffer.append("}"); return buffer.toString(); } public Component getComponent() { - return new Component(getHostName(), getServiceName(), getComponentName()); + return new Component(getHostName(), getServiceName(), getComponentName(), getHostId()); } } http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertReceivedListener.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertReceivedListener.java b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertReceivedListener.java index 266c7e8..7198814 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertReceivedListener.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertReceivedListener.java @@ -26,8 +26,8 @@ import org.apache.ambari.server.AmbariException; import org.apache.ambari.server.EagerSingleton; import org.apache.ambari.server.configuration.Configuration; import org.apache.ambari.server.controller.MaintenanceStateHelper; -import org.apache.ambari.server.controller.RootServiceResponseFactory.Components; -import org.apache.ambari.server.controller.RootServiceResponseFactory.Services; +import org.apache.ambari.server.controller.RootComponent; +import org.apache.ambari.server.controller.RootService; import org.apache.ambari.server.events.AlertEvent; import org.apache.ambari.server.events.AlertReceivedEvent; import org.apache.ambari.server.events.AlertStateChangeEvent; @@ -434,9 +434,9 @@ public class AlertReceivedListener { String hostName = alert.getHostName(); // AMBARI/AMBARI_SERVER is always a valid service/component combination - String ambariServiceName = Services.AMBARI.name(); - String ambariServerComponentName = Components.AMBARI_SERVER.name(); - String ambariAgentComponentName = Components.AMBARI_AGENT.name(); + String ambariServiceName = RootService.AMBARI.name(); + String ambariServerComponentName = RootComponent.AMBARI_SERVER.name(); + String ambariAgentComponentName = RootComponent.AMBARI_AGENT.name(); if (ambariServiceName.equals(serviceName) && ambariServerComponentName.equals(componentName)) { return true; } http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertStateChangedListener.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertStateChangedListener.java b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertStateChangedListener.java index d5dc530..8701b6d 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertStateChangedListener.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertStateChangedListener.java @@ -24,7 +24,7 @@ import java.util.UUID; import org.apache.ambari.server.AmbariException; import org.apache.ambari.server.EagerSingleton; -import org.apache.ambari.server.controller.RootServiceResponseFactory.Services; +import org.apache.ambari.server.controller.RootService; import org.apache.ambari.server.events.AlertStateChangeEvent; import org.apache.ambari.server.events.publishers.AlertEventPublisher; import org.apache.ambari.server.orm.dao.AlertDispatchDAO; @@ -67,7 +67,7 @@ import com.google.inject.Singleton; * <ul> * <li>If {@link AlertTargetEntity#isEnabled()} is {@code false} * <li>If the cluster is upgrading or the upgrade is suspended, only - * {@link Services#AMBARI} alerts will be dispatched. + * {@link RootService#AMBARI} alerts will be dispatched. * </ul> */ @Singleton @@ -230,7 +230,7 @@ public class AlertStateChangedListener { if (null != cluster.getUpgradeInProgress()) { // only send AMBARI alerts if in an upgrade String serviceName = definition.getServiceName(); - if (!StringUtils.equals(serviceName, Services.AMBARI.name())) { + if (!StringUtils.equals(serviceName, RootService.AMBARI.name())) { LOG.debug( "Skipping alert notifications for {} because the cluster is upgrading", definition.getDefinitionName(), target); http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfiguration.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfiguration.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfiguration.java index 8b26cd3..6c466ba 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfiguration.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfiguration.java @@ -19,8 +19,8 @@ import java.util.Map; import javax.inject.Inject; -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,7 +33,7 @@ public class AmbariLdapConfiguration { private static final Logger LOGGER = LoggerFactory.getLogger(AmbariLdapConfiguration.class); - private final Map<String, Object> configurationMap; + private final Map<String, String> configurationMap; private Object configValue(AmbariLdapConfigKeys ambariLdapConfigKeys) { Object value = null; @@ -45,13 +45,13 @@ public class AmbariLdapConfiguration { return value; } - public void setValueFor(AmbariLdapConfigKeys ambariLdapConfigKeys, Object value) { + public void setValueFor(AmbariLdapConfigKeys ambariLdapConfigKeys, String value) { configurationMap.put(ambariLdapConfigKeys.key(), value); } // intentionally package private, instances to be created through the factory @Inject - AmbariLdapConfiguration(@Assisted Map<String, Object> configuration) { + AmbariLdapConfiguration(@Assisted Map<String, String> configuration) { this.configurationMap = configuration; } @@ -179,21 +179,25 @@ public class AmbariLdapConfiguration { @Override public boolean equals(Object o) { - if (this == o) return true; + if (this == o) { + return true; + } - if (o == null || getClass() != o.getClass()) return false; + if (o == null || getClass() != o.getClass()) { + return false; + } AmbariLdapConfiguration that = (AmbariLdapConfiguration) o; return new EqualsBuilder() - .append(configurationMap, that.configurationMap) - .isEquals(); + .append(configurationMap, that.configurationMap) + .isEquals(); } @Override public int hashCode() { return new HashCodeBuilder(17, 37) - .append(configurationMap) - .toHashCode(); + .append(configurationMap) + .toHashCode(); } } http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfigurationFactory.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfigurationFactory.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfigurationFactory.java index 2b9f24b..aafd204 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfigurationFactory.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/domain/AmbariLdapConfigurationFactory.java @@ -30,5 +30,5 @@ public interface AmbariLdapConfigurationFactory { * @param configuration a map where keys are the configuration properties and values are the configuration values * @return an AmbariLdapConfiguration instance */ - AmbariLdapConfiguration createLdapConfiguration(Map<String, Object> configuration); + AmbariLdapConfiguration createLdapConfiguration(Map<String, String> configuration); } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigurationProvider.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigurationProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigurationProvider.java index c88d420..ac9c1bc 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigurationProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/AmbariLdapConfigurationProvider.java @@ -14,14 +14,11 @@ package org.apache.ambari.server.ldap.service; +import java.util.HashMap; +import java.util.List; import java.util.Map; -import java.util.Set; -import javax.inject.Inject; -import javax.inject.Provider; -import javax.inject.Singleton; - -import org.apache.ambari.server.events.AmbariLdapConfigChangedEvent; +import org.apache.ambari.server.events.AmbariConfigurationChangedEvent; import org.apache.ambari.server.events.publishers.AmbariEventPublisher; import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration; import org.apache.ambari.server.ldap.domain.AmbariLdapConfigurationFactory; @@ -32,8 +29,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.common.eventbus.Subscribe; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; +import com.google.inject.Inject; +import com.google.inject.Provider; +import com.google.inject.Singleton; /** * Provider implementation for LDAP configurations. @@ -41,7 +39,7 @@ import com.google.gson.GsonBuilder; * It's responsible for managing LDAP configurations in the application. * Whenever requested, this provider returns an AmbariLdapConfiguration which is always in sync with the persisted LDAP * configuration resource. - * + * <p> * The provider receives notifications on CRUD operations related to the persisted resource and reloads the cached * configuration instance accordingly. */ @@ -60,8 +58,6 @@ public class AmbariLdapConfigurationProvider implements Provider<AmbariLdapConfi @Inject private AmbariLdapConfigurationFactory ldapConfigurationFactory; - private Gson gson = new GsonBuilder().create(); - @Inject public AmbariLdapConfigurationProvider() { } @@ -73,48 +69,45 @@ public class AmbariLdapConfigurationProvider implements Provider<AmbariLdapConfi @Override public AmbariLdapConfiguration get() { - return instance != null ? instance : loadInstance(null); + return instance != null ? instance : loadInstance(); } /** * Loads the AmbariLdapConfiguration from the database. * - * @param configurationId the configuration id * @return the AmbariLdapConfiguration instance */ - private AmbariLdapConfiguration loadInstance(Long configurationId) { - AmbariConfigurationEntity configEntity = null; + private AmbariLdapConfiguration loadInstance() { + List<AmbariConfigurationEntity> configEntities; LOGGER.info("Loading LDAP configuration ..."); - if (null == configurationId) { + configEntities = ambariConfigurationDAOProvider.get().findByCategory("ldap-configuration"); - LOGGER.debug("Initial loading of the ldap configuration ..."); - configEntity = ambariConfigurationDAOProvider.get().getLdapConfiguration(); + if (configEntities != null) { + Map<String, String> properties = toProperties(configEntities); + instance = ldapConfigurationFactory.createLdapConfiguration(properties); + } - } else { + LOGGER.info("Loaded LDAP configuration instance: [ {} ]", instance); - LOGGER.debug("Reloading configuration based on the provied id: {}", configurationId); - configEntity = ambariConfigurationDAOProvider.get().findByPK(configurationId); + return instance; + } - } + private Map<String, String> toProperties(List<AmbariConfigurationEntity> configEntities) { + Map<String, String> map = new HashMap<>(); - if (configEntity != null) { - Set propertyMaps = gson.fromJson(configEntity.getConfigurationBaseEntity().getConfigurationData(), Set.class); - instance = ldapConfigurationFactory.createLdapConfiguration((Map<String, Object>) propertyMaps.iterator().next()); + for (AmbariConfigurationEntity entity : configEntities) { + map.put(entity.getPropertyName(), entity.getPropertyValue()); } - LOGGER.info("Loaded LDAP configuration instance: [ {} ]", instance); - - return instance; + return map; } // On changing the configuration, the provider gets updated with the fresh value @Subscribe - public void ambariLdapConfigChanged(AmbariLdapConfigChangedEvent event) { + public void ambariLdapConfigChanged(AmbariConfigurationChangedEvent event) { LOGGER.info("LDAP config changed event received: {}", event); - loadInstance(event.getConfigurationId()); + loadInstance(); LOGGER.info("Refreshed LDAP config instance."); } - - } http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionConfigService.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionConfigService.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionConfigService.java index 9afcf51..82b527f 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionConfigService.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/DefaultLdapConnectionConfigService.java @@ -35,7 +35,7 @@ import org.slf4j.LoggerFactory; @Singleton public class DefaultLdapConnectionConfigService implements LdapConnectionConfigService { - private static Logger LOG = LoggerFactory.getLogger(DefaultLdapConnectionConfigService.class); + private static final Logger LOG = LoggerFactory.getLogger(DefaultLdapConnectionConfigService.class); @Inject public DefaultLdapConnectionConfigService() { http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/LdapConnectionTemplateFactory.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/LdapConnectionTemplateFactory.java b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/LdapConnectionTemplateFactory.java index 8467af0..5e4e0ca 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/LdapConnectionTemplateFactory.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/ldap/service/ads/LdapConnectionTemplateFactory.java @@ -18,7 +18,7 @@ import javax.inject.Inject; import javax.inject.Provider; import javax.inject.Singleton; -import org.apache.ambari.server.events.AmbariLdapConfigChangedEvent; +import org.apache.ambari.server.events.AmbariConfigurationChangedEvent; import org.apache.ambari.server.ldap.domain.AmbariLdapConfiguration; import org.apache.ambari.server.ldap.service.AmbariLdapException; import org.apache.ambari.server.ldap.service.LdapConnectionConfigService; @@ -103,7 +103,7 @@ public class LdapConnectionTemplateFactory { * @throws AmbariLdapException */ @Subscribe - public void onConfigChange(AmbariLdapConfigChangedEvent event) throws AmbariLdapException { + public void onConfigChange(AmbariConfigurationChangedEvent event) throws AmbariLdapException { ldapConnectionTemplateInstance = create(ambariLdapConfigurationProvider.get()); } http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/metadata/AmbariServiceAlertDefinitions.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/metadata/AmbariServiceAlertDefinitions.java b/ambari-server/src/main/java/org/apache/ambari/server/metadata/AmbariServiceAlertDefinitions.java index 1e20571..d6b0c99 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/metadata/AmbariServiceAlertDefinitions.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/metadata/AmbariServiceAlertDefinitions.java @@ -23,8 +23,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Set; -import org.apache.ambari.server.controller.RootServiceResponseFactory.Components; -import org.apache.ambari.server.controller.RootServiceResponseFactory.Services; +import org.apache.ambari.server.controller.RootComponent; +import org.apache.ambari.server.controller.RootService; import org.apache.ambari.server.state.alert.AlertDefinition; import org.apache.ambari.server.state.alert.AlertDefinitionFactory; import org.slf4j.Logger; @@ -36,7 +36,7 @@ import com.google.inject.Singleton; /** * The {@link AmbariServiceAlertDefinitions} class is used to represent the * alerts defined in {@code alerts.json} which are for - * {@link Components#AMBARI_AGENT} and {@link Components#AMBARI_SERVER}. These + * {@link RootComponent#AMBARI_AGENT} and {@link RootComponent#AMBARI_SERVER}. These * alerts are bound to the host and are not part of a cluster or hadoop service. */ @Singleton @@ -67,7 +67,7 @@ public class AmbariServiceAlertDefinitions { * Gets all of the {@link AlertDefinition}s that exist on the path for all * agent hosts. * - * @return the alerts with {@link Components#AMBARI_AGENT} as the component + * @return the alerts with {@link RootComponent#AMBARI_AGENT} as the component * and {@code AMBARI} as the service. */ public List<AlertDefinition> getAgentDefinitions() { @@ -75,15 +75,15 @@ public class AmbariServiceAlertDefinitions { return m_agentDefinitions; } - m_agentDefinitions = getDefinitions(Components.AMBARI_AGENT); + m_agentDefinitions = getDefinitions(RootComponent.AMBARI_AGENT); return m_agentDefinitions; } /** * Gets all of the {@link AlertDefinition}s that exist on the path for - * {@link Components#AMBARI_SERVER}. + * {@link RootComponent#AMBARI_SERVER}. * - * @return the alerts with {@link Components#AMBARI_SERVER} as the component + * @return the alerts with {@link RootComponent#AMBARI_SERVER} as the component * and {@code AMBARI} as the service. */ public List<AlertDefinition> getServerDefinitions() { @@ -91,7 +91,7 @@ public class AmbariServiceAlertDefinitions { return m_serverDefinitions; } - m_serverDefinitions = getDefinitions(Components.AMBARI_SERVER); + m_serverDefinitions = getDefinitions(RootComponent.AMBARI_SERVER); return m_serverDefinitions; } @@ -104,7 +104,7 @@ public class AmbariServiceAlertDefinitions { * @return the alert definitions for {@code AMBARI} service for the given * component. */ - private List<AlertDefinition> getDefinitions(Components component) { + private List<AlertDefinition> getDefinitions(RootComponent component) { List<AlertDefinition> definitions = new ArrayList<>(); InputStream inputStream = ClassLoader.getSystemResourceAsStream("alerts.json"); @@ -112,7 +112,7 @@ public class AmbariServiceAlertDefinitions { try { Set<AlertDefinition> allDefinitions = m_factory.getAlertDefinitions( - reader, Services.AMBARI.name()); + reader, RootService.AMBARI.name()); String componentName = component.name(); http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAO.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAO.java index cda03f3..424910b 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAO.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAO.java @@ -25,7 +25,8 @@ import javax.persistence.EntityManager; import javax.persistence.TypedQuery; import org.apache.ambari.server.AmbariException; -import org.apache.ambari.server.controller.RootServiceResponseFactory; +import org.apache.ambari.server.controller.RootComponent; +import org.apache.ambari.server.controller.RootService; import org.apache.ambari.server.controller.internal.AlertDefinitionResourceProvider; import org.apache.ambari.server.events.AlertDefinitionChangedEvent; import org.apache.ambari.server.events.AlertDefinitionDeleteEvent; @@ -300,10 +301,10 @@ public class AlertDefinitionDAO { query.setParameter("clusterId", clusterId); query.setParameter("serviceName", - RootServiceResponseFactory.Services.AMBARI.name()); + RootService.AMBARI.name()); query.setParameter("componentName", - RootServiceResponseFactory.Components.AMBARI_AGENT.name()); + RootComponent.AMBARI_AGENT.name()); return daoUtils.selectList(query); } http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDispatchDAO.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDispatchDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDispatchDAO.java index 5c6a82f..1746048 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDispatchDAO.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDispatchDAO.java @@ -33,7 +33,7 @@ import org.apache.ambari.server.AmbariException; import org.apache.ambari.server.api.query.JpaPredicateVisitor; import org.apache.ambari.server.api.query.JpaSortBuilder; import org.apache.ambari.server.controller.AlertNoticeRequest; -import org.apache.ambari.server.controller.RootServiceResponseFactory.Services; +import org.apache.ambari.server.controller.RootService; import org.apache.ambari.server.controller.spi.Predicate; import org.apache.ambari.server.controller.utilities.PredicateHelper; import org.apache.ambari.server.orm.RequiresSession; @@ -452,7 +452,7 @@ public class AlertDispatchDAO { // AMBARI is a special service that we let through, otherwise we need to // verify that the service exists before we create the default group - String ambariServiceName = Services.AMBARI.name(); + String ambariServiceName = RootService.AMBARI.name(); if (!ambariServiceName.equals(serviceName)) { Cluster cluster = m_clusters.get().getClusterById(clusterId); Map<String, Service> services = cluster.getServices(); http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AmbariConfigurationDAO.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AmbariConfigurationDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AmbariConfigurationDAO.java index 83293ef..e4446d7 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AmbariConfigurationDAO.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AmbariConfigurationDAO.java @@ -14,13 +14,20 @@ package org.apache.ambari.server.orm.dao; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import javax.inject.Inject; import javax.inject.Singleton; import javax.persistence.EntityExistsException; import javax.persistence.EntityNotFoundException; import javax.persistence.TypedQuery; +import org.apache.ambari.server.orm.RequiresSession; import org.apache.ambari.server.orm.entities.AmbariConfigurationEntity; +import org.apache.ambari.server.orm.entities.AmbariConfigurationEntityPK; +import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -32,7 +39,7 @@ import com.google.inject.persist.Transactional; */ @Singleton -public class AmbariConfigurationDAO extends CrudDAO<AmbariConfigurationEntity, Long> { +public class AmbariConfigurationDAO extends CrudDAO<AmbariConfigurationEntity, AmbariConfigurationEntityPK> { private static final Logger LOGGER = LoggerFactory.getLogger(AmbariConfigurationDAO.class); @@ -41,49 +48,132 @@ public class AmbariConfigurationDAO extends CrudDAO<AmbariConfigurationEntity, L super(AmbariConfigurationEntity.class); } + /** + * Returns the Ambari configuration properties with the requested category name from the database. + * + * @param categoryName the configuration category name + * @return the configuration entity + */ + @RequiresSession + public List<AmbariConfigurationEntity> findByCategory(String categoryName) { + TypedQuery<AmbariConfigurationEntity> query = entityManagerProvider.get().createNamedQuery( + "AmbariConfigurationEntity.findByCategory", AmbariConfigurationEntity.class); + query.setParameter("categoryName", categoryName); + return daoUtils.selectList(query); + } + + /** + * Removes the Ambari configuration properties with the requested category name from the database. + * + * @param categoryName the configuration category name + * @return the number of items removed + */ + @Transactional + public int removeByCategory(String categoryName) { + TypedQuery<AmbariConfigurationEntity> query = entityManagerProvider.get().createNamedQuery( + "AmbariConfigurationEntity.deleteByCategory", AmbariConfigurationEntity.class); + query.setParameter("categoryName", categoryName); + return query.executeUpdate(); + } + @Transactional public void create(AmbariConfigurationEntity entity) { - // make sure only one LDAP config entry exists - if ("ldap-configuration".equals(entity.getConfigurationBaseEntity().getType())) { - AmbariConfigurationEntity ldapConfigEntity = getLdapConfiguration(); - if (ldapConfigEntity != null) { - LOGGER.error("Only one LDAP configuration entry can exist!"); - throw new EntityExistsException("LDAP configuration entity already exists!"); - } + // make sure only one entry exists per configuration type... + AmbariConfigurationEntity foundEntity = findByPK(new AmbariConfigurationEntityPK(entity.getCategoryName(), entity.getPropertyName())); + if (foundEntity != null) { + String message = String.format("Only one configuration entry can exist for the category %s and name %s", entity.getCategoryName(), entity.getPropertyName()); + LOGGER.error(message); + throw new EntityExistsException(message); } + super.create(entity); } + @Override + public AmbariConfigurationEntity merge(AmbariConfigurationEntity entity) { + AmbariConfigurationEntity foundEntity = findByPK(new AmbariConfigurationEntityPK(entity.getCategoryName(), entity.getPropertyName())); + if (foundEntity == null) { + String message = String.format("The configuration entry for the category %s and name %s does not exist", entity.getCategoryName(), entity.getPropertyName()); + LOGGER.debug(message); + throw new EntityNotFoundException(message); + } - @Transactional - public void update(AmbariConfigurationEntity entity) { - if (entity.getId() == null || findByPK(entity.getId()) == null) { - String msg = String.format("The entity with id [ %s ] is not found", entity.getId()); - LOGGER.debug(msg); - throw new EntityNotFoundException(msg); + AmbariConfigurationEntity updatedEntity = entity; + + if (!StringUtils.equals(foundEntity.getPropertyValue(), entity.getPropertyValue())) { + // updating the existing entity + updatedEntity = super.merge(entity); + entityManagerProvider.get().flush(); } - // updating the existing entity - super.merge(entity); - entityManagerProvider.get().flush(); + return updatedEntity; } /** - * Returns the LDAP configuration from the database. + * Reconciles the properties associted with an Ambari confgiration category (for example, ldap-configuration) + * using persisted properties and the supplied properties. + * <p> + * if <code>removeIfNotProvided</code> is <code>true</code>, only properties that exist in the new set of + * properties will be persisted; others will be removed. + * <p> + * If <code>removeIfNotProvided</code> is <code>false</code>, then the new properties will be used + * to update or append to the set of persisted properties. * - * @return the configuration entity + * @param categoryName the category name for the set of properties + * @param properties a map of name to value pairs + * @param removeIfNotProvided <code>true</code> to explicitly set the set of properties for the category; <code>false</code> to upadate the set of properties for the category + * @return <code>true</code> if changes were made; <code>false</code> if not changes were made. */ @Transactional - public AmbariConfigurationEntity getLdapConfiguration() { - LOGGER.info("Looking up the LDAP configuration ...."); - AmbariConfigurationEntity ldapConfigEntity = null; + public boolean reconcileCategory(String categoryName, Map<String, String> properties, boolean removeIfNotProvided) { + boolean changesDetected = false; + List<AmbariConfigurationEntity> existingEntities = findByCategory(categoryName); + Map<String, String> propertiesToProcess = new HashMap<>(); - TypedQuery<AmbariConfigurationEntity> query = entityManagerProvider.get().createNamedQuery( - "AmbariConfigurationEntity.findByType", AmbariConfigurationEntity.class); - query.setParameter("typeName", "ldap-configuration"); + if (properties != null) { + propertiesToProcess.putAll(properties); + } + + if (existingEntities != null) { + for (AmbariConfigurationEntity entity : existingEntities) { + String propertyName = entity.getPropertyName(); + + if (propertiesToProcess.containsKey(propertyName)) { + String newPropertyValue = propertiesToProcess.get(propertyName); + if (!StringUtils.equals(newPropertyValue, entity.getPropertyValue())) { + // Update the entry... + entity.setPropertyValue(newPropertyValue); + merge(entity); + changesDetected = true; + } + } else if (removeIfNotProvided) { + // Remove the entry since it is not in the new set of properties... + remove(entity); + changesDetected = true; + } + + // If already processed, remove it so we know no to add it later... + propertiesToProcess.remove(propertyName); + } + } + + // Add the new entries... + if (!propertiesToProcess.isEmpty()) { + for (Map.Entry<String, String> property : propertiesToProcess.entrySet()) { + AmbariConfigurationEntity entity = new AmbariConfigurationEntity(); + entity.setCategoryName(categoryName); + entity.setPropertyName(property.getKey()); + entity.setPropertyValue(property.getValue()); + create(entity); + } + + changesDetected = true; + } + + if (changesDetected) { + entityManagerProvider.get().flush(); + } - ldapConfigEntity = daoUtils.selectSingle(query); - LOGGER.info("Returned entity: {} ", ldapConfigEntity); - return ldapConfigEntity; + return changesDetected; } } http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/KerberosKeytabDAO.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/KerberosKeytabDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/KerberosKeytabDAO.java new file mode 100644 index 0000000..a8723b7 --- /dev/null +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/KerberosKeytabDAO.java @@ -0,0 +1,110 @@ +/* + * 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.orm.dao; + +import java.util.Collection; +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.TypedQuery; + +import org.apache.ambari.server.orm.RequiresSession; +import org.apache.ambari.server.orm.entities.HostEntity; +import org.apache.ambari.server.orm.entities.KerberosKeytabEntity; + +import com.google.inject.Inject; +import com.google.inject.Provider; +import com.google.inject.Singleton; +import com.google.inject.persist.Transactional; + +@Singleton +public class KerberosKeytabDAO { + @Inject + Provider<EntityManager> entityManagerProvider; + + @Transactional + public void create(KerberosKeytabEntity kerberosKeytabEntity) { + entityManagerProvider.get().persist(kerberosKeytabEntity); + } + + public void create(String keytabPath) { + create(new KerberosKeytabEntity(keytabPath)); + } + + @Transactional + public KerberosKeytabEntity merge(KerberosKeytabEntity kerberosKeytabEntity) { + return entityManagerProvider.get().merge(kerberosKeytabEntity); + } + + @Transactional + public void remove(KerberosKeytabEntity kerberosKeytabEntity) { + entityManagerProvider.get().remove(merge(kerberosKeytabEntity)); + } + + public void remove(String keytabPath) { + KerberosKeytabEntity kke = find(keytabPath); + if (kke != null) { + remove(kke); + } + } + + @Transactional + public void refresh(KerberosKeytabEntity kerberosKeytabEntity) { + entityManagerProvider.get().refresh(kerberosKeytabEntity); + } + + + @RequiresSession + public KerberosKeytabEntity find(String keytabPath) { + return entityManagerProvider.get().find(KerberosKeytabEntity.class, keytabPath); + } + + @RequiresSession + public List<KerberosKeytabEntity> findAll() { + TypedQuery<KerberosKeytabEntity> query = entityManagerProvider.get(). + createNamedQuery("KerberosKeytabEntity.findAll", KerberosKeytabEntity.class); + + return query.getResultList(); + } + + @RequiresSession + public boolean exists(String keytabPath) { + return find(keytabPath) != null; + } + + @RequiresSession + public Collection<KerberosKeytabEntity> findByHost(Long hostId) { + TypedQuery<KerberosKeytabEntity> query = entityManagerProvider.get(). + createNamedQuery("KerberosKeytabEntity.findByHost", KerberosKeytabEntity.class); + query.setParameter("hostId", hostId); + return query.getResultList(); + } + + public Collection<KerberosKeytabEntity> findByHost(HostEntity hostEntity) { + return findByHost(hostEntity.getHostId()); + } + + public void remove(List<KerberosKeytabEntity> entities) { + if (entities != null) { + for (KerberosKeytabEntity entity : entities) { + entityManagerProvider.get().remove(entity); + } + } + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/KerberosPrincipalDAO.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/KerberosPrincipalDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/KerberosPrincipalDAO.java index 93c55c1..81e4b3d 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/KerberosPrincipalDAO.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/KerberosPrincipalDAO.java @@ -161,4 +161,11 @@ public class KerberosPrincipalDAO { return find(principalName) != null; } + public void remove(List<KerberosPrincipalEntity> entities) { + if (entities != null) { + for (KerberosPrincipalEntity entity : entities) { + remove(entity); + } + } + } } http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/KerberosPrincipalHostDAO.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/KerberosPrincipalHostDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/KerberosPrincipalHostDAO.java index 0c17f19..f27dc48 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/KerberosPrincipalHostDAO.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/KerberosPrincipalHostDAO.java @@ -56,8 +56,8 @@ public class KerberosPrincipalHostDAO { entityManagerProvider.get().persist(kerberosPrincipalHostEntity); } - public void create(String principal, Long hostId) { - create(new KerberosPrincipalHostEntity(principal, hostId)); + public void create(String principal, Long hostId, String keytabPath) { + create(new KerberosPrincipalHostEntity(principal, hostId, keytabPath)); } /** @@ -121,6 +121,19 @@ public class KerberosPrincipalHostDAO { } /** + * Find KerberosPrincipalHostEntities for the requested host + * + * @return a List of requested KerberosPrincipalHostEntities or null if none were found + */ + @RequiresSession + public List<KerberosPrincipalHostEntity> findByKeytabPath(String keytabPath) { + final TypedQuery<KerberosPrincipalHostEntity> query = entityManagerProvider.get() + .createNamedQuery("KerberosPrincipalHostEntityFindByKeytabPath", KerberosPrincipalHostEntity.class); + query.setParameter("keytabPath", keytabPath); + return query.getResultList(); + } + + /** * Find the KerberosPrincipalHostEntity for the specified primary key * * @param primaryKey a KerberosPrincipalHostEntityPK containing the requested principal and host names @@ -139,9 +152,9 @@ public class KerberosPrincipalHostDAO { * @return the KerberosPrincipalHostEntity or null if not found */ @RequiresSession - public KerberosPrincipalHostEntity find(String principalName, Long hostId) { + public KerberosPrincipalHostEntity find(String principalName, Long hostId, String keytabPath) { return entityManagerProvider.get().find(KerberosPrincipalHostEntity.class, - new KerberosPrincipalHostEntityPK(principalName, hostId)); + new KerberosPrincipalHostEntityPK(principalName, hostId, keytabPath)); } /** @@ -179,6 +192,15 @@ public class KerberosPrincipalHostDAO { } /** + * Remove KerberosPrincipalHostEntity instances for the specified host + * + * @param keytabPath a String indicating the keytab path of principal + */ + @Transactional + public void removeByKeytabPath(String keytabPath) { + remove(findByKeytabPath(keytabPath)); + } + /** * Remove KerberosPrincipalHostEntity instance for the specified principal and host * * @param principalName a String indicating the name of the principal @@ -186,8 +208,8 @@ public class KerberosPrincipalHostDAO { * @see #remove(org.apache.ambari.server.orm.entities.KerberosPrincipalHostEntity) */ @Transactional - public void remove(String principalName, Long hostId) { - remove(new KerberosPrincipalHostEntity(principalName, hostId)); + public void remove(String principalName, Long hostId, String keytabPath) { + remove(new KerberosPrincipalHostEntity(principalName, hostId, keytabPath)); } /** @@ -210,8 +232,8 @@ public class KerberosPrincipalHostDAO { * @return true if the requested principal exists */ @RequiresSession - public boolean exists(String principalName, Long hostId) { - return find(principalName, hostId) != null; + public boolean exists(String principalName, Long hostId, String keytabPath) { + return find(principalName, hostId, keytabPath) != null; } /** @@ -219,7 +241,7 @@ public class KerberosPrincipalHostDAO { * * @param entities a collection of KerberosPrincipalHostEntity items to remove */ - private void remove(List<KerberosPrincipalHostEntity> entities) { + public void remove(List<KerberosPrincipalHostEntity> entities) { if (entities != null) { for (KerberosPrincipalHostEntity entity : entities) { entityManagerProvider.get().remove(entity); http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AmbariConfigurationEntity.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AmbariConfigurationEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AmbariConfigurationEntity.java index c9f4695..8cd6751 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AmbariConfigurationEntity.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AmbariConfigurationEntity.java @@ -14,57 +14,99 @@ package org.apache.ambari.server.orm.entities; -import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.MapsId; +import javax.persistence.IdClass; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; -import javax.persistence.OneToOne; import javax.persistence.Table; -@Entity +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; + @Table(name = "ambari_configuration") @NamedQueries({ - @NamedQuery( - name = "AmbariConfigurationEntity.findByType", - query = "select ace from AmbariConfigurationEntity ace where ace.configurationBaseEntity.type = :typeName") + @NamedQuery( + name = "AmbariConfigurationEntity.findByCategory", + query = "select ace from AmbariConfigurationEntity ace where ace.categoryName = :categoryName"), + @NamedQuery( + name = "AmbariConfigurationEntity.deleteByCategory", + query = "delete from AmbariConfigurationEntity ace where ace.categoryName = :categoryName") }) - +@IdClass(AmbariConfigurationEntityPK.class) +@Entity public class AmbariConfigurationEntity { @Id - @Column(name = "id") - private Long id; + @Column(name = "category_name") + private String categoryName; + + @Id + @Column(name = "property_name") + private String propertyName; + + @Column(name = "property_value") + private String propertyValue; - @OneToOne(cascade = CascadeType.ALL) - @MapsId - @JoinColumn(name = "id") - private ConfigurationBaseEntity configurationBaseEntity; + public String getCategoryName() { + return categoryName; + } + + public void setCategoryName(String category) { + this.categoryName = category; + } - public Long getId() { - return id; + public String getPropertyName() { + return propertyName; } - public void setId(Long id) { - this.id = id; + public void setPropertyName(String propertyName) { + this.propertyName = propertyName; } - public ConfigurationBaseEntity getConfigurationBaseEntity() { - return configurationBaseEntity; + public String getPropertyValue() { + return propertyValue; } - public void setConfigurationBaseEntity(ConfigurationBaseEntity configurationBaseEntity) { - this.configurationBaseEntity = configurationBaseEntity; + public void setPropertyValue(String propertyValue) { + this.propertyValue = propertyValue; } @Override public String toString() { return "AmbariConfigurationEntity{" + - "id=" + id + - ", configurationBaseEntity=" + configurationBaseEntity + - '}'; + ", category=" + categoryName + + ", name=" + propertyName + + ", value=" + propertyValue + + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + AmbariConfigurationEntity that = (AmbariConfigurationEntity) o; + + return new EqualsBuilder() + .append(categoryName, that.categoryName) + .append(propertyName, that.propertyName) + .append(propertyValue, that.propertyValue) + .isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 37) + .append(categoryName) + .append(propertyName) + .append(propertyValue) + .toHashCode(); } } http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AmbariConfigurationEntityPK.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AmbariConfigurationEntityPK.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AmbariConfigurationEntityPK.java new file mode 100644 index 0000000..3674e12 --- /dev/null +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AmbariConfigurationEntityPK.java @@ -0,0 +1,88 @@ +/* + * 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.orm.entities; + +import java.io.Serializable; + +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; + +/** + * Composite primary key for {@link AmbariConfigurationEntity}. + */ +public class AmbariConfigurationEntityPK implements Serializable { + + private String categoryName; + private String propertyName; + + /** + * Constructor. + * + * @param categoryName configuration category name + * @param propertyName configuration property name + */ + public AmbariConfigurationEntityPK(String categoryName, String propertyName) { + this.categoryName = categoryName; + this.propertyName = propertyName; + } + + /** + * Get the configuration category name. + * + * @return category name + */ + public String getCategoryName() { + return categoryName; + } + + /** + * Get the property name. + * + * @return property name + */ + public String getPropertyName() { + return propertyName; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + AmbariConfigurationEntityPK that = (AmbariConfigurationEntityPK) o; + + return new EqualsBuilder() + .append(categoryName, that.categoryName) + .append(propertyName, that.propertyName) + .isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 37) + .append(categoryName) + .append(propertyName) + .toHashCode(); + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ConfigurationBaseEntity.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ConfigurationBaseEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ConfigurationBaseEntity.java deleted file mode 100644 index 9ad30d7..0000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ConfigurationBaseEntity.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * 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 org.apache.ambari.server.orm.entities; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; -import javax.persistence.TableGenerator; - -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; - -@Table(name = "configuration_base") -@TableGenerator( - name = "configuration_id_generator", - table = "ambari_sequences", - pkColumnName = "sequence_name", - valueColumnName = "sequence_value", - pkColumnValue = "configuration_id_seq", - initialValue = 1 -) -@Entity -public class ConfigurationBaseEntity { - - @Id - @Column(name = "id") - @GeneratedValue(strategy = GenerationType.TABLE, generator = "configuration_id_generator") - private Long id; - - @Column(name = "version") - private Integer version; - - @Column(name = "version_tag") - private String versionTag; - - @Column(name = "type") - private String type; - - @Column(name = "data") - private String configurationData; - - @Column(name = "attributes") - private String configurationAttributes; - - @Column(name = "create_timestamp") - private Long createTimestamp; - - public Long getId() { - return id; - } - - public Integer getVersion() { - return version; - } - - public void setVersion(Integer version) { - this.version = version; - } - - public String getVersionTag() { - return versionTag; - } - - public void setVersionTag(String versionTag) { - this.versionTag = versionTag; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getConfigurationData() { - return configurationData; - } - - public void setConfigurationData(String configurationData) { - this.configurationData = configurationData; - } - - public String getConfigurationAttributes() { - return configurationAttributes; - } - - public void setConfigurationAttributes(String configurationAttributes) { - this.configurationAttributes = configurationAttributes; - } - - public Long getCreateTimestamp() { - return createTimestamp; - } - - public void setCreateTimestamp(Long createTimestamp) { - this.createTimestamp = createTimestamp; - } - - @Override - public String toString() { - return "ConfigurationBaseEntity{" + - "id=" + id + - ", version=" + version + - ", versionTag='" + versionTag + '\'' + - ", type='" + type + '\'' + - ", configurationData='" + configurationData + '\'' + - ", configurationAttributes='" + configurationAttributes + '\'' + - ", createTimestamp=" + createTimestamp + - '}'; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - - if (o == null || getClass() != o.getClass()) return false; - - ConfigurationBaseEntity that = (ConfigurationBaseEntity) o; - - return new EqualsBuilder() - .append(id, that.id) - .append(version, that.version) - .append(versionTag, that.versionTag) - .append(type, that.type) - .append(configurationData, that.configurationData) - .append(configurationAttributes, that.configurationAttributes) - .append(createTimestamp, that.createTimestamp) - .isEquals(); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(17, 37) - .append(id) - .append(version) - .append(versionTag) - .append(type) - .append(configurationData) - .append(configurationAttributes) - .append(createTimestamp) - .toHashCode(); - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/KerberosKeytabEntity.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/KerberosKeytabEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/KerberosKeytabEntity.java new file mode 100644 index 0000000..a25931b --- /dev/null +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/KerberosKeytabEntity.java @@ -0,0 +1,86 @@ +/* + * 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.orm.entities; + +import java.util.Collection; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.OneToMany; +import javax.persistence.Table; + +@Entity +@Table(name = "kerberos_keytab") +@NamedQueries({ + @NamedQuery(name = "KerberosKeytabEntity.findAll", query = "SELECT kk FROM KerberosKeytabEntity kk"), + @NamedQuery(name = "KerberosKeytabEntity.findByHost", + query = "SELECT kk FROM KerberosKeytabEntity kk JOIN kk.kerberosPrincipalHostEntities he WHERE he.hostId=:hostId") +}) +public class KerberosKeytabEntity { + @Id + @Column(name = "keytab_path", insertable = true, updatable = false, nullable = false) + private String keytabPath = null; + + @OneToMany(mappedBy = "keytabEntity", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY) + private Collection<KerberosPrincipalHostEntity> kerberosPrincipalHostEntities; + + public KerberosKeytabEntity(){ + + } + + public KerberosKeytabEntity(String keytabPath){ + setKeytabPath(keytabPath); + } + + public String getKeytabPath() { + return keytabPath; + } + + public void setKeytabPath(String keytabPath) { + this.keytabPath = keytabPath; + } + + public Collection<KerberosPrincipalHostEntity> getKerberosPrincipalHostEntities() { + return kerberosPrincipalHostEntities; + } + + public void setKerberosPrincipalHostEntities(Collection<KerberosPrincipalHostEntity> kerberosPrincipalHostEntities) { + this.kerberosPrincipalHostEntities = kerberosPrincipalHostEntities; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + KerberosKeytabEntity that = (KerberosKeytabEntity) o; + + return keytabPath.equals(that.keytabPath); + } + + @Override + public int hashCode() { + return keytabPath.hashCode(); + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/KerberosPrincipalHostEntity.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/KerberosPrincipalHostEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/KerberosPrincipalHostEntity.java index bb67131..d4e80c6 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/KerberosPrincipalHostEntity.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/KerberosPrincipalHostEntity.java @@ -23,6 +23,7 @@ import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.IdClass; import javax.persistence.JoinColumn; +import javax.persistence.JoinColumns; import javax.persistence.ManyToOne; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; @@ -40,7 +41,9 @@ import javax.persistence.Table; @NamedQuery(name = "KerberosPrincipalHostEntityFindByPrincipal", query = "SELECT kph FROM KerberosPrincipalHostEntity kph WHERE kph.principalName=:principalName"), @NamedQuery(name = "KerberosPrincipalHostEntityFindByHost", - query = "SELECT kph FROM KerberosPrincipalHostEntity kph WHERE kph.hostId=:hostId") + query = "SELECT kph FROM KerberosPrincipalHostEntity kph WHERE kph.hostId=:hostId"), + @NamedQuery(name = "KerberosPrincipalHostEntityFindByKeytabPath", + query = "SELECT kph FROM KerberosPrincipalHostEntity kph WHERE kph.keytabPath=:keytabPath"), }) public class KerberosPrincipalHostEntity { @@ -52,6 +55,10 @@ public class KerberosPrincipalHostEntity { @Column(name = "host_id", insertable = true, updatable = false, nullable = false) private Long hostId; + @Id + @Column(name = "keytab_path", updatable = false, nullable = false) + private String keytabPath; + @ManyToOne @JoinColumn(name = "principal_name", referencedColumnName = "principal_name", nullable = false, insertable = false, updatable = false) private KerberosPrincipalEntity principalEntity; @@ -60,6 +67,14 @@ public class KerberosPrincipalHostEntity { @JoinColumn(name = "host_id", referencedColumnName = "host_id", nullable = false, insertable = false, updatable = false) private HostEntity hostEntity; + @ManyToOne + @JoinColumns({ + @JoinColumn(name = "keytab_path", referencedColumnName = "keytab_path", nullable = false, insertable = false, updatable = false) + }) + private KerberosKeytabEntity keytabEntity; + + @Column(name = "is_distributed", insertable = true, updatable = true, nullable = false) + private Integer isDistributed = 0; /** * Constucts an empty KerberosPrincipalHostEntity */ @@ -72,9 +87,23 @@ public class KerberosPrincipalHostEntity { * @param principalName a String indicating this KerberosPrincipalHostEntity's principal name * @param hostId a Long indicating the KerberosPrincipalHostEntity's host id */ - public KerberosPrincipalHostEntity(String principalName, Long hostId) { + public KerberosPrincipalHostEntity(String principalName, Long hostId, String keytabPath) { + setPrincipalName(principalName); + setHostId(hostId); + setKeytabPath(keytabPath); + } + + /** + * Constructs a new KerberosPrincipalHostEntity + * + * @param principalName a String indicating this KerberosPrincipalHostEntity's principal name + * @param hostId a Long indicating the KerberosPrincipalHostEntity's host id + */ + public KerberosPrincipalHostEntity(String principalName, Long hostId, String keytabPath, boolean isDistributed) { setPrincipalName(principalName); setHostId(hostId); + setKeytabPath(keytabPath); + setDistributed(isDistributed); } /** @@ -157,4 +186,28 @@ public class KerberosPrincipalHostEntity { public void setPrincipalEntity(KerberosPrincipalEntity principalEntity) { this.principalEntity = principalEntity; } + + public String getKeytabPath() { + return keytabPath; + } + + public void setKeytabPath(String keytabPath) { + this.keytabPath = keytabPath; + } + + public KerberosKeytabEntity getKeytabEntity() { + return keytabEntity; + } + + public void setKeytabEntity(KerberosKeytabEntity keytabEntity) { + this.keytabEntity = keytabEntity; + } + + public Boolean getDistributed() { + return isDistributed == 1; + } + + public void setDistributed(Boolean isDistributed) { + this.isDistributed = (isDistributed) ? 1 : 0; + } } http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/KerberosPrincipalHostEntityPK.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/KerberosPrincipalHostEntityPK.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/KerberosPrincipalHostEntityPK.java index 600bb8b..7e57e4a 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/KerberosPrincipalHostEntityPK.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/KerberosPrincipalHostEntityPK.java @@ -36,12 +36,17 @@ public class KerberosPrincipalHostEntityPK implements Serializable{ @Column(name = "host_id", insertable = false, updatable = false, nullable = false) private Long hostId = null; + @Id + @Column(name = "keytab_path", insertable = false, updatable = false, nullable = false) + private String keytabPath = null; + public KerberosPrincipalHostEntityPK() { } - public KerberosPrincipalHostEntityPK(String principalName, Long hostId) { + public KerberosPrincipalHostEntityPK(String principalName, Long hostId, String keytabPath) { setPrincipalName(principalName); setHostId(hostId); + setKeytabPath(keytabPath); } /** @@ -92,11 +97,19 @@ public class KerberosPrincipalHostEntityPK implements Serializable{ KerberosPrincipalHostEntityPK that = (KerberosPrincipalHostEntityPK) o; return this.principalName.equals(that.principalName) && - this.hostId.equals(that.hostId); + this.hostId.equals(that.hostId) && this.keytabPath.equals(that.keytabPath); } @Override public int hashCode() { - return 31 * principalName.hashCode() + hostId.hashCode(); + return 31 * principalName.hashCode() + hostId.hashCode() + keytabPath.hashCode(); + } + + public String getKeytabPath() { + return keytabPath; + } + + public void setKeytabPath(String keytabPath) { + this.keytabPath = keytabPath; } } http://git-wip-us.apache.org/repos/asf/ambari/blob/e83bf1bd/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RemoteAmbariClusterEntity.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RemoteAmbariClusterEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RemoteAmbariClusterEntity.java index 4f10d6f..aad37d8 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RemoteAmbariClusterEntity.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RemoteAmbariClusterEntity.java @@ -65,7 +65,7 @@ public class RemoteAmbariClusterEntity { /** * The logger. */ - protected final static Logger LOG = LoggerFactory.getLogger(RemoteAmbariClusterEntity.class); + private static final Logger LOG = LoggerFactory.getLogger(RemoteAmbariClusterEntity.class); @Id @Column(name = "cluster_id", nullable = false)
