incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject svn commit: r1392745 - in /incubator/ambari/branches/AMBARI-666: ./ ambari-server/src/main/assemblies/ ambari-server/src/main/java/org/apache/ambari/server/ ambari-server/src/main/java/org/apache/ambari/server/configuration/ ambari-server/src/main/java...
Date Tue, 02 Oct 2012 05:22:50 GMT
Author: mahadev
Date: Tue Oct  2 05:22:49 2012
New Revision: 1392745

URL: http://svn.apache.org/viewvc?rev=1392745&view=rev
Log:
AMBARI-784. Add Resource download API on the server. (mahadev)

Added:
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/assemblies/empty.xml
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/resources/
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/resources/ResourceManager.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/resources/api/
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/resources/api/rest/
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/resources/api/rest/GetResource.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/python/ambari-server.py  
(with props)
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/resources/db/index.txt
    incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/resources/
    incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/resources/TestResources.java
Modified:
    incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/assemblies/server.xml
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/AmbariException.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/security/SecurityFilter.java

Modified: incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt?rev=1392745&r1=1392744&r2=1392745&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt (original)
+++ incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt Tue Oct  2 05:22:49 2012
@@ -12,6 +12,8 @@ AMBARI-666 branch (unreleased changes)
 
   NEW FEATURES
 
