Modified: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/event/LocalizerEvent.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/event/LocalizerEvent.java?rev=1097727&r1=1097726&r2=1097727&view=diff
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/event/LocalizerEvent.java (original)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/event/LocalizerEvent.java Fri Apr 29 08:35:53 2011
@@ -15,16 +15,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event;
import org.apache.hadoop.yarn.event.AbstractEvent;
-import org.apache.hadoop.yarn.event.Event;
-public abstract class LocalizerEvent extends AbstractEvent<LocalizerEventType> {
+public class LocalizerEvent extends AbstractEvent<LocalizerEventType> {
+
+ private final String localizerId;
+
+ public LocalizerEvent(LocalizerEventType type, String localizerId) {
+ super(type);
+ this.localizerId = localizerId;
+ }
- public LocalizerEvent(LocalizerEventType event) {
- super(event);
+ public String getLocalizerId() {
+ return localizerId;
}
}
Modified: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/event/LocalizerEventType.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/event/LocalizerEventType.java?rev=1097727&r1=1097726&r2=1097727&view=diff
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/event/LocalizerEventType.java (original)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/event/LocalizerEventType.java Fri Apr 29 08:35:53 2011
@@ -15,11 +15,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event;
public enum LocalizerEventType {
- INIT_APPLICATION_RESOURCES,
- CLEANUP_CONTAINER_RESOURCES,
- DESTROY_APPLICATION_RESOURCES,
+ REQUEST_RESOURCE_LOCALIZATION,
+ ABORT_LOCALIZATION
}
Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/event/LocalizerResourceRequestEvent.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/event/LocalizerResourceRequestEvent.java?rev=1097727&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/event/LocalizerResourceRequestEvent.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/event/LocalizerResourceRequestEvent.java Fri Apr 29 08:35:53 2011
@@ -0,0 +1,52 @@
+/**
+* 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.hadoop.yarn.server.nodemanager.containermanager.localizer.event;
+
+import org.apache.hadoop.yarn.api.records.LocalResourceVisibility;
+import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.LocalizedResource;
+import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.LocalizerContext;
+import org.apache.hadoop.yarn.util.ConverterUtils;
+
+public class LocalizerResourceRequestEvent extends LocalizerEvent {
+
+ private final LocalizerContext context;
+ private final LocalizedResource resource;
+ private final LocalResourceVisibility vis;
+
+ public LocalizerResourceRequestEvent(LocalizedResource resource,
+ LocalResourceVisibility vis, LocalizerContext context) {
+ super(LocalizerEventType.REQUEST_RESOURCE_LOCALIZATION,
+ ConverterUtils.toString(context.getContainer()));
+ this.vis = vis;
+ this.context = context;
+ this.resource = resource;
+ }
+
+ public LocalizedResource getResource() {
+ return resource;
+ }
+
+ public LocalizerContext getContext() {
+ return context;
+ }
+
+ public LocalResourceVisibility getVisibility() {
+ return vis;
+ }
+
+}
Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/event/ResourceEvent.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/event/ResourceEvent.java?rev=1097727&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/event/ResourceEvent.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/event/ResourceEvent.java Fri Apr 29 08:35:53 2011
@@ -0,0 +1,36 @@
+/**
+* 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.hadoop.yarn.server.nodemanager.containermanager.localizer.event;
+
+import org.apache.hadoop.yarn.event.AbstractEvent;
+import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.LocalResourceRequest;
+
+public class ResourceEvent extends AbstractEvent<ResourceEventType> {
+
+ private final LocalResourceRequest rsrc;
+
+ public ResourceEvent(LocalResourceRequest rsrc, ResourceEventType type) {
+ super(type);
+ this.rsrc = rsrc;
+ }
+
+ public LocalResourceRequest getLocalResource() {
+ return rsrc;
+ }
+
+}
Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/event/ResourceEventType.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/event/ResourceEventType.java?rev=1097727&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/event/ResourceEventType.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/event/ResourceEventType.java Fri Apr 29 08:35:53 2011
@@ -0,0 +1,24 @@
+/**
+* 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.hadoop.yarn.server.nodemanager.containermanager.localizer.event;
+
+public enum ResourceEventType {
+ REQUEST,
+ LOCALIZED,
+ RELEASE
+}
Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/event/ResourceLocalizedEvent.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/event/ResourceLocalizedEvent.java?rev=1097727&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/event/ResourceLocalizedEvent.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/event/ResourceLocalizedEvent.java Fri Apr 29 08:35:53 2011
@@ -0,0 +1,43 @@
+/**
+* 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.hadoop.yarn.server.nodemanager.containermanager.localizer.event;
+
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.LocalResourceRequest;
+
+public class ResourceLocalizedEvent extends ResourceEvent {
+
+ private final long size;
+ private final Path location;
+
+ public ResourceLocalizedEvent(LocalResourceRequest rsrc, Path location,
+ long size) {
+ super(rsrc, ResourceEventType.LOCALIZED);
+ this.size = size;
+ this.location = location;
+ }
+
+ public Path getLocation() {
+ return location;
+ }
+
+ public long getSize() {
+ return size;
+ }
+
+}
Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/event/ResourceReleaseEvent.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/event/ResourceReleaseEvent.java?rev=1097727&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/event/ResourceReleaseEvent.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/event/ResourceReleaseEvent.java Fri Apr 29 08:35:53 2011
@@ -0,0 +1,39 @@
+/**
+* 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.hadoop.yarn.server.nodemanager.containermanager.localizer.event;
+
+import java.net.URISyntaxException;
+
+import org.apache.hadoop.yarn.api.records.ContainerId;
+import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.LocalResourceRequest;
+
+public class ResourceReleaseEvent extends ResourceEvent {
+
+ private final ContainerId container;
+
+ public ResourceReleaseEvent(LocalResourceRequest rsrc, ContainerId container)
+ throws URISyntaxException {
+ super(rsrc, ResourceEventType.RELEASE);
+ this.container = container;
+ }
+
+ public ContainerId getContainer() {
+ return container;
+ }
+
+}
Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/event/ResourceRequestEvent.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/event/ResourceRequestEvent.java?rev=1097727&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/event/ResourceRequestEvent.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/event/ResourceRequestEvent.java Fri Apr 29 08:35:53 2011
@@ -0,0 +1,44 @@
+/**
+* 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.hadoop.yarn.server.nodemanager.containermanager.localizer.event;
+
+import org.apache.hadoop.yarn.api.records.LocalResourceVisibility;
+import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.LocalResourceRequest;
+import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.LocalizerContext;
+
+public class ResourceRequestEvent extends ResourceEvent {
+
+ private final LocalizerContext context;
+ private final LocalResourceVisibility vis;
+
+ public ResourceRequestEvent(LocalResourceRequest resource,
+ LocalResourceVisibility vis, LocalizerContext context) {
+ super(resource, ResourceEventType.REQUEST);
+ this.vis = vis;
+ this.context = context;
+ }
+
+ public LocalizerContext getContext() {
+ return context;
+ }
+
+ public LocalResourceVisibility getVisibility() {
+ return vis;
+ }
+
+}
Modified: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/webapp/ContainerLogsPage.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/webapp/ContainerLogsPage.java?rev=1097727&r1=1097726&r2=1097727&view=diff
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/webapp/ContainerLogsPage.java (original)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/webapp/ContainerLogsPage.java Fri Apr 29 08:35:53 2011
@@ -34,7 +34,7 @@ import org.apache.hadoop.yarn.factory.pr
import org.apache.hadoop.yarn.server.nodemanager.Context;
import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container;
import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerState;
-import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.ApplicationLocalizer;
+import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.ContainerLocalizer;
import org.apache.hadoop.yarn.util.ConverterUtils;
import org.apache.hadoop.yarn.webapp.SubView;
import org.apache.hadoop.yarn.webapp.hamlet.Hamlet;
@@ -158,11 +158,11 @@ public class ContainerLogsPage extends N
conf.getStrings(NM_LOCAL_DIR, DEFAULT_NM_LOCAL_DIR);
File localDir = new File(sLocalDirs[0]); // TODO: Fix
File userCacheDir =
- new File(localDir, ApplicationLocalizer.USERCACHE);
+ new File(localDir, ContainerLocalizer.USERCACHE);
String user =
nmContext.getContainers().get(containerId).getUser();
File userDir = new File(userCacheDir, user);
- File appCacheDir = new File(userDir, ApplicationLocalizer.APPCACHE);
+ File appCacheDir = new File(userDir, ContainerLocalizer.APPCACHE);
File containerDir =
new File(new File(appCacheDir,
ConverterUtils.toString(containerId
Modified: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/proto/LocalizationProtocol.proto
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/proto/LocalizationProtocol.proto?rev=1097727&r1=1097726&r2=1097727&view=diff
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/proto/LocalizationProtocol.proto (original)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/proto/LocalizationProtocol.proto Fri Apr 29 08:35:53 2011
@@ -5,8 +5,6 @@ option java_generate_equals_and_hash = t
import "yarn_server_nodemanager_service_protos.proto";
-
service LocalizationProtocolService {
- rpc successfulLocalization(SuccessfulLocalizationRequestProto) returns (SuccessfulLocalizationResponseProto);
- rpc failedLocalization(FailedLocalizationRequestProto) returns (FailedLocalizationResponseProto);
+ rpc heartbeat(LocalizerStatusProto) returns (LocalizerHeartbeatResponseProto);
}
Modified: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/proto/yarn_server_nodemanager_service_protos.proto
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/proto/yarn_server_nodemanager_service_protos.proto?rev=1097727&r1=1097726&r2=1097727&view=diff
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/proto/yarn_server_nodemanager_service_protos.proto (original)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/main/proto/yarn_server_nodemanager_service_protos.proto Fri Apr 29 08:35:53 2011
@@ -5,18 +5,31 @@ option java_generate_equals_and_hash = t
import "yarn_protos.proto";
-message SuccessfulLocalizationRequestProto {
- optional string user = 1;
- optional LocalResourceProto resource = 2;
- optional URLProto path = 3;
+enum ResourceStatusTypeProto {
+ FETCH_PENDING = 1;
+ FETCH_SUCCESS = 2;
+ FETCH_FAILURE = 3;
}
-message SuccessfulLocalizationResponseProto {
+
+message LocalResourceStatusProto {
+ optional LocalResourceProto resource = 1;
+ optional ResourceStatusTypeProto status = 2;
+ optional URLProto localPath = 3;
+ optional int64 localSize = 4;
+ optional YarnRemoteExceptionProto exception = 5;
+}
+
+message LocalizerStatusProto {
+ optional string localizer_id = 1;
+ repeated LocalResourceStatusProto resources = 2;
}
-message FailedLocalizationRequestProto {
- optional string user = 1;
- optional LocalResourceProto resource = 2;
- optional YarnRemoteExceptionProto exception =3;
+enum LocalizerActionProto {
+ LIVE = 1;
+ DIE = 2;
}
-message FailedLocalizationResponseProto {
+
+message LocalizerHeartbeatResponseProto {
+ optional LocalizerActionProto action = 1;
+ repeated LocalResourceProto resources = 2;
}
Modified: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/DummyContainerManager.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/DummyContainerManager.java?rev=1097727&r1=1097726&r2=1097727&view=diff
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/DummyContainerManager.java (original)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/DummyContainerManager.java Fri Apr 29 08:35:53 2011
@@ -18,7 +18,10 @@
package org.apache.hadoop.yarn.server.nodemanager;
-import java.util.HashMap;
+import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerResourceLocalizedEvent;
+import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.LocalResourceRequest;
+import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.ContainerLocalizationRequestEvent;
+import org.apache.hadoop.yarn.util.ConverterUtils;
import junit.framework.Assert;
@@ -45,9 +48,11 @@ import org.apache.hadoop.yarn.server.nod
import org.apache.hadoop.yarn.server.nodemanager.containermanager.launcher.ContainersLauncher;
import org.apache.hadoop.yarn.server.nodemanager.containermanager.launcher.ContainersLauncherEvent;
import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.ResourceLocalizationService;
-import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.ApplicationLocalizerEvent;
-import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.ContainerLocalizerEvent;
-import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.LocalizerEvent;
+import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.ApplicationLocalizationEvent;
+import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.ContainerLocalizationEvent;
+import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.LocalizationEvent;
+
+import static org.junit.Assert.*;
public class DummyContainerManager extends ContainerManagerImpl {
@@ -66,19 +71,31 @@ public class DummyContainerManager exten
DeletionService deletionContext) {
return new ResourceLocalizationService(super.dispatcher, exec, deletionContext) {
@Override
- public void handle(LocalizerEvent event) {
+ public void handle(LocalizationEvent event) {
switch (event.getType()) {
case INIT_APPLICATION_RESOURCES:
Application app =
- ((ApplicationLocalizerEvent) event).getApplication();
+ ((ApplicationLocalizationEvent) event).getApplication();
// Simulate event from ApplicationLocalization.
- this.dispatcher.getEventHandler().handle(
- new ApplicationInitedEvent(app.getAppId(),
- new HashMap<Path, String>(), new Path("workDir")));
+ dispatcher.getEventHandler().handle(new ApplicationInitedEvent(
+ app.getAppId(), new Path("logdir")));
+ break;
+ case INIT_CONTAINER_RESOURCES:
+ ContainerLocalizationRequestEvent rsrcReqs =
+ (ContainerLocalizationRequestEvent) event;
+ // simulate localization of all requested resources
+ for (LocalResourceRequest req : rsrcReqs.getRequestedResources()) {
+ LOG.info("DEBUG: " + req + ":" +
+ rsrcReqs.getContainer().getContainerID());
+ dispatcher.getEventHandler().handle(
+ new ContainerResourceLocalizedEvent(
+ rsrcReqs.getContainer().getContainerID(), req,
+ new Path("file:///local" + req.getPath().toUri().getPath())));
+ }
break;
case CLEANUP_CONTAINER_RESOURCES:
Container container =
- ((ContainerLocalizerEvent) event).getContainer();
+ ((ContainerLocalizationEvent) event).getContainer();
// TODO: delete the container dir
this.dispatcher.getEventHandler().handle(
new ContainerEvent(container.getContainerID(),
@@ -86,7 +103,7 @@ public class DummyContainerManager exten
break;
case DESTROY_APPLICATION_RESOURCES:
Application application =
- ((ApplicationLocalizerEvent) event).getApplication();
+ ((ApplicationLocalizationEvent) event).getApplication();
// decrement reference counts of all resources associated with this
// app
@@ -94,6 +111,8 @@ public class DummyContainerManager exten
new ApplicationEvent(application.getAppId(),
ApplicationEventType.APPLICATION_RESOURCES_CLEANEDUP));
break;
+ default:
+ fail("Unexpected event: " + event.getType());
}
}
};
@@ -140,7 +159,9 @@ public class DummyContainerManager exten
while (!containerStatus.getState().equals(finalState)
&& timeoutSecs++ < timeOutMax) {
Thread.sleep(1000);
- LOG.info("Waiting for container to get into state " + finalState
+ LOG.info("Waiting for container " +
+ ConverterUtils.toString(containerID) +
+ " to get into state " + finalState
+ ". Current state is " + containerStatus.getState());
containerStatus = containerManager.getContainerStatus(request).getStatus();
}
Modified: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestDefaultContainerExecutor.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestDefaultContainerExecutor.java?rev=1097727&r1=1097726&r2=1097727&view=diff
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestDefaultContainerExecutor.java (original)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestDefaultContainerExecutor.java Fri Apr 29 08:35:53 2011
@@ -38,7 +38,6 @@ import org.apache.hadoop.fs.permission.F
import org.apache.hadoop.io.DataInputBuffer;
import org.apache.hadoop.io.DataOutputBuffer;
import org.apache.hadoop.util.Progressable;
-import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.ApplicationLocalizer;
import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.FakeFSDataInputStream;
import static org.apache.hadoop.fs.CreateFlag.*;
@@ -216,17 +215,4 @@ public class TestDefaultContainerExecuto
// new FsPermission(ApplicationLocalizer.LOGDIR_PERM), true);
// }
- @Test
- public void testLaunch() throws Exception {
- }
-
- @Test
- public void testSignal() throws Exception {
- }
-
- @Test
- public void testDelete() throws Exception {
- // TestDeletionService covers?
- }
-
}
Modified: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestRPCFactories.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestRPCFactories.java?rev=1097727&r1=1097726&r2=1097727&view=diff
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestRPCFactories.java (original)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestRPCFactories.java Fri Apr 29 08:35:53 2011
@@ -1,21 +1,36 @@
+/**
+* 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.hadoop.yarn.server.nodemanager;
import java.net.InetSocketAddress;
+import org.apache.hadoop.yarn.server.nodemanager.api.protocolrecords.LocalizerHeartbeatResponse;
+import org.apache.hadoop.yarn.server.nodemanager.api.protocolrecords.LocalizerStatus;
+
import junit.framework.Assert;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.ipc.Server;
import org.apache.hadoop.net.NetUtils;
import org.apache.hadoop.yarn.YarnException;
-import org.apache.hadoop.yarn.exceptions.YarnRemoteException;
import org.apache.hadoop.yarn.factories.impl.pb.RpcClientFactoryPBImpl;
import org.apache.hadoop.yarn.factories.impl.pb.RpcServerFactoryPBImpl;
import org.apache.hadoop.yarn.server.nodemanager.api.LocalizationProtocol;
-import org.apache.hadoop.yarn.server.nodemanager.api.protocolrecords.FailedLocalizationRequest;
-import org.apache.hadoop.yarn.server.nodemanager.api.protocolrecords.FailedLocalizationResponse;
-import org.apache.hadoop.yarn.server.nodemanager.api.protocolrecords.SuccessfulLocalizationRequest;
-import org.apache.hadoop.yarn.server.nodemanager.api.protocolrecords.SuccessfulLocalizationResponse;
import org.junit.Test;
public class TestRPCFactories {
@@ -43,7 +58,9 @@ public class TestRPCFactories {
e.printStackTrace();
Assert.fail("Failed to create server");
} finally {
- server.stop();
+ if (server != null) {
+ server.stop();
+ }
}
}
@@ -60,9 +77,12 @@ public class TestRPCFactories {
System.err.println(server.getListenerAddress());
System.err.println(NetUtils.getConnectAddress(server));
- LocalizationProtocol client = null;
try {
- client = (LocalizationProtocol) RpcClientFactoryPBImpl.get().getClient(LocalizationProtocol.class, 1, NetUtils.getConnectAddress(server), conf);
+ LocalizationProtocol client = (LocalizationProtocol)
+ RpcClientFactoryPBImpl.get().getClient(
+ LocalizationProtocol.class, 1,
+ NetUtils.getConnectAddress(server), conf);
+ Assert.assertNotNull(client);
} catch (YarnException e) {
e.printStackTrace();
Assert.fail("Failed to create client");
@@ -79,16 +99,7 @@ public class TestRPCFactories {
public class LocalizationProtocolTestImpl implements LocalizationProtocol {
@Override
- public SuccessfulLocalizationResponse successfulLocalization(
- SuccessfulLocalizationRequest request) throws YarnRemoteException {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public FailedLocalizationResponse failedLocalization(
- FailedLocalizationRequest request) throws YarnRemoteException {
- // TODO Auto-generated method stub
+ public LocalizerHeartbeatResponse heartbeat(LocalizerStatus status) {
return null;
}
Modified: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestRecordFactory.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestRecordFactory.java?rev=1097727&r1=1097726&r2=1097727&view=diff
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestRecordFactory.java (original)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestRecordFactory.java Fri Apr 29 08:35:53 2011
@@ -1,13 +1,30 @@
+/**
+* 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.hadoop.yarn.server.nodemanager;
-import junit.framework.Assert;
-
import org.apache.hadoop.yarn.YarnException;
import org.apache.hadoop.yarn.factories.RecordFactory;
import org.apache.hadoop.yarn.factories.impl.pb.RecordFactoryPBImpl;
-import org.apache.hadoop.yarn.server.nodemanager.api.protocolrecords.FailedLocalizationRequest;
-import org.apache.hadoop.yarn.server.nodemanager.api.protocolrecords.impl.pb.FailedLocalizationRequestPBImpl;
+import org.apache.hadoop.yarn.server.nodemanager.api.protocolrecords.LocalizerHeartbeatResponse;
+import org.apache.hadoop.yarn.server.nodemanager.api.protocolrecords.impl.pb.LocalizerHeartbeatResponsePBImpl;
+
import org.junit.Test;
+import junit.framework.Assert;
public class TestRecordFactory {
@@ -16,8 +33,10 @@ public class TestRecordFactory {
RecordFactory pbRecordFactory = RecordFactoryPBImpl.get();
try {
- FailedLocalizationRequest response = pbRecordFactory.newRecordInstance(FailedLocalizationRequest.class);
- Assert.assertEquals(FailedLocalizationRequestPBImpl.class, response.getClass());
+ LocalizerHeartbeatResponse response = pbRecordFactory.newRecordInstance(
+ LocalizerHeartbeatResponse.class);
+ Assert.assertEquals(LocalizerHeartbeatResponsePBImpl.class,
+ response.getClass());
} catch (YarnException e) {
e.printStackTrace();
Assert.fail("Failed to crete record");
Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/api/protocolrecords/impl/pb/TestPBLocalizerRPC.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/api/protocolrecords/impl/pb/TestPBLocalizerRPC.java?rev=1097727&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/api/protocolrecords/impl/pb/TestPBLocalizerRPC.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/api/protocolrecords/impl/pb/TestPBLocalizerRPC.java Fri Apr 29 08:35:53 2011
@@ -0,0 +1,83 @@
+package org.apache.hadoop.yarn.server.nodemanager.api.protocolrecords.impl.pb;
+
+import java.net.InetSocketAddress;
+
+import org.apache.avro.ipc.Server;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.yarn.factories.RecordFactory;
+import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider;
+import org.apache.hadoop.yarn.ipc.YarnRPC;
+import org.apache.hadoop.yarn.server.nodemanager.api.LocalizationProtocol;
+import org.apache.hadoop.yarn.server.nodemanager.api.protocolrecords.LocalizerAction;
+import org.apache.hadoop.yarn.server.nodemanager.api.protocolrecords.LocalizerHeartbeatResponse;
+import org.apache.hadoop.yarn.server.nodemanager.api.protocolrecords.LocalizerStatus;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class TestPBLocalizerRPC {
+
+ static final RecordFactory recordFactory = createPBRecordFactory();
+
+ static RecordFactory createPBRecordFactory() {
+ Configuration conf = new Configuration();
+ conf.set(RecordFactoryProvider.RPC_SERIALIZER_KEY, "protocolbuffers");
+ return RecordFactoryProvider.getRecordFactory(conf);
+ }
+
+ static class LocalizerService implements LocalizationProtocol {
+ private final InetSocketAddress locAddr;
+ private Server server;
+ LocalizerService(InetSocketAddress locAddr) {
+ this.locAddr = locAddr;
+ }
+
+ public void start() {
+ Configuration conf = new Configuration();
+ YarnRPC rpc = YarnRPC.create(conf);
+ server = rpc.getServer(
+ LocalizationProtocol.class, this, locAddr, conf, null);
+ server.start();
+ }
+
+ public void stop() {
+ if (server != null) {
+ server.close();
+ }
+ }
+
+ @Override
+ public LocalizerHeartbeatResponse heartbeat(LocalizerStatus status) {
+ return dieHBResponse();
+ }
+ }
+
+ static LocalizerHeartbeatResponse dieHBResponse() {
+ LocalizerHeartbeatResponse response =
+ recordFactory.newRecordInstance(LocalizerHeartbeatResponse.class);
+ response.setLocalizerAction(LocalizerAction.DIE);
+ return response;
+ }
+
+ @Test
+ public void testLocalizerRPC() throws Exception {
+ InetSocketAddress locAddr = new InetSocketAddress("0.0.0.0", 4344);
+ LocalizerService server = new LocalizerService(locAddr);
+ try {
+ server.start();
+ Configuration conf = new Configuration();
+ YarnRPC rpc = YarnRPC.create(conf);
+ LocalizationProtocol client = (LocalizationProtocol)
+ rpc.getProxy(LocalizationProtocol.class, locAddr, conf);
+ LocalizerStatus status =
+ recordFactory.newRecordInstance(LocalizerStatus.class);
+ status.setLocalizerId("localizer0");
+ LocalizerHeartbeatResponse response = client.heartbeat(status);
+ assertEquals(dieHBResponse(), response);
+ } finally {
+ server.stop();
+ }
+ assertTrue(true);
+ }
+
+}
Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/api/protocolrecords/impl/pb/TestPBRecordImpl.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/api/protocolrecords/impl/pb/TestPBRecordImpl.java?rev=1097727&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/api/protocolrecords/impl/pb/TestPBRecordImpl.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/api/protocolrecords/impl/pb/TestPBRecordImpl.java Fri Apr 29 08:35:53 2011
@@ -0,0 +1,164 @@
+/**
+* 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.hadoop.yarn.server.nodemanager.api.protocolrecords.impl.pb;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.io.DataInputBuffer;
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.apache.hadoop.yarn.api.records.LocalResource;
+import org.apache.hadoop.yarn.api.records.LocalResourceVisibility;
+import org.apache.hadoop.yarn.api.records.impl.pb.LocalResourcePBImpl;
+import org.apache.hadoop.yarn.factories.RecordFactory;
+import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider;
+import org.apache.hadoop.yarn.ipc.RPCUtil;
+import org.apache.hadoop.yarn.proto.YarnServerNodemanagerServiceProtos.LocalResourceStatusProto;
+import org.apache.hadoop.yarn.proto.YarnServerNodemanagerServiceProtos.LocalizerHeartbeatResponseProto;
+import org.apache.hadoop.yarn.proto.YarnServerNodemanagerServiceProtos.LocalizerStatusProto;
+import org.apache.hadoop.yarn.server.nodemanager.api.protocolrecords.LocalResourceStatus;
+import org.apache.hadoop.yarn.server.nodemanager.api.protocolrecords.LocalizerAction;
+import org.apache.hadoop.yarn.server.nodemanager.api.protocolrecords.LocalizerHeartbeatResponse;
+import org.apache.hadoop.yarn.server.nodemanager.api.protocolrecords.LocalizerStatus;
+import org.apache.hadoop.yarn.server.nodemanager.api.protocolrecords.ResourceStatusType;
+import org.apache.hadoop.yarn.util.ConverterUtils;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class TestPBRecordImpl {
+
+ static final RecordFactory recordFactory = createPBRecordFactory();
+
+ static RecordFactory createPBRecordFactory() {
+ Configuration conf = new Configuration();
+ conf.set(RecordFactoryProvider.RPC_SERIALIZER_KEY, "protocolbuffers");
+ return RecordFactoryProvider.getRecordFactory(conf);
+ }
+
+ static LocalResource createResource() {
+ LocalResource ret = recordFactory.newRecordInstance(LocalResource.class);
+ assertTrue(ret instanceof LocalResourcePBImpl);
+ ret.setResource(
+ ConverterUtils.getYarnUrlFromPath(
+ new Path("hdfs://y.ak:8020/foo/bar")));
+ ret.setSize(4344L);
+ ret.setTimestamp(3141592653589793L);
+ ret.setVisibility(LocalResourceVisibility.PUBLIC);
+ return ret;
+ }
+
+ static LocalResourceStatus createLocalResourceStatus() {
+ LocalResourceStatus ret =
+ recordFactory.newRecordInstance(LocalResourceStatus.class);
+ assertTrue(ret instanceof LocalResourceStatusPBImpl);
+ ret.setResource(createResource());
+ ret.setLocalPath(
+ ConverterUtils.getYarnUrlFromPath(
+ new Path("file:///local/foo/bar")));
+ ret.setStatus(ResourceStatusType.FETCH_SUCCESS);
+ ret.setLocalSize(4443L);
+ Exception e = new Exception("Dingos.");
+ e.setStackTrace(new StackTraceElement[] {
+ new StackTraceElement("foo", "bar", "baz", 10),
+ new StackTraceElement("sbb", "one", "onm", 10) });
+ ret.setException(RPCUtil.getRemoteException(e));
+ return ret;
+ }
+
+ static LocalizerStatus createLocalizerStatus() {
+ LocalizerStatus ret =
+ recordFactory.newRecordInstance(LocalizerStatus.class);
+ assertTrue(ret instanceof LocalizerStatusPBImpl);
+ ret.setLocalizerId("localizer0");
+ ret.addResourceStatus(createLocalResourceStatus());
+ return ret;
+ }
+
+ static LocalizerHeartbeatResponse createLocalizerHeartbeatResponse() {
+ LocalizerHeartbeatResponse ret =
+ recordFactory.newRecordInstance(LocalizerHeartbeatResponse.class);
+ assertTrue(ret instanceof LocalizerHeartbeatResponsePBImpl);
+ ret.setLocalizerAction(LocalizerAction.LIVE);
+ ret.addResource(createResource());
+ return ret;
+ }
+
+ @Test
+ public void testLocalResourceStatusSerDe() throws Exception {
+ LocalResourceStatus rsrcS = createLocalResourceStatus();
+ assertTrue(rsrcS instanceof LocalResourceStatusPBImpl);
+ LocalResourceStatusPBImpl rsrcPb = (LocalResourceStatusPBImpl) rsrcS;
+ DataOutputBuffer out = new DataOutputBuffer();
+ rsrcPb.getProto().writeDelimitedTo(out);
+ DataInputBuffer in = new DataInputBuffer();
+ in.reset(out.getData(), 0, out.getLength());
+ LocalResourceStatusProto rsrcPbD =
+ LocalResourceStatusProto.parseDelimitedFrom(in);
+ assertNotNull(rsrcPbD);
+ LocalResourceStatus rsrcD =
+ new LocalResourceStatusPBImpl(rsrcPbD);
+
+ assertEquals(rsrcS, rsrcD);
+ assertEquals(createResource(), rsrcS.getResource());
+ assertEquals(createResource(), rsrcD.getResource());
+ }
+
+ @Test
+ public void testLocalizerStatusSerDe() throws Exception {
+ LocalizerStatus rsrcS = createLocalizerStatus();
+ assertTrue(rsrcS instanceof LocalizerStatusPBImpl);
+ LocalizerStatusPBImpl rsrcPb = (LocalizerStatusPBImpl) rsrcS;
+ DataOutputBuffer out = new DataOutputBuffer();
+ rsrcPb.getProto().writeDelimitedTo(out);
+ DataInputBuffer in = new DataInputBuffer();
+ in.reset(out.getData(), 0, out.getLength());
+ LocalizerStatusProto rsrcPbD =
+ LocalizerStatusProto.parseDelimitedFrom(in);
+ assertNotNull(rsrcPbD);
+ LocalizerStatus rsrcD =
+ new LocalizerStatusPBImpl(rsrcPbD);
+
+ assertEquals(rsrcS, rsrcD);
+ assertEquals("localizer0", rsrcS.getLocalizerId());
+ assertEquals("localizer0", rsrcD.getLocalizerId());
+ assertEquals(createLocalResourceStatus(), rsrcS.getResourceStatus(0));
+ assertEquals(createLocalResourceStatus(), rsrcD.getResourceStatus(0));
+ }
+
+ @Test
+ public void testLocalizerHeartbeatResponseSerDe() throws Exception {
+ LocalizerHeartbeatResponse rsrcS = createLocalizerHeartbeatResponse();
+ assertTrue(rsrcS instanceof LocalizerHeartbeatResponsePBImpl);
+ LocalizerHeartbeatResponsePBImpl rsrcPb =
+ (LocalizerHeartbeatResponsePBImpl) rsrcS;
+ DataOutputBuffer out = new DataOutputBuffer();
+ rsrcPb.getProto().writeDelimitedTo(out);
+ DataInputBuffer in = new DataInputBuffer();
+ in.reset(out.getData(), 0, out.getLength());
+ LocalizerHeartbeatResponseProto rsrcPbD =
+ LocalizerHeartbeatResponseProto.parseDelimitedFrom(in);
+ assertNotNull(rsrcPbD);
+ LocalizerHeartbeatResponse rsrcD =
+ new LocalizerHeartbeatResponsePBImpl(rsrcPbD);
+
+ assertEquals(rsrcS, rsrcD);
+ assertEquals(createResource(), rsrcS.getLocalResource(0));
+ assertEquals(createResource(), rsrcD.getLocalResource(0));
+ }
+
+}
Modified: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/TestContainerManager.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/TestContainerManager.java?rev=1097727&r1=1097726&r2=1097727&view=diff
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/TestContainerManager.java (original)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/TestContainerManager.java Fri Apr 29 08:35:53 2011
@@ -29,6 +29,7 @@ import junit.framework.Assert;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
import org.apache.hadoop.NodeHealthCheckerService;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileContext;
@@ -56,9 +57,9 @@ import org.apache.hadoop.yarn.factories.
import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider;
import org.apache.hadoop.yarn.server.api.ResourceTracker;
import org.apache.hadoop.yarn.server.nodemanager.CMgrCompletedAppsEvent;
-import org.apache.hadoop.yarn.server.nodemanager.ContainerExecutor;
import org.apache.hadoop.yarn.server.nodemanager.ContainerExecutor.ExitCode;
import org.apache.hadoop.yarn.server.nodemanager.ContainerExecutor.Signal;
+import org.apache.hadoop.yarn.server.nodemanager.ContainerExecutor;
import org.apache.hadoop.yarn.server.nodemanager.Context;
import org.apache.hadoop.yarn.server.nodemanager.DefaultContainerExecutor;
import org.apache.hadoop.yarn.server.nodemanager.DeletionService;
@@ -70,10 +71,11 @@ import org.apache.hadoop.yarn.server.nod
import org.apache.hadoop.yarn.server.nodemanager.NodeStatusUpdaterImpl;
import org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application;
import org.apache.hadoop.yarn.server.nodemanager.containermanager.application.ApplicationState;
-import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.ApplicationLocalizer;
+import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.ContainerLocalizer;
import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.ResourceLocalizationService;
import org.apache.hadoop.yarn.service.Service.STATE;
import org.apache.hadoop.yarn.util.ConverterUtils;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -240,9 +242,9 @@ public class TestContainerManager {
// TODO: Don't we need clusterStamp in localDir?
String appIDStr = ConverterUtils.toString(appId);
String containerIDStr = ConverterUtils.toString(cId);
- File userCacheDir = new File(localDir, ApplicationLocalizer.USERCACHE);
+ File userCacheDir = new File(localDir, ContainerLocalizer.USERCACHE);
File userDir = new File(userCacheDir, user);
- File appCache = new File(userDir, ApplicationLocalizer.APPCACHE);
+ File appCache = new File(userDir, ContainerLocalizer.APPCACHE);
File appDir = new File(appCache, appIDStr);
File containerDir = new File(appDir, containerIDStr);
File targetFile = new File(containerDir, destinationFile);
@@ -425,9 +427,9 @@ public class TestContainerManager {
// Now ascertain that the resources are localised correctly.
String appIDStr = ConverterUtils.toString(appId);
String containerIDStr = ConverterUtils.toString(cId);
- File userCacheDir = new File(localDir, ApplicationLocalizer.USERCACHE);
+ File userCacheDir = new File(localDir, ContainerLocalizer.USERCACHE);
File userDir = new File(userCacheDir, user);
- File appCache = new File(userDir, ApplicationLocalizer.APPCACHE);
+ File appCache = new File(userDir, ContainerLocalizer.APPCACHE);
File appDir = new File(appCache, appIDStr);
File containerDir = new File(appDir, containerIDStr);
File targetFile = new File(containerDir, destinationFile);
Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/container/TestContainer.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/container/TestContainer.java?rev=1097727&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/container/TestContainer.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/container/TestContainer.java Fri Apr 29 08:35:53 2011
@@ -0,0 +1,334 @@
+/**
+* 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.hadoop.yarn.server.nodemanager.containermanager.container;
+
+import java.net.URISyntaxException;
+
+import java.nio.ByteBuffer;
+
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Random;
+import java.util.Map.Entry;
+import java.util.AbstractMap.SimpleEntry;
+
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.yarn.api.records.ApplicationId;
+import org.apache.hadoop.yarn.api.records.ContainerId;
+import org.apache.hadoop.yarn.api.records.ContainerLaunchContext;
+import org.apache.hadoop.yarn.api.records.LocalResource;
+import org.apache.hadoop.yarn.api.records.LocalResourceType;
+import org.apache.hadoop.yarn.api.records.LocalResourceVisibility;
+import org.apache.hadoop.yarn.api.records.URL;
+import org.apache.hadoop.yarn.event.DrainDispatcher;
+import org.apache.hadoop.yarn.event.EventHandler;
+import org.apache.hadoop.yarn.server.nodemanager.containermanager.AuxServicesEvent;
+import org.apache.hadoop.yarn.server.nodemanager.containermanager.AuxServicesEventType;
+import org.apache.hadoop.yarn.server.nodemanager.containermanager.launcher.ContainersLauncherEvent;
+import org.apache.hadoop.yarn.server.nodemanager.containermanager.launcher.ContainersLauncherEventType;
+import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.LocalResourceRequest;
+import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.LocalizationEvent;
+import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.LocalizationEventType;
+import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.event.ContainerLocalizationRequestEvent;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+import org.mockito.ArgumentMatcher;
+import static org.mockito.Mockito.*;
+
+public class TestContainer {
+
+ /**
+ * Verify correct container request events sent to localizer.
+ */
+ @Test
+ @SuppressWarnings("unchecked") // mocked generic
+ public void testLocalizationRequest() throws Exception {
+ DrainDispatcher dispatcher = new DrainDispatcher();
+ dispatcher.init(null);
+ try {
+ dispatcher.start();
+ EventHandler<LocalizationEvent> localizerBus = mock(EventHandler.class);
+ dispatcher.register(LocalizationEventType.class, localizerBus);
+ // null serviceData; no registered AuxServicesEventType handler
+
+ ContainerLaunchContext ctxt = mock(ContainerLaunchContext.class);
+ ContainerId cId = getMockContainerId(7, 314159265358979L, 4344);
+ when(ctxt.getUser()).thenReturn("yak");
+ when(ctxt.getContainerId()).thenReturn(cId);
+
+ Random r = new Random();
+ long seed = r.nextLong();
+ r.setSeed(seed);
+ System.out.println("testLocalizationRequest seed: " + seed);
+ final Map<String,LocalResource> localResources = createLocalResources(r);
+ when(ctxt.getAllLocalResources()).thenReturn(localResources);
+
+ final Container c = new ContainerImpl(dispatcher, ctxt);
+ assertEquals(ContainerState.NEW, c.getContainerState());
+
+ // Verify request for public/private resources to localizer
+ c.handle(new ContainerEvent(cId, ContainerEventType.INIT_CONTAINER));
+ dispatcher.await();
+ ContainerReqMatcher matchesPublicReq =
+ new ContainerReqMatcher(localResources,
+ EnumSet.of(LocalResourceVisibility.PUBLIC));
+ ContainerReqMatcher matchesPrivateReq =
+ new ContainerReqMatcher(localResources,
+ EnumSet.of(LocalResourceVisibility.PRIVATE));
+ ContainerReqMatcher matchesAppReq =
+ new ContainerReqMatcher(localResources,
+ EnumSet.of(LocalResourceVisibility.APPLICATION));
+ verify(localizerBus).handle(argThat(matchesPublicReq));
+ verify(localizerBus).handle(argThat(matchesPrivateReq));
+ verify(localizerBus).handle(argThat(matchesAppReq));
+ assertEquals(ContainerState.LOCALIZING, c.getContainerState());
+ } finally {
+ dispatcher.stop();
+ }
+ }
+
+ /**
+ * Verify container launch when all resources already cached.
+ */
+ @Test
+ @SuppressWarnings("unchecked") // mocked generic
+ public void testLocalizationLaunch() throws Exception {
+ DrainDispatcher dispatcher = new DrainDispatcher();
+ dispatcher.init(null);
+ try {
+ dispatcher.start();
+ EventHandler<LocalizationEvent> localizerBus = mock(EventHandler.class);
+ dispatcher.register(LocalizationEventType.class, localizerBus);
+ EventHandler<ContainersLauncherEvent> launcherBus =
+ mock(EventHandler.class);
+ dispatcher.register(ContainersLauncherEventType.class, launcherBus);
+ // null serviceData; no registered AuxServicesEventType handler
+
+ ContainerLaunchContext ctxt = mock(ContainerLaunchContext.class);
+ ContainerId cId = getMockContainerId(8, 314159265358979L, 4344);
+ when(ctxt.getUser()).thenReturn("yak");
+ when(ctxt.getContainerId()).thenReturn(cId);
+
+ Random r = new Random();
+ long seed = r.nextLong();
+ r.setSeed(seed);
+ System.out.println("testLocalizationLaunch seed: " + seed);
+ final Map<String,LocalResource> localResources = createLocalResources(r);
+ when(ctxt.getAllLocalResources()).thenReturn(localResources);
+
+ final Container c = new ContainerImpl(dispatcher, ctxt);
+ assertEquals(ContainerState.NEW, c.getContainerState());
+
+ c.handle(new ContainerEvent(cId, ContainerEventType.INIT_CONTAINER));
+ dispatcher.await();
+
+ // Container prepared for localization events
+ Path cache = new Path("file:///cache");
+ Map<Path,String> localPaths = new HashMap<Path,String>();
+ for (Entry<String,LocalResource> rsrc : localResources.entrySet()) {
+ assertEquals(ContainerState.LOCALIZING, c.getContainerState());
+ LocalResourceRequest req = new LocalResourceRequest(rsrc.getValue());
+ Path p = new Path(cache, rsrc.getKey());
+ localPaths.put(p, rsrc.getKey());
+ // rsrc copied to p
+ c.handle(new ContainerResourceLocalizedEvent(c.getContainerID(), req, p));
+ }
+ dispatcher.await();
+
+ // all resources should be localized
+ assertEquals(ContainerState.LOCALIZED, c.getContainerState());
+ for (Entry<Path,String> loc : c.getLocalizedResources().entrySet()) {
+ assertEquals(localPaths.remove(loc.getKey()), loc.getValue());
+ }
+ assertTrue(localPaths.isEmpty());
+
+ // verify container launch
+ ArgumentMatcher<ContainersLauncherEvent> matchesContainerLaunch =
+ new ArgumentMatcher<ContainersLauncherEvent>() {
+ @Override
+ public boolean matches(Object o) {
+ ContainersLauncherEvent launchEvent = (ContainersLauncherEvent) o;
+ return c == launchEvent.getContainer();
+ }
+ };
+ verify(launcherBus).handle(argThat(matchesContainerLaunch));
+ } finally {
+ dispatcher.stop();
+ }
+ }
+
+ /**
+ * Verify serviceData correctly sent.
+ */
+ @Test
+ @SuppressWarnings("unchecked") // mocked generic
+ public void testServiceData() throws Exception {
+ DrainDispatcher dispatcher = new DrainDispatcher();
+ dispatcher.init(null);
+ dispatcher.start();
+ try {
+ EventHandler<LocalizationEvent> localizerBus = mock(EventHandler.class);
+ dispatcher.register(LocalizationEventType.class, localizerBus);
+ EventHandler<AuxServicesEvent> auxBus = mock(EventHandler.class);
+ dispatcher.register(AuxServicesEventType.class, auxBus);
+ EventHandler<ContainersLauncherEvent> launchBus = mock(EventHandler.class);
+ dispatcher.register(ContainersLauncherEventType.class, launchBus);
+
+ ContainerLaunchContext ctxt = mock(ContainerLaunchContext.class);
+ final ContainerId cId = getMockContainerId(9, 314159265358979L, 4344);
+ when(ctxt.getUser()).thenReturn("yak");
+ when(ctxt.getContainerId()).thenReturn(cId);
+ when(ctxt.getAllLocalResources()).thenReturn(
+ Collections.<String,LocalResource>emptyMap());
+
+ Random r = new Random();
+ long seed = r.nextLong();
+ r.setSeed(seed);
+ System.out.println("testServiceData seed: " + seed);
+ final Map<String,ByteBuffer> serviceData = createServiceData(r);
+ when(ctxt.getAllServiceData()).thenReturn(serviceData);
+
+ final Container c = new ContainerImpl(dispatcher, ctxt);
+ assertEquals(ContainerState.NEW, c.getContainerState());
+
+ // Verify propagation of service data to AuxServices
+ c.handle(new ContainerEvent(cId, ContainerEventType.INIT_CONTAINER));
+ dispatcher.await();
+ for (final Map.Entry<String,ByteBuffer> e : serviceData.entrySet()) {
+ ArgumentMatcher<AuxServicesEvent> matchesServiceReq =
+ new ArgumentMatcher<AuxServicesEvent>() {
+ @Override
+ public boolean matches(Object o) {
+ AuxServicesEvent evt = (AuxServicesEvent) o;
+ return e.getKey().equals(evt.getServiceID())
+ && 0 == e.getValue().compareTo(evt.getServiceData());
+ }
+ };
+ verify(auxBus).handle(argThat(matchesServiceReq));
+ }
+
+ // verify launch on empty resource request
+ ArgumentMatcher<ContainersLauncherEvent> matchesLaunchReq =
+ new ArgumentMatcher<ContainersLauncherEvent>() {
+ @Override
+ public boolean matches(Object o) {
+ ContainersLauncherEvent evt = (ContainersLauncherEvent) o;
+ return evt.getType() == ContainersLauncherEventType.LAUNCH_CONTAINER
+ && cId == evt.getContainer().getContainerID();
+ }
+ };
+ verify(launchBus).handle(argThat(matchesLaunchReq));
+ } finally {
+ dispatcher.stop();
+ }
+ }
+
+ // Accept iff the resource request payload matches.
+ static class ContainerReqMatcher extends ArgumentMatcher<LocalizationEvent> {
+ final HashSet<LocalResourceRequest> resources =
+ new HashSet<LocalResourceRequest>();
+ ContainerReqMatcher(Map<String,LocalResource> allResources,
+ EnumSet<LocalResourceVisibility> vis) throws URISyntaxException {
+ for (Entry<String,LocalResource> e : allResources.entrySet()) {
+ if (vis.contains(e.getValue().getVisibility())) {
+ resources.add(new LocalResourceRequest(e.getValue()));
+ }
+ }
+ }
+ @Override
+ public boolean matches(Object o) {
+ ContainerLocalizationRequestEvent evt = (ContainerLocalizationRequestEvent) o;
+ final HashSet<LocalResourceRequest> expected =
+ new HashSet<LocalResourceRequest>(resources);
+ for (LocalResourceRequest rsrc : evt.getRequestedResources()) {
+ if (!expected.remove(rsrc)) {
+ return false;
+ }
+ }
+ return expected.isEmpty();
+ }
+ }
+
+ static Entry<String,LocalResource> getMockRsrc(Random r,
+ LocalResourceVisibility vis) {
+ LocalResource rsrc = mock(LocalResource.class);
+
+ String name = Long.toHexString(r.nextLong());
+ URL uri = mock(org.apache.hadoop.yarn.api.records.URL.class);
+ when(uri.getScheme()).thenReturn("file");
+ when(uri.getHost()).thenReturn(null);
+ when(uri.getFile()).thenReturn("/local/" + vis + "/" + name);
+
+ when(rsrc.getResource()).thenReturn(uri);
+ when(rsrc.getSize()).thenReturn(r.nextInt(1024) + 1024L);
+ when(rsrc.getTimestamp()).thenReturn(r.nextInt(1024) + 2048L);
+ when(rsrc.getType()).thenReturn(LocalResourceType.FILE);
+ when(rsrc.getVisibility()).thenReturn(vis);
+
+ return new SimpleEntry<String,LocalResource>(name, rsrc);
+ }
+
+ static Map<String,LocalResource> createLocalResources(Random r) {
+ Map<String,LocalResource> localResources =
+ new HashMap<String,LocalResource>();
+ for (int i = r.nextInt(5) + 5; i >= 0; --i) {
+ Entry<String,LocalResource> rsrc =
+ getMockRsrc(r, LocalResourceVisibility.PUBLIC);
+ localResources.put(rsrc.getKey(), rsrc.getValue());
+ }
+ for (int i = r.nextInt(5) + 5; i >= 0; --i) {
+ Entry<String,LocalResource> rsrc =
+ getMockRsrc(r, LocalResourceVisibility.PRIVATE);
+ localResources.put(rsrc.getKey(), rsrc.getValue());
+ }
+ for (int i = r.nextInt(2) + 2; i >= 0; --i) {
+ Entry<String,LocalResource> rsrc =
+ getMockRsrc(r, LocalResourceVisibility.APPLICATION);
+ localResources.put(rsrc.getKey(), rsrc.getValue());
+ }
+ return localResources;
+ }
+
+ static ContainerId getMockContainerId(int appId, long timestamp, int id) {
+ ApplicationId aId = mock(ApplicationId.class);
+ when(aId.getId()).thenReturn(appId);
+ when(aId.getClusterTimestamp()).thenReturn(timestamp);
+ ContainerId cId = mock(ContainerId.class);
+ when(cId.getId()).thenReturn(id);
+ when(cId.getAppId()).thenReturn(aId);
+ return cId;
+ }
+
+ static Map<String,ByteBuffer> createServiceData(Random r) {
+ Map<String,ByteBuffer> serviceData =
+ new HashMap<String,ByteBuffer>();
+ for (int i = r.nextInt(5) + 5; i >= 0; --i) {
+ String service = Long.toHexString(r.nextLong());
+ byte[] b = new byte[r.nextInt(1024) + 1024];
+ r.nextBytes(b);
+ serviceData.put(service, ByteBuffer.wrap(b));
+ }
+ return serviceData;
+ }
+
+}
Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/MockLocalResourceStatus.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/MockLocalResourceStatus.java?rev=1097727&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/MockLocalResourceStatus.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/MockLocalResourceStatus.java Fri Apr 29 08:35:53 2011
@@ -0,0 +1,82 @@
+/**
+* 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.hadoop.yarn.server.nodemanager.containermanager.localizer;
+
+import org.apache.hadoop.yarn.api.records.LocalResource;
+import org.apache.hadoop.yarn.api.records.URL;
+import org.apache.hadoop.yarn.exceptions.YarnRemoteException;
+import org.apache.hadoop.yarn.server.nodemanager.api.protocolrecords.LocalResourceStatus;
+import org.apache.hadoop.yarn.server.nodemanager.api.protocolrecords.ResourceStatusType;
+
+public class MockLocalResourceStatus implements LocalResourceStatus {
+
+ private LocalResource rsrc = null;
+ private ResourceStatusType tag = null;
+ private URL localPath = null;
+ private long size = -1L;
+ private YarnRemoteException ex = null;
+
+ MockLocalResourceStatus() { }
+ MockLocalResourceStatus(LocalResource rsrc, ResourceStatusType tag,
+ URL localPath, YarnRemoteException ex) {
+ this.rsrc = rsrc;
+ this.tag = tag;
+ this.localPath = localPath;
+ this.ex = ex;
+ }
+
+ @Override
+ public LocalResource getResource() { return rsrc; }
+ @Override
+ public ResourceStatusType getStatus() { return tag; }
+ @Override
+ public long getLocalSize() { return size; }
+ @Override
+ public URL getLocalPath() { return localPath; }
+ @Override
+ public YarnRemoteException getException() { return ex; }
+ @Override
+ public void setResource(LocalResource rsrc) { this.rsrc = rsrc; }
+ @Override
+ public void setStatus(ResourceStatusType tag) { this.tag = tag; }
+ @Override
+ public void setLocalPath(URL localPath) { this.localPath = localPath; }
+ @Override
+ public void setLocalSize(long size) { this.size = size; }
+ @Override
+ public void setException(YarnRemoteException ex) { this.ex = ex; }
+
+ @Override
+ public boolean equals(Object o) {
+ if (!(o instanceof MockLocalResourceStatus)) {
+ return false;
+ }
+ MockLocalResourceStatus other = (MockLocalResourceStatus) o;
+ return getResource().equals(other.getResource())
+ && getStatus().equals(other.getStatus())
+ && (null != getLocalPath()
+ && getLocalPath().equals(other.getLocalPath()))
+ && (null != getException()
+ && getException().equals(other.getException()));
+ }
+
+ @Override
+ public int hashCode() {
+ return 4344;
+ }
+}
Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/MockLocalizerHeartbeatResponse.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/MockLocalizerHeartbeatResponse.java?rev=1097727&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/MockLocalizerHeartbeatResponse.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/MockLocalizerHeartbeatResponse.java Fri Apr 29 08:35:53 2011
@@ -0,0 +1,55 @@
+/**
+* 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.hadoop.yarn.server.nodemanager.containermanager.localizer;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.hadoop.yarn.api.records.LocalResource;
+import org.apache.hadoop.yarn.server.nodemanager.api.protocolrecords.LocalizerAction;
+import org.apache.hadoop.yarn.server.nodemanager.api.protocolrecords.LocalizerHeartbeatResponse;
+
+public class MockLocalizerHeartbeatResponse
+ implements LocalizerHeartbeatResponse {
+
+ LocalizerAction action;
+ List<LocalResource> rsrc;
+
+ MockLocalizerHeartbeatResponse() {
+ rsrc = new ArrayList<LocalResource>();
+ }
+
+ MockLocalizerHeartbeatResponse(
+ LocalizerAction action, List<LocalResource> rsrc) {
+ this.action = action;
+ this.rsrc = rsrc;
+ }
+
+ public LocalizerAction getLocalizerAction() { return action; }
+ public List<LocalResource> getAllResources() { return rsrc; }
+ public LocalResource getLocalResource(int i) { return rsrc.get(i); }
+ public void setLocalizerAction(LocalizerAction action) {
+ this.action = action;
+ }
+ public void addAllResources(List<LocalResource> resources) {
+ rsrc.addAll(resources);
+ }
+ public void addResource(LocalResource resource) { rsrc.add(resource); }
+ public void removeResource(int index) { rsrc.remove(index); }
+ public void clearResources() { rsrc.clear(); }
+}
Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/MockLocalizerStatus.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/MockLocalizerStatus.java?rev=1097727&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/MockLocalizerStatus.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/MockLocalizerStatus.java Fri Apr 29 08:35:53 2011
@@ -0,0 +1,80 @@
+/**
+* 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.hadoop.yarn.server.nodemanager.containermanager.localizer;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.hadoop.yarn.server.nodemanager.api.protocolrecords.LocalResourceStatus;
+import org.apache.hadoop.yarn.server.nodemanager.api.protocolrecords.LocalizerStatus;
+
+public class MockLocalizerStatus implements LocalizerStatus {
+
+ private String locId;
+ private List<LocalResourceStatus> stats;
+
+ public MockLocalizerStatus() {
+ stats = new ArrayList<LocalResourceStatus>();
+ }
+
+ public MockLocalizerStatus(String locId, List<LocalResourceStatus> stats) {
+ this.locId = locId;
+ this.stats = stats;
+ }
+
+ @Override
+ public String getLocalizerId() { return locId; }
+ @Override
+ public List<LocalResourceStatus> getResources() { return stats; }
+ @Override
+ public void setLocalizerId(String id) { this.locId = id; }
+ @Override
+ public void addAllResources(List<LocalResourceStatus> rsrcs) {
+ stats.addAll(rsrcs);
+ }
+ @Override
+ public LocalResourceStatus getResourceStatus(int index) {
+ return stats.get(index);
+ }
+ @Override
+ public void addResourceStatus(LocalResourceStatus resource) {
+ stats.add(resource);
+ }
+ @Override
+ public void removeResource(int index) {
+ stats.remove(index);
+ }
+ public void clearResources() { stats.clear(); }
+
+ @Override
+ public boolean equals(Object o) {
+ if (!(o instanceof MockLocalizerStatus)) {
+ return false;
+ }
+ MockLocalizerStatus other = (MockLocalizerStatus) o;
+ return getLocalizerId().equals(other)
+ && getResources().containsAll(other.getResources())
+ && other.getResources().containsAll(getResources());
+ }
+
+ @Override
+ public int hashCode() {
+ return 4344;
+ }
+
+}
|