You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@slider.apache.org by st...@apache.org on 2014/06/25 03:11:58 UTC
[2/6] git commit: File upload work ... security model wrong
File upload work ... security model wrong
Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/8327e52a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/8327e52a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/8327e52a
Branch: refs/heads/develop
Commit: 8327e52ae2dec00e0a954da1804413b1ef76f93c
Parents: 81578df
Author: Steve Loughran <st...@apache.org>
Authored: Mon Jun 23 18:42:25 2014 -0700
Committer: Steve Loughran <st...@apache.org>
Committed: Mon Jun 23 18:42:25 2014 -0700
----------------------------------------------------------------------
.../funtest/framework/AgentUploads.groovy | 41 +++++++++++
.../funtest/framework/FileUploader.groovy | 76 ++++++++++++++++++++
.../slider/funtest/framework/SudoClosure.groovy | 54 ++++++++++++++
3 files changed, 171 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/8327e52a/slider-funtest/src/main/groovy/org/apache/slider/funtest/framework/AgentUploads.groovy
----------------------------------------------------------------------
diff --git a/slider-funtest/src/main/groovy/org/apache/slider/funtest/framework/AgentUploads.groovy b/slider-funtest/src/main/groovy/org/apache/slider/funtest/framework/AgentUploads.groovy
new file mode 100644
index 0000000..b1c29c0
--- /dev/null
+++ b/slider-funtest/src/main/groovy/org/apache/slider/funtest/framework/AgentUploads.groovy
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.slider.funtest.framework
+
+import groovy.util.logging.Slf4j
+import org.apache.hadoop.conf.Configuration
+import org.apache.hadoop.fs.FileUtil
+import org.apache.hadoop.fs.Path
+import org.apache.hadoop.fs.permission.FsPermission
+import org.apache.hadoop.security.UserGroupInformation
+
+@Slf4j
+class AgentUploads {
+ final Configuration conf
+
+
+ AgentUploads(Configuration conf) {
+ this.conf = conf
+ }
+
+ def execUploadSequence() {
+ UserGroupInformation.loginUserFromKeytabAndReturnUGI("yarn")
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/8327e52a/slider-funtest/src/main/groovy/org/apache/slider/funtest/framework/FileUploader.groovy
----------------------------------------------------------------------
diff --git a/slider-funtest/src/main/groovy/org/apache/slider/funtest/framework/FileUploader.groovy b/slider-funtest/src/main/groovy/org/apache/slider/funtest/framework/FileUploader.groovy
new file mode 100644
index 0000000..dd42473
--- /dev/null
+++ b/slider-funtest/src/main/groovy/org/apache/slider/funtest/framework/FileUploader.groovy
@@ -0,0 +1,76 @@
+/*
+ * 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.slider.funtest.framework
+
+import groovy.util.logging.Slf4j
+import org.apache.hadoop.conf.Configuration
+import org.apache.hadoop.fs.FileUtil
+import org.apache.hadoop.fs.Path
+import org.apache.hadoop.fs.permission.FsPermission
+import org.apache.hadoop.security.UserGroupInformation
+
+@Slf4j
+class FileUploader {
+ final Configuration conf
+ final UserGroupInformation user
+
+ FileUploader(Configuration conf, UserGroupInformation user) {
+ this.conf = conf
+ this.user = user
+ }
+
+ /**
+ * Copy if the file is considered out of date
+ * @param src
+ * @param dest
+ * @param force
+ * @return
+ */
+ public boolean copyIfOutOfDate(File src, Path dest, boolean force) {
+ def srcLen = src.length()
+ def fs = getFileSystem(user, dest.toUri())
+ boolean toCopy = force
+ if (!toCopy) {
+ try {
+ def status = fs.getFileStatus(dest)
+ toCopy = status.len != srcLen
+ } catch (FileNotFoundException fnfe) {
+ toCopy = true;
+ }
+ }
+ if (toCopy) {
+ log.info("Copying $src to $dest")
+ fs.mkdirs(dest, FsPermission.dirDefault)
+ return FileUtil.copy(src, fs, dest, false, conf)
+ } else {
+ log.debug("Skipping copy as the destination $dest considered up to date")
+ return false;
+ }
+
+ }
+
+
+ public static def getFileSystem(
+ UserGroupInformation user, final URI uri) {
+ SudoClosure.sudo(user) {
+ org.apache.hadoop.fs.FileSystem.get(uri, conf);
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/8327e52a/slider-funtest/src/main/groovy/org/apache/slider/funtest/framework/SudoClosure.groovy
----------------------------------------------------------------------
diff --git a/slider-funtest/src/main/groovy/org/apache/slider/funtest/framework/SudoClosure.groovy b/slider-funtest/src/main/groovy/org/apache/slider/funtest/framework/SudoClosure.groovy
new file mode 100644
index 0000000..363e1b3
--- /dev/null
+++ b/slider-funtest/src/main/groovy/org/apache/slider/funtest/framework/SudoClosure.groovy
@@ -0,0 +1,54 @@
+/*
+ * 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.slider.funtest.framework
+
+import org.apache.hadoop.security.UserGroupInformation
+
+import java.security.PrivilegedExceptionAction
+
+/**
+ * Bridge from groovy closures to doAs
+ * @param < T >
+ */
+class SudoClosure<T> implements PrivilegedExceptionAction<T> {
+
+ final Closure<T> closure;
+
+ SudoClosure(Closure<T> closure) {
+ this.closure = closure
+ }
+
+ @Override
+ T run() throws Exception {
+ return closure()
+ }
+
+ /**
+ *
+ * @param user
+ * @param closure
+ * @return
+ */
+ public static <T2> T2 sudo(UserGroupInformation user,
+ Closure<T2> closure) {
+
+ user.doAs(new SudoClosure<T2>(closure))
+
+ }
+}