+  AMBARI-784. Add Resource download API on the server. (mahadev)
+
   AMBARI-781. Registration unit test. (jitendra)
 
   AMBARI-754. Heartbeat handler: Registration response should query component 

Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/assemblies/empty.xml
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/assemblies/empty.xml?rev=1392745&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/assemblies/empty.xml (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/assemblies/empty.xml Tue Oct
 2 05:22:49 2012
@@ -0,0 +1,21 @@
+<!--
+  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.
+-->
+<assembly>
+    <id>empty</id>
+    <formats/>
+</assembly>

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/assemblies/server.xml
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/assemblies/server.xml?rev=1392745&r1=1392744&r2=1392745&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/assemblies/server.xml (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/assemblies/server.xml Tue
Oct  2 05:22:49 2012
@@ -28,7 +28,6 @@
       <source>${project.build.directory}/${artifact.artifactId}-${artifact.version}.jar</source>
       <outputDirectory>ambari-server-${project.version}/lib</outputDirectory>
     </file>
-
   </files>
   <fileSets>
     <!-- Distro files, readme, licenses, etc -->
@@ -60,6 +59,14 @@
       </includes>
     </fileSet>
 
+    <fileSet>
+      <directory>src/main/assemblies</directory>
+      <outputDirectory>/ambari-server-${project.version}/res</outputDirectory>
+      <excludes>
+        <exclude>*</exclude>
+      </excludes>
+    </fileSet>
+
   </fileSets>
   <dependencySets>
     <dependencySet>

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/AmbariException.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/AmbariException.java?rev=1392745&r1=1392744&r2=1392745&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/AmbariException.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/AmbariException.java
Tue Oct  2 05:22:49 2012
@@ -26,4 +26,8 @@ public class AmbariException extends IOE
   public AmbariException(String message) {
     super(message);
   }
+
+  public AmbariException(String message, Throwable cause) {
+    super(message, cause);
+  }
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java?rev=1392745&r1=1392744&r2=1392745&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
Tue Oct  2 05:22:49 2012
@@ -52,6 +52,7 @@ public class Configuration {
   public static final String SRVR_CRT_PASS_KEY = "security.server.crt_pass";
   public static final String PASSPHRASE_ENV_KEY = "security.server.passphrase_env_var";
   public static final String PASSPHRASE_KEY = "security.server.passphrase";
+  public static final String RESOURCES_DIR_KEY = "resources.dir";
 
   public static final String CLIENT_SECURITY_KEY = "client.security";
   public static final String LDAP_USE_SSL_KEY = "authorization.ldap.useSSL";
@@ -70,6 +71,7 @@ public class Configuration {
   public static final String KSTR_NAME_DEFAULT = "keystore.p12";
   private static final String SRVR_CRT_PASS_FILE_DEFAULT ="pass.txt";
   private static final String PASSPHRASE_ENV_DEFAULT = "AMBARI_PASSPHRASE";
+  private static final String RESOURCES_DIR_DEFAULT = "res";
 
 
   private static final String CLIENT_SECURITY_DEFAULT = "local";
@@ -120,7 +122,7 @@ public class Configuration {
 	configsMap.put(PASSPHRASE_KEY, System.getenv(configsMap.get(PASSPHRASE_ENV_KEY)));
     configsMap.put(CLIENT_SECURITY_KEY, properties.getProperty(CLIENT_SECURITY_KEY, CLIENT_SECURITY_DEFAULT));
     configsMap.put(LDAP_USER_DEFAULT_ROLE_KEY, properties.getProperty(LDAP_USER_DEFAULT_ROLE_KEY,
LDAP_USER_DEFAULT_ROLE_DEFAULT));
-
+    configsMap.put(RESOURCES_DIR_KEY, properties.getProperty(RESOURCES_DIR_KEY, RESOURCES_DIR_DEFAULT));
     try {
         File passFile = new File(configsMap.get(SRVR_KSTR_DIR_KEY) + File.separator
             + configsMap.get(SRVR_CRT_PASS_FILE_KEY));

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java?rev=1392745&r1=1392744&r2=1392745&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
Tue Oct  2 05:22:49 2012
@@ -170,6 +170,14 @@ public class AmbariServer {
       root.addServlet(cert, "/certs/*");
       certs.setInitOrder(5);
 
+      ServletHolder resources = new ServletHolder(ServletContainer.class);
+      resources.setInitParameter("com.sun.jersey.config.property.resourceConfigClass",
+        "com.sun.jersey.api.core.PackagesResourceConfig");
+      resources.setInitParameter("com.sun.jersey.config.property.packages",
+        "org.apache.ambari.server.resources.api.rest");
+      root.addServlet(resources, "/resources/*");
+      resources.setInitOrder(6);
+
       server.setStopAtShutdown(true);
 
       springAppContext.start();

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java?rev=1392745&r1=1392744&r2=1392745&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
Tue Oct  2 05:22:49 2012
@@ -17,6 +17,7 @@
  */
 package org.apache.ambari.server.controller;
 import org.apache.ambari.server.agent.rest.AgentResource;
+import org.apache.ambari.server.resources.api.rest.GetResource;
 import org.apache.ambari.server.security.unsecured.rest.CertificateDownload;
 import org.apache.ambari.server.security.unsecured.rest.CertificateSign;
 
@@ -30,8 +31,10 @@ public class ControllerModule extends Ab
 
   @Override
   protected void configure() {
+
     requestStaticInjection(AgentResource.class);
     requestStaticInjection(CertificateDownload.class);
     requestStaticInjection(CertificateSign.class);
+    requestStaticInjection(GetResource.class);
   }
 }

Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/resources/ResourceManager.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/resources/ResourceManager.java?rev=1392745&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/resources/ResourceManager.java
(added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/resources/ResourceManager.java
Tue Oct  2 05:22:49 2012
@@ -0,0 +1,48 @@
+/**
+ * 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.resources;
+
+import java.io.File;
+
+import org.apache.ambari.server.configuration.Configuration;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+
+/**
+ * Resource manager.
+ */
+@Singleton
+public class ResourceManager {
+  private static Log LOG = LogFactory.getLog(ResourceManager.class);
+	
+  @Inject Configuration configs;
+  /**
+  * Returns resource file.
+  * @param resourcePath relational path to file
+  * @return resource file
+  */
+  public File getResource(String resourcePath) {
+    String resDir = configs.getConfigsMap().get(Configuration.RESOURCES_DIR_KEY);
+    String resourcePathIndep = resourcePath.replaceAll("/", File.separator);
+    File resourceFile = new File(resDir + File.separator + resourcePathIndep);
+    return resourceFile;
+  }
+}

Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/resources/api/rest/GetResource.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/resources/api/rest/GetResource.java?rev=1392745&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/resources/api/rest/GetResource.java
(added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/resources/api/rest/GetResource.java
Tue Oct  2 05:22:49 2012
@@ -0,0 +1,67 @@
+/**
+ * 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.resources.api.rest;
+
+
+import java.io.File;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.ambari.server.resources.ResourceManager;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import com.google.inject.Inject;
+
+/**
+ * Resource api.
+ */
+@Path("/")
+public class GetResource {
+  private static Log LOG = LogFactory.getLog(GetResource.class);
+
+  private static ResourceManager resMan;
+
+  @Inject
+  static void init(ResourceManager instance) {
+	  resMan = instance;
+  }
+
+
+  @GET
+  @Path("{resourcePath:.*}")
+  @Consumes(MediaType.TEXT_PLAIN)
+  @Produces(MediaType.APPLICATION_OCTET_STREAM)
+  public Response getResource(@PathParam("resourcePath") String resourcePath, @Context HttpServletRequest
req) {
+    File resourceFile = resMan.getResource(resourcePath);
+
+    if (!resourceFile.exists())
+    	return Response.status(HttpServletResponse.SC_NOT_FOUND).build();
+
+    return Response.ok(resourceFile).build();
+  }
+}

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/security/SecurityFilter.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/security/SecurityFilter.java?rev=1392745&r1=1392744&r2=1392745&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/security/SecurityFilter.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/security/SecurityFilter.java
Tue Oct  2 05:22:49 2012
@@ -49,7 +49,6 @@ public class SecurityFilter implements F
 
     System.out.println("req url:" + reqUrl);
 
-    //req.getC
 	
     if (serReq.getLocalPort() == AmbariServer.CLIENT_ONE_WAY) {
       if (isRequestAllowed(reqUrl))
@@ -78,6 +77,11 @@ public class SecurityFilter implements F
 		 if (isMatch)
 			 return true;
 		
+		 isMatch = Pattern.matches("https://[A-z]*:[0-9]*/resources/.*", reqUrl);
+		
+		 if (isMatch)
+			 return true;
+		
 	} catch (Exception e) {
 	}
 	return false;

Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/python/ambari-server.py
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/python/ambari-server.py?rev=1392745&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/python/ambari-server.py (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/python/ambari-server.py Tue
Oct  2 05:22:49 2012
@@ -0,0 +1,62 @@
+#!/usr/bin/env python
+
+'''
+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.
+'''
+
+import optparse
+import argparse
+import sys
+import subprocess
+
+SETUP_ACTION = "setup"
+START_ACTION = "start"
+STOP_ACTION = "stop"
+SETUP_CMD = "sudo -u postgres psql -f setup_db.sql"
+
+
+def setup():
+  command = SETUP_CMD
+  process = subprocess.Popen(command.split(' '),
+                             stdout=subprocess.PIPE,
+                             stderr=subprocess.PIPE)
+  process.communicate()
+
+def main():
+  parser = argparse.ArgumentParser()
+  parser.add_argument("action", help="action to perform with ambari server")
+  parser.add_argument('-postgreuser', '--postgreuser', default='root',
+                      help="User in postgresql to run init scripts")
+  parser.add_argument('-postgrepass', '--postgrepass')
+  args = parser.parse_args()
+
+  action = args.action
+  if action == SETUP_ACTION:
+    setup()
+  elif action == START_ACTION:
+    print START_ACTION
+  elif action == STOP_ACTION:
+    print STOP_ACTION
+  else:
+    print "Incorrect action"
+    sys.exit(2)
+    
+
+    
+    
+if __name__ == "__main__":
+  main()
\ No newline at end of file

Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/python/ambari-server.py
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/resources/db/index.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/resources/db/index.txt?rev=1392745&view=auto
==============================================================================
    (empty)

Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/resources/TestResources.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/resources/TestResources.java?rev=1392745&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/resources/TestResources.java
(added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/resources/TestResources.java
Tue Oct  2 05:22:49 2012
@@ -0,0 +1,92 @@
+/**
+ * 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.resources;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+import org.apache.ambari.server.configuration.Configuration;
+import org.apache.commons.io.FileUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+
+public class TestResources extends TestCase {
+	
+  private static ResourceManager resMan;
+  private static final String RESOURCE_FILE_NAME = "resource.ext";
+  private static final String RESOURCE_FILE_CONTENT = "CONTENT";
+  Injector injector;
+  private TemporaryFolder tempFolder = new TemporaryFolder();
+  private File resourceFile;
+
+  private class ResourceModule extends AbstractModule {
+  @Override
+    protected void configure() {
+	  requestStaticInjection(TestResources.class);
+	}
+  }
+
+  @Inject
+  static void init(ResourceManager instance) {
+    resMan = instance;
+  }
+
+  @Before
+  public void setUp() throws IOException {
+	tempFolder.create();
+	
+    System.setProperty(Configuration.AMBARI_CONF_VAR, tempFolder.getRoot().getAbsolutePath());
+	Properties props = new Properties();
+	props.setProperty(Configuration.SRVR_KSTR_DIR_KEY, tempFolder.getRoot().getAbsolutePath());
+	props.setProperty(Configuration.RESOURCES_DIR_KEY, tempFolder.getRoot().getAbsolutePath());
+	FileOutputStream out = new FileOutputStream(tempFolder.getRoot().getAbsolutePath() + File.separator
+ Configuration.CONFIG_FILE);
+	props.store(out, "");
+	out.close();
+    resourceFile = tempFolder.newFile(RESOURCE_FILE_NAME);
+    FileUtils.write(resourceFile, RESOURCE_FILE_CONTENT);
+    injector = Guice.createInjector(new ResourceModule());
+    resMan = injector.getInstance(ResourceManager.class);
+  }
+	
+  @After
+  public void tearDown() throws IOException {
+    resourceFile.delete();
+	tempFolder.delete();
+  }
+	
+  @Test
+  public void testGetResource() throws Exception {
+    File resFile = resMan.getResource(resourceFile.getName());
+    assertTrue(resFile.exists());
+    String resContent = FileUtils.readFileToString(resFile);
+    assertEquals(resContent, RESOURCE_FILE_CONTENT);
+  }
+
+}



Mime
View raw message