Пример #1
0
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        /// <exception cref="System.IO.IOException"/>
        public virtual SCMUploaderNotifyResponse Notify(SCMUploaderNotifyRequest request)
        {
            SCMUploaderNotifyResponse response = recordFactory.NewRecordInstance <SCMUploaderNotifyResponse
                                                                                  >();
            // TODO (YARN-2774): proper security/authorization needs to be implemented
            string filename = store.AddResource(request.GetResourceKey(), request.GetFileName
                                                    ());
            bool accepted = filename.Equals(request.GetFileName());

            if (accepted)
            {
                this.metrics.IncAcceptedUploads();
            }
            else
            {
                this.metrics.IncRejectedUploads();
            }
            response.SetAccepted(accepted);
            return(response);
        }
        public virtual void TestSuccess()
        {
            Configuration conf = new Configuration();

            conf.SetBoolean(YarnConfiguration.SharedCacheEnabled, true);
            LocalResource resource  = Org.Mockito.Mockito.Mock <LocalResource>();
            Path          localPath = Org.Mockito.Mockito.Mock <Path>();

            Org.Mockito.Mockito.When(localPath.GetName()).ThenReturn("foo.jar");
            string user = "******";
            SCMUploaderProtocol       scmClient = Org.Mockito.Mockito.Mock <SCMUploaderProtocol>();
            SCMUploaderNotifyResponse response  = Org.Mockito.Mockito.Mock <SCMUploaderNotifyResponse
                                                                            >();

            Org.Mockito.Mockito.When(response.GetAccepted()).ThenReturn(true);
            Org.Mockito.Mockito.When(scmClient.Notify(Matchers.IsA <SCMUploaderNotifyRequest>(
                                                          ))).ThenReturn(response);
            FileSystem fs = Org.Mockito.Mockito.Mock <FileSystem>();

            // return false when rename is called
            Org.Mockito.Mockito.When(fs.Rename(Matchers.IsA <Path>(), Matchers.IsA <Path>())).ThenReturn
                (true);
            FileSystem          localFs = FileSystem.GetLocal(conf);
            SharedCacheUploader spied   = CreateSpiedUploader(resource, localPath, user, conf,
                                                              scmClient, fs, localFs);

            // stub verifyAccess() to return true
            Org.Mockito.Mockito.DoReturn(true).When(spied).VerifyAccess();
            // stub getActualPath()
            Org.Mockito.Mockito.DoReturn(localPath).When(spied).GetActualPath();
            // stub computeChecksum()
            Org.Mockito.Mockito.DoReturn("abcdef0123456789").When(spied).ComputeChecksum(Matchers.IsA
                                                                                         <Path>());
            // stub uploadFile() to return true
            Org.Mockito.Mockito.DoReturn(true).When(spied).UploadFile(Matchers.IsA <Path>(), Matchers.IsA
                                                                      <Path>());
            // stub notifySharedCacheManager to return true
            Org.Mockito.Mockito.DoReturn(true).When(spied).NotifySharedCacheManager(Matchers.IsA
                                                                                    <string>(), Matchers.IsA <string>());
            NUnit.Framework.Assert.IsTrue(spied.Call());
        }
        /// <exception cref="Com.Google.Protobuf.ServiceException"/>
        public virtual YarnServerCommonServiceProtos.SCMUploaderNotifyResponseProto Notify
            (RpcController controller, YarnServerCommonServiceProtos.SCMUploaderNotifyRequestProto
            proto)
        {
            SCMUploaderNotifyRequestPBImpl request = new SCMUploaderNotifyRequestPBImpl(proto
                                                                                        );

            try
            {
                SCMUploaderNotifyResponse response = real.Notify(request);
                return(((SCMUploaderNotifyResponsePBImpl)response).GetProto());
            }
            catch (YarnException e)
            {
                throw new ServiceException(e);
            }
            catch (IOException e)
            {
                throw new ServiceException(e);
            }
        }