You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by am...@apache.org on 2018/05/11 07:28:15 UTC
[ambari] branch trunk updated: [AMBARI-23793]. MySQL Connector JAR
distribution is broken (amagyar) (#1219)
This is an automated email from the ASF dual-hosted git repository.
amagyar pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git
The following commit(s) were added to refs/heads/trunk by this push:
new ad366eb [AMBARI-23793]. MySQL Connector JAR distribution is broken (amagyar) (#1219)
ad366eb is described below
commit ad366eb2787e9c404f1c29bef5233af2f0154069
Author: Attila Magyar <m....@gmail.com>
AuthorDate: Fri May 11 09:28:12 2018 +0200
[AMBARI-23793]. MySQL Connector JAR distribution is broken (amagyar) (#1219)
* AMBARI-23793. MySQL Connector JAR distribution is broken (amagyar)
* AMBARI-23793. MySQL Connector JAR distribution is broken (amagyar)
* AMBARI-23793. MySQL Connector JAR distribution is broken (amagyar)
* AMBARI-23793. MySQL Connector JAR distribution is broken (amagyar)
---
ambari-project/pom.xml | 6 ++
ambari-server/pom.xml | 5 ++
.../ambari/server/agent/stomp/MetadataHolder.java | 6 ++
.../ambari/server/configuration/Configuration.java | 10 ++-
.../server/configuration/SingleFileWatch.java | 95 ++++++++++++++++++++++
.../ambari/server/controller/AmbariServer.java | 12 +++
.../apache/ambari/server/events/AmbariEvent.java | 5 ++
.../events/AmbariPropertiesChangedEvent.java | 31 +++++++
.../server/configuration/SingleFileWatchTest.java | 81 ++++++++++++++++++
9 files changed, 248 insertions(+), 3 deletions(-)
diff --git a/ambari-project/pom.xml b/ambari-project/pom.xml
index 854f9cb..662c2d5 100644
--- a/ambari-project/pom.xml
+++ b/ambari-project/pom.xml
@@ -247,6 +247,12 @@
<version>1.3</version>
</dependency>
<dependency>
+ <groupId>org.awaitility</groupId>
+ <artifactId>awaitility</artifactId>
+ <version>3.1.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
diff --git a/ambari-server/pom.xml b/ambari-server/pom.xml
index b52baf4..1c05d94 100644
--- a/ambari-server/pom.xml
+++ b/ambari-server/pom.xml
@@ -1271,6 +1271,11 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.awaitility</groupId>
+ <artifactId>awaitility</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/MetadataHolder.java b/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/MetadataHolder.java
index 596808f..6e5d9cc 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/MetadataHolder.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/agent/stomp/MetadataHolder.java
@@ -22,6 +22,7 @@ import java.util.Map;
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.agent.stomp.dto.MetadataCluster;
import org.apache.ambari.server.controller.AmbariManagementControllerImpl;
+import org.apache.ambari.server.events.AmbariPropertiesChangedEvent;
import org.apache.ambari.server.events.ClusterComponentsRepoChangedEvent;
import org.apache.ambari.server.events.ClusterConfigChangedEvent;
import org.apache.ambari.server.events.MetadataUpdateEvent;
@@ -107,4 +108,9 @@ public class MetadataHolder extends AgentClusterDataHolder<MetadataUpdateEvent>
Cluster cluster = m_clusters.get().getCluster(serviceCredentialStoreUpdateEvent.getClusterId());
updateData(ambariManagementController.getClusterMetadataOnServiceCredentialStoreUpdate(cluster, serviceCredentialStoreUpdateEvent.getServiceName()));
}
+
+ @Subscribe
+ public void onAmbariPropertiesChange(AmbariPropertiesChangedEvent event) throws AmbariException {
+ updateData(ambariManagementController.getClustersMetadata());
+ }
}
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
index dd99b97..badb79e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
@@ -2936,7 +2936,7 @@ public class Configuration {
private void writeConfigFile(Properties propertiesToStore, boolean append) throws AmbariException {
File configFile = null;
try {
- configFile = new File(Configuration.class.getClassLoader().getResource(Configuration.CONFIG_FILE).getPath());
+ configFile = getConfigFile();
propertiesToStore.store(new OutputStreamWriter(new FileOutputStream(configFile, append), Charsets.UTF_8), null);
} catch (Exception e) {
LOG.error("Cannot write properties [" + propertiesToStore + "] into configuration file [" + configFile + ", " + append + "] ");
@@ -3096,7 +3096,7 @@ public class Configuration {
}
public Map<String, String> getDatabaseConnectorNames() {
- File file = new File(Configuration.class.getClassLoader().getResource(CONFIG_FILE).getPath());
+ File file = getConfigFile();
Long currentConfigLastModifiedDate = file.lastModified();
Properties properties = null;
if (currentConfigLastModifiedDate.longValue() != configLastModifiedDateForCustomJDBC.longValue()) {
@@ -3120,8 +3120,12 @@ public class Configuration {
return databaseConnectorNames;
}
+ public File getConfigFile() {
+ return new File(Configuration.class.getClassLoader().getResource(CONFIG_FILE).getPath());
+ }
+
public Map<String, String> getPreviousDatabaseConnectorNames() {
- File file = new File(Configuration.class.getClassLoader().getResource(CONFIG_FILE).getPath());
+ File file = getConfigFile();
Long currentConfigLastModifiedDate = file.lastModified();
Properties properties = null;
if (currentConfigLastModifiedDate.longValue() != configLastModifiedDateForCustomJDBCToRemove.longValue()) {
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/configuration/SingleFileWatch.java b/ambari-server/src/main/java/org/apache/ambari/server/configuration/SingleFileWatch.java
new file mode 100644
index 0000000..3d9e8e2
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/configuration/SingleFileWatch.java
@@ -0,0 +1,95 @@
+/*
+ *
+ * * 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.configuration;
+
+import java.io.File;
+import java.util.function.Consumer;
+
+import org.apache.log4j.helpers.FileWatchdog;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Watchdog that notifies a listener on a file content change.
+ */
+public class SingleFileWatch {
+ private static final Logger LOG = LoggerFactory.getLogger(SingleFileWatch.class);
+ private final File file;
+ private final FileWatchdog watchdog;
+ private final Consumer<File> changeListener;
+ private volatile boolean started = false;
+
+ /**
+ * @param file to be watched
+ * @param changeListener to be notified if the file content changes
+ */
+ public SingleFileWatch(File file, Consumer<File> changeListener) {
+ this.file = file;
+ this.changeListener = changeListener;
+ this.watchdog = createWatchDog();
+ }
+
+ private FileWatchdog createWatchDog() {
+ FileWatchdog fileWatch = new FileWatchdog(file.getAbsolutePath()) {
+ @Override
+ protected void doOnChange() {
+ if (started) {
+ notifyListener();
+ }
+ }
+ };
+ fileWatch.setDelay(1000);
+ fileWatch.setDaemon(true);
+ fileWatch.setName("FileWatchdog:" + file.getName());
+ return fileWatch;
+ }
+
+ private void notifyListener() {
+ LOG.info("{} changed. Sending notification.", file);
+ try {
+ changeListener.accept(file);
+ } catch (Exception e) {
+ LOG.warn("Error while notifying " + this + " listener", e);
+ }
+ }
+
+ /**
+ * Start the watch service in the background
+ */
+ public void start() {
+ LOG.info("Starting " + this);
+ started = true;
+ watchdog.start();
+ }
+
+ /**
+ * Stop the watch service
+ */
+ public void stop() {
+ LOG.info("Stopping " + this);
+ started = false;
+ watchdog.interrupt();
+ }
+
+ public String toString() {
+ return "SingleFileWatcher:" + file.getName();
+ }
+}
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
index a425dd8..986c7b6 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
@@ -59,6 +59,7 @@ import org.apache.ambari.server.checks.DatabaseConsistencyCheckHelper;
import org.apache.ambari.server.checks.DatabaseConsistencyCheckResult;
import org.apache.ambari.server.configuration.ComponentSSLConfiguration;
import org.apache.ambari.server.configuration.Configuration;
+import org.apache.ambari.server.configuration.SingleFileWatch;
import org.apache.ambari.server.configuration.spring.AgentStompConfig;
import org.apache.ambari.server.configuration.spring.ApiSecurityConfig;
import org.apache.ambari.server.configuration.spring.ApiStompConfig;
@@ -79,6 +80,8 @@ import org.apache.ambari.server.controller.internal.ViewPermissionResourceProvid
import org.apache.ambari.server.controller.metrics.ThreadPoolEnabledPropertyProvider;
import org.apache.ambari.server.controller.utilities.KerberosChecker;
import org.apache.ambari.server.controller.utilities.KerberosIdentityCleaner;
+import org.apache.ambari.server.events.AmbariPropertiesChangedEvent;
+import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
import org.apache.ambari.server.ldap.LdapModule;
import org.apache.ambari.server.metrics.system.MetricsService;
import org.apache.ambari.server.orm.GuiceJpaInitializer;
@@ -945,6 +948,15 @@ public class AmbariServer {
KerberosIdentityCleaner identityCleaner = injector.getInstance(KerberosIdentityCleaner.class);
identityCleaner.register();
+
+ configureFileWatcher();
+ }
+
+ private void configureFileWatcher() {
+ AmbariEventPublisher ambariEventPublisher = injector.getInstance(AmbariEventPublisher.class);
+ Configuration config = injector.getInstance(Configuration.class);
+ SingleFileWatch watch = new SingleFileWatch(config.getConfigFile(), file -> ambariEventPublisher.publish(new AmbariPropertiesChangedEvent()));
+ watch.start();
}
/**
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 fee12b1..bb18cc9 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
@@ -168,6 +168,11 @@ public abstract class AmbariEvent {
AMBARI_CONFIGURATION_CHANGED,
/**
+ * Ambari properties changed event;
+ */
+ AMBARI_PROPERTIES_CHANGED,
+
+ /**
* JPA initialized
*/
JPA_INITIALIZED,
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariPropertiesChangedEvent.java b/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariPropertiesChangedEvent.java
new file mode 100644
index 0000000..5c557e7
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariPropertiesChangedEvent.java
@@ -0,0 +1,31 @@
+/*
+ *
+ * * 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.events;
+
+/**
+ * This event is fired when ambari.properties file changes
+ */
+public class AmbariPropertiesChangedEvent extends AmbariEvent {
+
+ public AmbariPropertiesChangedEvent() {
+ super(AmbariEventType.AMBARI_CONFIGURATION_CHANGED);
+ }
+}
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/configuration/SingleFileWatchTest.java b/ambari-server/src/test/java/org/apache/ambari/server/configuration/SingleFileWatchTest.java
new file mode 100644
index 0000000..791a9ce
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/configuration/SingleFileWatchTest.java
@@ -0,0 +1,81 @@
+/*
+ *
+ * * 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.configuration;
+
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.apache.commons.io.FileUtils.writeStringToFile;
+import static org.awaitility.Awaitility.await;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+
+import org.awaitility.core.ConditionTimeoutException;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+public class SingleFileWatchTest {
+ @Rule
+ public TemporaryFolder tmp = new TemporaryFolder();
+ private SingleFileWatch watchDog;
+ private File fileToWatch;
+ private volatile int numberOfEventsReceived = 0;
+
+ @Before
+ public void setUp() throws Exception {
+ tmp.create();
+ fileToWatch = tmp.newFile();
+ watchDog = new SingleFileWatch(fileToWatch, file -> numberOfEventsReceived++);
+ watchDog.start();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ watchDog.stop();
+ }
+
+ @Test
+ public void testTriggersEventsOnMultipleFileChange() throws Exception {
+ changeFile("change1");
+ hasReceivedChangeEvents(1);
+ changeFile("change2");
+ hasReceivedChangeEvents(2);
+ changeFile("change3");
+ hasReceivedChangeEvents(3);
+ }
+
+ private void hasReceivedChangeEvents(int expectedNumberOfEvents) {
+ try {
+ await().atMost(8, SECONDS).until(() -> numberOfEventsReceived == expectedNumberOfEvents);
+ } catch (ConditionTimeoutException e) {
+ fail("Expected number of file change events: " + expectedNumberOfEvents + " but received: " + numberOfEventsReceived);
+ }
+ }
+
+ private void changeFile(String content) throws Exception {
+ long lastModified = fileToWatch.lastModified();
+ while (lastModified == fileToWatch.lastModified()) {
+ writeStringToFile(fileToWatch, content, "UTF-8");
+ }
+ }
+}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
amagyar@apache.org.