You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ma...@apache.org on 2012/10/08 03:38:08 UTC
svn commit: r1395430 [11/13] - in /incubator/ambari/branches/AMBARI-666: ./
ambari-agent/src/main/puppet/manifestloader/
ambari-agent/src/main/puppet/modules/configgenerator/manifests/
ambari-agent/src/main/puppet/modules/hdp-hadoop/manifests/ ambari-a...
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostStatusUpdatesReceivedEvent.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostStatusUpdatesReceivedEvent.java?rev=1395430&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostStatusUpdatesReceivedEvent.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostStatusUpdatesReceivedEvent.java Mon Oct 8 01:37:59 2012
@@ -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.ambari.server.state.host;
+
+import org.apache.ambari.server.state.HostEvent;
+import org.apache.ambari.server.state.HostEventType;
+
+public class HostStatusUpdatesReceivedEvent extends HostEvent {
+
+ private final long timestamp;
+
+ // TODO need to add any additional information required for verification
+ // tracking
+ public HostStatusUpdatesReceivedEvent(String hostName,
+ long timestamp) {
+ super(hostName, HostEventType.HOST_STATUS_UPDATES_RECEIVED);
+ this.timestamp = timestamp;
+ }
+
+ /**
+ * @return the timestamp
+ */
+ public long getTimestamp() {
+ return timestamp;
+ }
+
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostUnhealthyHeartbeatEvent.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostUnhealthyHeartbeatEvent.java?rev=1395430&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostUnhealthyHeartbeatEvent.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostUnhealthyHeartbeatEvent.java Mon Oct 8 01:37:59 2012
@@ -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.ambari.server.state.host;
+
+import org.apache.ambari.server.state.HostEvent;
+import org.apache.ambari.server.state.HostEventType;
+import org.apache.ambari.server.state.HostHealthStatus;
+
+public class HostUnhealthyHeartbeatEvent extends HostEvent {
+
+ private final long heartbeatTime;
+
+ private final HostHealthStatus healthStatus;
+
+ public HostUnhealthyHeartbeatEvent(String hostName, long heartbeatTime,
+ HostHealthStatus healthStatus) {
+ super(hostName, HostEventType.HOST_HEARTBEAT_UNHEALTHY);
+ this.heartbeatTime = heartbeatTime;
+ this.healthStatus = healthStatus;
+ }
+
+ /**
+ * @return the heartbeatTime
+ */
+ public long getHeartbeatTime() {
+ return heartbeatTime;
+ }
+
+ /**
+ * @return the healthStatus
+ */
+ public HostHealthStatus getHealthStatus() {
+ return healthStatus;
+ }
+
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/Job.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/Job.java?rev=1395430&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/Job.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/Job.java Mon Oct 8 01:37:59 2012
@@ -0,0 +1,75 @@
+/**
+ * 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.state.job;
+
+import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
+
+public interface Job {
+
+ /**
+ * Get the Job ID for the action
+ * @return JobId
+ */
+ public JobId getId();
+
+ // TODO requires some form of JobType to ensure only one running
+ // job per job type
+ // There may be gotchas such as de-commissioning should be allowed to happen
+ // on more than one host at a time
+
+
+ /**
+ * Get Start Time of the job
+ * @return Start time as a unix timestamp
+ */
+ public long getStartTime();
+
+ /**
+ * Get the last update time of the Job when its progress status
+ * was updated
+ * @return Last Update Time as a unix timestamp
+ */
+ public long getLastUpdateTime();
+
+ /**
+ * Time when the Job completed
+ * @return Completion Time as a unix timestamp
+ */
+ public long getCompletionTime();
+
+ /**
+ * Get the current state of the Job
+ * @return JobState
+ */
+ public JobState getState();
+
+ /**
+ * Set the State of the Job
+ * @param state JobState
+ */
+ public void setState(JobState state);
+
+ /**
+ * Send a JobEvent to the Job's StateMachine
+ * @param event JobEvent
+ * @throws InvalidStateTransitonException
+ */
+ public void handleEvent(JobEvent event)
+ throws InvalidStateTransitonException;
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobCompletedEvent.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobCompletedEvent.java?rev=1395430&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobCompletedEvent.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobCompletedEvent.java Mon Oct 8 01:37:59 2012
@@ -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.ambari.server.state.job;
+
+public class JobCompletedEvent extends JobEvent {
+
+ private final long completionTime;
+
+ // TODO
+ // need to add job report
+
+ public JobCompletedEvent(JobId jobId, long completionTime) {
+ super(JobEventType.JOB_COMPLETED, jobId);
+ this.completionTime = completionTime;
+ }
+
+ /**
+ * @return the completionTime
+ */
+ public long getCompletionTime() {
+ return completionTime;
+ }
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobEvent.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobEvent.java?rev=1395430&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobEvent.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobEvent.java Mon Oct 8 01:37:59 2012
@@ -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.ambari.server.state.job;
+
+import org.apache.ambari.server.state.fsm.event.AbstractEvent;
+
+/**
+ * Base class for all events that affect the Job FSM
+ */
+public abstract class JobEvent extends AbstractEvent<JobEventType> {
+
+ /**
+ * JobId identifying the job
+ */
+ private final JobId jobId;
+
+ public JobEvent(JobEventType type, JobId jobId) {
+ super(type);
+ this.jobId = jobId;
+ }
+
+ /**
+ * @return the jobId
+ */
+ public JobId getJobId() {
+ return jobId;
+ }
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobEventType.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobEventType.java?rev=1395430&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobEventType.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobEventType.java Mon Oct 8 01:37:59 2012
@@ -0,0 +1,38 @@
+/**
+ * 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.state.job;
+
+public enum JobEventType {
+ /**
+ * Initial state for the job when triggered.
+ */
+ JOB_INIT,
+ /**
+ * Job still in progress.
+ */
+ JOB_IN_PROGRESS,
+ /**
+ * Job completed successfully.
+ */
+ JOB_COMPLETED,
+ /**
+ * Job failed to complete successfully.
+ */
+ JOB_FAILED
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobFailedEvent.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobFailedEvent.java?rev=1395430&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobFailedEvent.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobFailedEvent.java Mon Oct 8 01:37:59 2012
@@ -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.ambari.server.state.job;
+
+public class JobFailedEvent extends JobEvent {
+
+ private final long completionTime;
+
+ // TODO
+ // need to add job report
+
+ public JobFailedEvent(JobId jobId, long completionTime) {
+ super(JobEventType.JOB_FAILED, jobId);
+ this.completionTime = completionTime;
+ }
+
+ /**
+ * @return the completionTime
+ */
+ public long getCompletionTime() {
+ return completionTime;
+ }
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobId.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobId.java?rev=1395430&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobId.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobId.java Mon Oct 8 01:37:59 2012
@@ -0,0 +1,38 @@
+/**
+ * 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.state.job;
+
+// TODO
+public class JobId {
+
+ final long jobId;
+
+ final JobType jobType;
+
+ public JobId(long jobId, JobType jobType) {
+ super();
+ this.jobId = jobId;
+ this.jobType = jobType;
+ }
+
+ public String toString() {
+ return "[ jobId=" + jobId
+ + ", jobType=" + jobType + "]";
+ }
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobImpl.java?rev=1395430&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobImpl.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobImpl.java Mon Oct 8 01:37:59 2012
@@ -0,0 +1,314 @@
+/**
+ * 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.state.job;
+
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
+import org.apache.ambari.server.state.fsm.SingleArcTransition;
+import org.apache.ambari.server.state.fsm.StateMachine;
+import org.apache.ambari.server.state.fsm.StateMachineFactory;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class JobImpl implements Job {
+
+ private static final Log LOG = LogFactory.getLog(JobImpl.class);
+
+ private final Lock readLock;
+ private final Lock writeLock;
+
+ private JobId id;
+
+ private long startTime;
+ private long lastUpdateTime;
+ private long completionTime;
+
+ // TODO
+ // need to add job report
+
+ private static final StateMachineFactory
+ <JobImpl, JobState, JobEventType, JobEvent>
+ stateMachineFactory
+ = new StateMachineFactory<JobImpl, JobState,
+ JobEventType, JobEvent>
+ (JobState.INIT)
+
+ // define the state machine of a Job
+
+ .addTransition(JobState.INIT, JobState.IN_PROGRESS,
+ JobEventType.JOB_IN_PROGRESS, new JobProgressUpdateTransition())
+ .addTransition(JobState.INIT, JobState.COMPLETED,
+ JobEventType.JOB_COMPLETED, new JobCompletedTransition())
+ .addTransition(JobState.INIT, JobState.FAILED,
+ JobEventType.JOB_FAILED, new JobFailedTransition())
+ .addTransition(JobState.INIT, JobState.IN_PROGRESS,
+ JobEventType.JOB_IN_PROGRESS, new JobProgressUpdateTransition())
+ .addTransition(JobState.IN_PROGRESS, JobState.IN_PROGRESS,
+ JobEventType.JOB_IN_PROGRESS, new JobProgressUpdateTransition())
+ .addTransition(JobState.IN_PROGRESS, JobState.COMPLETED,
+ JobEventType.JOB_COMPLETED, new JobCompletedTransition())
+ .addTransition(JobState.IN_PROGRESS, JobState.FAILED,
+ JobEventType.JOB_FAILED, new JobFailedTransition())
+ .addTransition(JobState.COMPLETED, JobState.INIT,
+ JobEventType.JOB_INIT, new NewJobTransition())
+ .addTransition(JobState.FAILED, JobState.INIT,
+ JobEventType.JOB_INIT, new NewJobTransition())
+ .installTopology();
+
+ private final StateMachine<JobState, JobEventType, JobEvent>
+ stateMachine;
+
+ public JobImpl(JobId id, long startTime) {
+ super();
+ this.id = id;
+ this.stateMachine = stateMachineFactory.make(this);
+ ReadWriteLock rwLock = new ReentrantReadWriteLock();
+ this.readLock = rwLock.readLock();
+ this.writeLock = rwLock.writeLock();
+ this.startTime = startTime;
+ this.lastUpdateTime = -1;
+ this.completionTime = -1;
+ }
+
+ private void reset() {
+ try {
+ writeLock.lock();
+ this.startTime = -1;
+ this.lastUpdateTime = -1;
+ this.completionTime = -1;
+ }
+ finally {
+ writeLock.unlock();
+ }
+ }
+
+ static class NewJobTransition
+ implements SingleArcTransition<JobImpl, JobEvent> {
+
+ @Override
+ public void transition(JobImpl job, JobEvent event) {
+ NewJobEvent e = (NewJobEvent) event;
+ // TODO audit logs
+ job.reset();
+ job.setId(e.getJobId());
+ job.setStartTime(e.getStartTime());
+ LOG.info("Launching a new Job"
+ + ", jobId=" + job.getId()
+ + ", startTime=" + job.getStartTime());
+ }
+ }
+
+ static class JobProgressUpdateTransition
+ implements SingleArcTransition<JobImpl, JobEvent> {
+
+ @Override
+ public void transition(JobImpl job, JobEvent event) {
+ JobProgressUpdateEvent e = (JobProgressUpdateEvent) event;
+ job.setLastUpdateTime(e.getProgressUpdateTime());
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Progress update for Job"
+ + ", jobId=" + job.getId()
+ + ", startTime=" + job.getStartTime()
+ + ", lastUpdateTime=" + job.getLastUpdateTime());
+ }
+ }
+ }
+
+ static class JobCompletedTransition
+ implements SingleArcTransition<JobImpl, JobEvent> {
+
+ @Override
+ public void transition(JobImpl job, JobEvent event) {
+ // TODO audit logs
+ JobCompletedEvent e = (JobCompletedEvent) event;
+ job.setCompletionTime(e.getCompletionTime());
+ job.setLastUpdateTime(e.getCompletionTime());
+
+ LOG.info("Job completed successfully"
+ + ", jobId=" + job.getId()
+ + ", startTime=" + job.getStartTime()
+ + ", completionTime=" + job.getCompletionTime());
+ }
+ }
+
+ static class JobFailedTransition
+ implements SingleArcTransition<JobImpl, JobEvent> {
+
+ @Override
+ public void transition(JobImpl job, JobEvent event) {
+ // TODO audit logs
+ JobFailedEvent e = (JobFailedEvent) event;
+ job.setCompletionTime(e.getCompletionTime());
+ job.setLastUpdateTime(e.getCompletionTime());
+ LOG.info("Job failed to complete"
+ + ", jobId=" + job.getId()
+ + ", startTime=" + job.getStartTime()
+ + ", completionTime=" + job.getCompletionTime());
+ }
+ }
+
+
+ @Override
+ public JobState getState() {
+ try {
+ readLock.lock();
+ return stateMachine.getCurrentState();
+ }
+ finally {
+ readLock.unlock();
+ }
+ }
+
+ @Override
+ public void setState(JobState state) {
+ try {
+ writeLock.lock();
+ stateMachine.setCurrentState(state);
+ }
+ finally {
+ writeLock.unlock();
+ }
+ }
+
+ @Override
+ public void handleEvent(JobEvent event)
+ throws InvalidStateTransitonException {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Handling Job event, eventType=" + event.getType().name()
+ + ", event=" + event.toString());
+ }
+ JobState oldState = getState();
+ try {
+ writeLock.lock();
+ try {
+ stateMachine.doTransition(event.getType(), event);
+ } catch (InvalidStateTransitonException e) {
+ LOG.error("Can't handle Job event at current state"
+ + ", jobId=" + this.getId()
+ + ", currentState=" + oldState
+ + ", eventType=" + event.getType()
+ + ", event=" + event);
+ throw e;
+ }
+ }
+ finally {
+ writeLock.unlock();
+ }
+ if (oldState != getState()) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Job transitioned to a new state"
+ + ", jobId=" + this.getId()
+ + ", oldState=" + oldState
+ + ", currentState=" + getState()
+ + ", eventType=" + event.getType().name()
+ + ", event=" + event);
+ }
+ }
+ }
+
+ @Override
+ public JobId getId() {
+ try {
+ readLock.lock();
+ return id;
+ }
+ finally {
+ readLock.unlock();
+ }
+ }
+
+ private void setId(JobId id) {
+ try {
+ writeLock.lock();
+ this.id = id;
+ }
+ finally {
+ writeLock.unlock();
+ }
+ }
+
+ @Override
+ public long getStartTime() {
+ try {
+ readLock.lock();
+ return startTime;
+ }
+ finally {
+ readLock.unlock();
+ }
+ }
+
+ public void setStartTime(long startTime) {
+ try {
+ writeLock.lock();
+ this.startTime = startTime;
+ }
+ finally {
+ writeLock.unlock();
+ }
+ }
+
+ @Override
+ public long getLastUpdateTime() {
+ try {
+ readLock.lock();
+ return lastUpdateTime;
+ }
+ finally {
+ readLock.unlock();
+ }
+ }
+
+ public void setLastUpdateTime(long lastUpdateTime) {
+ try {
+ writeLock.lock();
+ this.lastUpdateTime = lastUpdateTime;
+ }
+ finally {
+ writeLock.unlock();
+ }
+
+ }
+
+ @Override
+ public long getCompletionTime() {
+ try {
+ readLock.lock();
+ return completionTime;
+ }
+ finally {
+ readLock.unlock();
+ }
+ }
+
+ public void setCompletionTime(long completionTime) {
+ try {
+ writeLock.lock();
+ this.completionTime = completionTime;
+ }
+ finally {
+ writeLock.unlock();
+ }
+ }
+
+
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobProgressUpdateEvent.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobProgressUpdateEvent.java?rev=1395430&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobProgressUpdateEvent.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobProgressUpdateEvent.java Mon Oct 8 01:37:59 2012
@@ -0,0 +1,37 @@
+/**
+ * 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.state.job;
+
+public class JobProgressUpdateEvent extends JobEvent {
+
+ private final long progressUpdateTime;
+
+ public JobProgressUpdateEvent(JobId jobId, long progressUpdateTime) {
+ super(JobEventType.JOB_IN_PROGRESS, jobId);
+ this.progressUpdateTime = progressUpdateTime;
+ }
+
+ /**
+ * @return the progressUpdateTime
+ */
+ public long getProgressUpdateTime() {
+ return progressUpdateTime;
+ }
+
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobState.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobState.java?rev=1395430&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobState.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobState.java Mon Oct 8 01:37:59 2012
@@ -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.ambari.server.state.job;
+
+public enum JobState {
+ /**
+ * Initial state for the Job.
+ * When a new action is triggered or set in motion.
+ */
+ INIT,
+ /**
+ * State when the job is triggered on the cluster,
+ */
+ IN_PROGRESS,
+ /**
+ * State of successful completion
+ */
+ COMPLETED,
+ /**
+ * Job failed to complete successfully
+ */
+ FAILED
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobType.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobType.java?rev=1395430&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobType.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/JobType.java Mon Oct 8 01:37:59 2012
@@ -0,0 +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.ambari.server.state.job;
+
+public class JobType {
+
+ public final String jobName;
+
+ public JobType(String jobName) {
+ super();
+ this.jobName = jobName;
+ }
+
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/NewJobEvent.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/NewJobEvent.java?rev=1395430&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/NewJobEvent.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/job/NewJobEvent.java Mon Oct 8 01:37:59 2012
@@ -0,0 +1,37 @@
+/**
+ * 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.state.job;
+
+public class NewJobEvent extends JobEvent {
+
+ private final long startTime;
+
+ public NewJobEvent(JobId jobId, long startTime) {
+ super(JobEventType.JOB_INIT, jobId);
+ this.startTime = startTime;
+ }
+
+ /**
+ * @return the start time of the Job
+ */
+ public long getStartTime() {
+ return startTime;
+ }
+
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java?rev=1395430&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java Mon Oct 8 01:37:59 2012
@@ -0,0 +1,709 @@
+/**
+ * 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.state.svccomphost;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+import org.apache.ambari.server.controller.ServiceComponentHostResponse;
+import org.apache.ambari.server.state.Config;
+import org.apache.ambari.server.state.State;
+import org.apache.ambari.server.state.ServiceComponent;
+import org.apache.ambari.server.state.ServiceComponentHost;
+import org.apache.ambari.server.state.ServiceComponentHostEvent;
+import org.apache.ambari.server.state.ServiceComponentHostEventType;
+import org.apache.ambari.server.state.StackVersion;
+import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
+import org.apache.ambari.server.state.fsm.SingleArcTransition;
+import org.apache.ambari.server.state.fsm.StateMachine;
+import org.apache.ambari.server.state.fsm.StateMachineFactory;
+import org.apache.ambari.server.state.job.Job;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ServiceComponentHostImpl implements ServiceComponentHost {
+
+ private static final Logger LOG =
+ LoggerFactory.getLogger(ServiceComponentHostImpl.class);
+
+ private final Lock readLock;
+ private final Lock writeLock;
+
+ private final ServiceComponent serviceComponent;
+ private final String hostName;
+
+ private Map<String, Config> configs;
+ private Map<String, Config> desiredConfigs;
+ private StackVersion stackVersion;
+ private StackVersion desiredStackVersion;
+
+ private State desiredState;
+
+ private long lastOpStartTime;
+ private long lastOpEndTime;
+ private long lastOpLastUpdateTime;
+
+ private static final StateMachineFactory
+ <ServiceComponentHostImpl, State,
+ ServiceComponentHostEventType, ServiceComponentHostEvent>
+ daemonStateMachineFactory
+ = new StateMachineFactory<ServiceComponentHostImpl,
+ State, ServiceComponentHostEventType,
+ ServiceComponentHostEvent>
+ (State.INIT)
+
+ // define the state machine of a HostServiceComponent for runnable
+ // components
+
+ .addTransition(State.INIT,
+ State.INSTALLING,
+ ServiceComponentHostEventType.HOST_SVCCOMP_INSTALL,
+ new ServiceComponentHostOpStartedTransition())
+ .addTransition(State.INSTALLING,
+ State.INSTALLED,
+ ServiceComponentHostEventType.HOST_SVCCOMP_OP_SUCCEEDED,
+ new ServiceComponentHostOpCompletedTransition())
+ .addTransition(State.INSTALLING,
+ State.INSTALLING,
+ ServiceComponentHostEventType.HOST_SVCCOMP_OP_IN_PROGRESS,
+ new ServiceComponentHostOpInProgressTransition())
+ .addTransition(State.INSTALLING,
+ State.INSTALL_FAILED,
+ ServiceComponentHostEventType.HOST_SVCCOMP_OP_FAILED,
+ new ServiceComponentHostOpCompletedTransition())
+
+ .addTransition(State.INSTALL_FAILED,
+ State.INSTALLING,
+ ServiceComponentHostEventType.HOST_SVCCOMP_OP_RESTART,
+ new ServiceComponentHostOpStartedTransition())
+
+ .addTransition(State.INSTALLED,
+ State.STARTING,
+ ServiceComponentHostEventType.HOST_SVCCOMP_START,
+ new ServiceComponentHostOpStartedTransition())
+ .addTransition(State.INSTALLED,
+ State.UNINSTALLING,
+ ServiceComponentHostEventType.HOST_SVCCOMP_UNINSTALL,
+ new ServiceComponentHostOpStartedTransition())
+ .addTransition(State.INSTALLED,
+ State.INSTALLING,
+ ServiceComponentHostEventType.HOST_SVCCOMP_INSTALL,
+ new ServiceComponentHostOpStartedTransition())
+
+ .addTransition(State.STARTING,
+ State.STARTING,
+ ServiceComponentHostEventType.HOST_SVCCOMP_OP_IN_PROGRESS,
+ new ServiceComponentHostOpInProgressTransition())
+ .addTransition(State.STARTING,
+ State.STARTED,
+ ServiceComponentHostEventType.HOST_SVCCOMP_OP_SUCCEEDED,
+ new ServiceComponentHostOpCompletedTransition())
+ .addTransition(State.STARTING,
+ State.START_FAILED,
+ ServiceComponentHostEventType.HOST_SVCCOMP_OP_FAILED,
+ new ServiceComponentHostOpCompletedTransition())
+
+ .addTransition(State.START_FAILED,
+ State.STARTING,
+ ServiceComponentHostEventType.HOST_SVCCOMP_OP_RESTART,
+ new ServiceComponentHostOpStartedTransition())
+
+ .addTransition(State.STARTED,
+ State.STOPPING,
+ ServiceComponentHostEventType.HOST_SVCCOMP_STOP,
+ new ServiceComponentHostOpStartedTransition())
+
+ .addTransition(State.STOPPING,
+ State.STOPPING,
+ ServiceComponentHostEventType.HOST_SVCCOMP_OP_IN_PROGRESS,
+ new ServiceComponentHostOpInProgressTransition())
+ .addTransition(State.STOPPING,
+ State.INSTALLED,
+ ServiceComponentHostEventType.HOST_SVCCOMP_OP_SUCCEEDED,
+ new ServiceComponentHostOpCompletedTransition())
+ .addTransition(State.STOPPING,
+ State.STOP_FAILED,
+ ServiceComponentHostEventType.HOST_SVCCOMP_OP_FAILED,
+ new ServiceComponentHostOpCompletedTransition())
+
+ .addTransition(State.STOP_FAILED,
+ State.STOPPING,
+ ServiceComponentHostEventType.HOST_SVCCOMP_OP_RESTART,
+ new ServiceComponentHostOpStartedTransition())
+
+ .addTransition(State.UNINSTALLING,
+ State.UNINSTALLING,
+ ServiceComponentHostEventType.HOST_SVCCOMP_OP_IN_PROGRESS,
+ new ServiceComponentHostOpInProgressTransition())
+ .addTransition(State.UNINSTALLING,
+ State.UNINSTALLED,
+ ServiceComponentHostEventType.HOST_SVCCOMP_OP_SUCCEEDED,
+ new ServiceComponentHostOpCompletedTransition())
+ .addTransition(State.UNINSTALLING,
+ State.UNINSTALL_FAILED,
+ ServiceComponentHostEventType.HOST_SVCCOMP_OP_FAILED,
+ new ServiceComponentHostOpCompletedTransition())
+
+ .addTransition(State.UNINSTALL_FAILED,
+ State.UNINSTALLING,
+ ServiceComponentHostEventType.HOST_SVCCOMP_OP_RESTART,
+ new ServiceComponentHostOpStartedTransition())
+
+ .addTransition(State.UNINSTALLED,
+ State.INSTALLING,
+ ServiceComponentHostEventType.HOST_SVCCOMP_INSTALL,
+ new ServiceComponentHostOpStartedTransition())
+
+ .addTransition(State.UNINSTALLED,
+ State.WIPING_OUT,
+ ServiceComponentHostEventType.HOST_SVCCOMP_WIPEOUT,
+ new ServiceComponentHostOpStartedTransition())
+
+ .addTransition(State.WIPING_OUT,
+ State.WIPING_OUT,
+ ServiceComponentHostEventType.HOST_SVCCOMP_OP_IN_PROGRESS,
+ new ServiceComponentHostOpInProgressTransition())
+ .addTransition(State.WIPING_OUT,
+ State.INIT,
+ ServiceComponentHostEventType.HOST_SVCCOMP_OP_SUCCEEDED,
+ new ServiceComponentHostOpCompletedTransition())
+ .addTransition(State.WIPING_OUT,
+ State.WIPEOUT_FAILED,
+ ServiceComponentHostEventType.HOST_SVCCOMP_OP_FAILED,
+ new ServiceComponentHostOpCompletedTransition())
+ .addTransition(State.WIPEOUT_FAILED,
+ State.WIPING_OUT,
+ ServiceComponentHostEventType.HOST_SVCCOMP_OP_RESTART,
+ new ServiceComponentHostOpStartedTransition())
+
+ .installTopology();
+
+ private static final StateMachineFactory
+ <ServiceComponentHostImpl, State,
+ ServiceComponentHostEventType, ServiceComponentHostEvent>
+ clientStateMachineFactory
+ = new StateMachineFactory<ServiceComponentHostImpl,
+ State, ServiceComponentHostEventType,
+ ServiceComponentHostEvent>
+ (State.INIT)
+
+ // define the state machine of a HostServiceComponent for client only
+ // components
+
+ .addTransition(State.INIT,
+ State.INSTALLING,
+ ServiceComponentHostEventType.HOST_SVCCOMP_INSTALL,
+ new ServiceComponentHostOpStartedTransition())
+
+ .addTransition(State.INSTALLING,
+ State.INSTALLED,
+ ServiceComponentHostEventType.HOST_SVCCOMP_OP_SUCCEEDED,
+ new ServiceComponentHostOpCompletedTransition())
+ .addTransition(State.INSTALLING,
+ State.INSTALLING,
+ ServiceComponentHostEventType.HOST_SVCCOMP_OP_IN_PROGRESS,
+ new ServiceComponentHostOpInProgressTransition())
+ .addTransition(State.INSTALLING,
+ State.INSTALL_FAILED,
+ ServiceComponentHostEventType.HOST_SVCCOMP_OP_FAILED,
+ new ServiceComponentHostOpCompletedTransition())
+
+ .addTransition(State.INSTALL_FAILED,
+ State.INSTALLING,
+ ServiceComponentHostEventType.HOST_SVCCOMP_OP_RESTART,
+ new ServiceComponentHostOpStartedTransition())
+
+ .addTransition(State.INSTALLED,
+ State.UNINSTALLING,
+ ServiceComponentHostEventType.HOST_SVCCOMP_UNINSTALL,
+ new ServiceComponentHostOpStartedTransition())
+ .addTransition(State.INSTALLED,
+ State.INSTALLING,
+ ServiceComponentHostEventType.HOST_SVCCOMP_INSTALL,
+ new ServiceComponentHostOpStartedTransition())
+
+ .addTransition(State.UNINSTALLING,
+ State.UNINSTALLING,
+ ServiceComponentHostEventType.HOST_SVCCOMP_OP_IN_PROGRESS,
+ new ServiceComponentHostOpInProgressTransition())
+ .addTransition(State.UNINSTALLING,
+ State.UNINSTALLED,
+ ServiceComponentHostEventType.HOST_SVCCOMP_OP_SUCCEEDED,
+ new ServiceComponentHostOpCompletedTransition())
+ .addTransition(State.UNINSTALLING,
+ State.UNINSTALL_FAILED,
+ ServiceComponentHostEventType.HOST_SVCCOMP_OP_FAILED,
+ new ServiceComponentHostOpCompletedTransition())
+
+ .addTransition(State.UNINSTALL_FAILED,
+ State.UNINSTALLING,
+ ServiceComponentHostEventType.HOST_SVCCOMP_OP_RESTART,
+ new ServiceComponentHostOpStartedTransition())
+
+ .addTransition(State.UNINSTALLED,
+ State.INSTALLING,
+ ServiceComponentHostEventType.HOST_SVCCOMP_INSTALL,
+ new ServiceComponentHostOpStartedTransition())
+
+ .addTransition(State.UNINSTALLED,
+ State.WIPING_OUT,
+ ServiceComponentHostEventType.HOST_SVCCOMP_WIPEOUT,
+ new ServiceComponentHostOpStartedTransition())
+
+ .addTransition(State.WIPING_OUT,
+ State.WIPING_OUT,
+ ServiceComponentHostEventType.HOST_SVCCOMP_OP_IN_PROGRESS,
+ new ServiceComponentHostOpInProgressTransition())
+ .addTransition(State.WIPING_OUT,
+ State.INIT,
+ ServiceComponentHostEventType.HOST_SVCCOMP_OP_SUCCEEDED,
+ new ServiceComponentHostOpCompletedTransition())
+ .addTransition(State.WIPING_OUT,
+ State.WIPEOUT_FAILED,
+ ServiceComponentHostEventType.HOST_SVCCOMP_OP_FAILED,
+ new ServiceComponentHostOpCompletedTransition())
+ .addTransition(State.WIPEOUT_FAILED,
+ State.WIPING_OUT,
+ ServiceComponentHostEventType.HOST_SVCCOMP_OP_RESTART,
+ new ServiceComponentHostOpStartedTransition())
+
+ .installTopology();
+
+
+ private final StateMachine<State,
+ ServiceComponentHostEventType, ServiceComponentHostEvent> stateMachine;
+
+ static class ServiceComponentHostOpCompletedTransition
+ implements SingleArcTransition<ServiceComponentHostImpl,
+ ServiceComponentHostEvent> {
+
+ @Override
+ public void transition(ServiceComponentHostImpl impl,
+ ServiceComponentHostEvent event) {
+ // TODO Audit logs
+ impl.updateLastOpInfo(event.getType(), event.getOpTimestamp());
+ }
+
+ }
+
+ static class ServiceComponentHostOpStartedTransition
+ implements SingleArcTransition<ServiceComponentHostImpl,
+ ServiceComponentHostEvent> {
+
+ @Override
+ public void transition(ServiceComponentHostImpl impl,
+ ServiceComponentHostEvent event) {
+ // TODO Audit logs
+ impl.updateLastOpInfo(event.getType(), event.getOpTimestamp());
+ }
+ }
+
+ static class ServiceComponentHostOpInProgressTransition
+ implements SingleArcTransition<ServiceComponentHostImpl,
+ ServiceComponentHostEvent> {
+
+ @Override
+ public void transition(ServiceComponentHostImpl impl,
+ ServiceComponentHostEvent event) {
+ // TODO Audit logs
+ impl.updateLastOpInfo(event.getType(), event.getOpTimestamp());
+ }
+ }
+
+
+ private void resetLastOpInfo() {
+ try {
+ writeLock.lock();
+ setLastOpStartTime(-1);
+ setLastOpLastUpdateTime(-1);
+ setLastOpEndTime(-1);
+ }
+ finally {
+ writeLock.unlock();
+ }
+ }
+
+ private void updateLastOpInfo(ServiceComponentHostEventType eventType,
+ long time) {
+ try {
+ writeLock.lock();
+ switch (eventType) {
+ case HOST_SVCCOMP_INSTALL:
+ case HOST_SVCCOMP_START:
+ case HOST_SVCCOMP_STOP:
+ case HOST_SVCCOMP_UNINSTALL:
+ case HOST_SVCCOMP_WIPEOUT:
+ case HOST_SVCCOMP_OP_RESTART:
+ resetLastOpInfo();
+ setLastOpStartTime(time);
+ break;
+ case HOST_SVCCOMP_OP_FAILED:
+ case HOST_SVCCOMP_OP_SUCCEEDED:
+ setLastOpLastUpdateTime(time);
+ setLastOpEndTime(time);
+ break;
+ case HOST_SVCCOMP_OP_IN_PROGRESS:
+ setLastOpLastUpdateTime(time);
+ break;
+ }
+ }
+ finally {
+ writeLock.unlock();
+ }
+ }
+
+ public ServiceComponentHostImpl(ServiceComponent serviceComponent,
+ String hostName, boolean isClient) {
+ super();
+ if (isClient) {
+ this.stateMachine = clientStateMachineFactory.make(this);
+ } else {
+ this.stateMachine = daemonStateMachineFactory.make(this);
+ }
+ ReadWriteLock rwLock = new ReentrantReadWriteLock();
+ this.readLock = rwLock.readLock();
+ this.writeLock = rwLock.writeLock();
+ this.serviceComponent = serviceComponent;
+ this.hostName = hostName;
+ this.resetLastOpInfo();
+ }
+
+ @Override
+ public State getState() {
+ try {
+ readLock.lock();
+ return stateMachine.getCurrentState();
+ }
+ finally {
+ readLock.unlock();
+ }
+ }
+
+ @Override
+ public void setState(State state) {
+ try {
+ writeLock.lock();
+ stateMachine.setCurrentState(state);
+ }
+ finally {
+ writeLock.unlock();
+ }
+ }
+
+ @Override
+ public void handleEvent(ServiceComponentHostEvent event)
+ throws InvalidStateTransitonException {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Handling ServiceComponentHostEvent event,"
+ + " eventType=" + event.getType().name()
+ + ", event=" + event.toString());
+ }
+ State oldState = getState();
+ try {
+ writeLock.lock();
+ try {
+ stateMachine.doTransition(event.getType(), event);
+ // TODO Audit logs
+ } catch (InvalidStateTransitonException e) {
+ LOG.error("Can't handle ServiceComponentHostEvent event at"
+ + " current state"
+ + ", serviceComponentName=" + this.getServiceComponentName()
+ + ", hostName=" + this.getHostName()
+ + ", currentState=" + oldState
+ + ", eventType=" + event.getType()
+ + ", event=" + event);
+ throw e;
+ }
+ }
+ finally {
+ writeLock.unlock();
+ }
+ if (!oldState.equals(getState())) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("ServiceComponentHost transitioned to a new state"
+ + ", serviceComponentName=" + this.getServiceComponentName()
+ + ", hostName=" + this.getHostName()
+ + ", oldState=" + oldState
+ + ", currentState=" + getState()
+ + ", eventType=" + event.getType().name()
+ + ", event=" + event);
+ }
+ }
+ }
+
+ @Override
+ public List<Job> getJobs() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getServiceComponentName() {
+ return serviceComponent.getName();
+ }
+
+ @Override
+ public String getHostName() {
+ return hostName;
+ }
+
+ /**
+ * @return the lastOpStartTime
+ */
+ public long getLastOpStartTime() {
+ try {
+ readLock.lock();
+ return lastOpStartTime;
+ }
+ finally {
+ readLock.unlock();
+ }
+ }
+
+ /**
+ * @param lastOpStartTime the lastOpStartTime to set
+ */
+ public void setLastOpStartTime(long lastOpStartTime) {
+ try {
+ writeLock.lock();
+ this.lastOpStartTime = lastOpStartTime;
+ }
+ finally {
+ writeLock.unlock();
+ }
+ }
+
+ /**
+ * @return the lastOpEndTime
+ */
+ public long getLastOpEndTime() {
+ try {
+ readLock.lock();
+ return lastOpEndTime;
+ }
+ finally {
+ readLock.unlock();
+ }
+ }
+
+ /**
+ * @param lastOpEndTime the lastOpEndTime to set
+ */
+ public void setLastOpEndTime(long lastOpEndTime) {
+ try {
+ writeLock.lock();
+ this.lastOpEndTime = lastOpEndTime;
+ }
+ finally {
+ writeLock.unlock();
+ }
+ }
+
+ /**
+ * @return the lastOpLastUpdateTime
+ */
+ public long getLastOpLastUpdateTime() {
+ try {
+ readLock.lock();
+ return lastOpLastUpdateTime;
+ }
+ finally {
+ readLock.unlock();
+ }
+ }
+
+ /**
+ * @param lastOpLastUpdateTime the lastOpLastUpdateTime to set
+ */
+ public void setLastOpLastUpdateTime(long lastOpLastUpdateTime) {
+ try {
+ writeLock.lock();
+ this.lastOpLastUpdateTime = lastOpLastUpdateTime;
+ }
+ finally {
+ writeLock.unlock();
+ }
+ }
+
+ @Override
+ public long getClusterId() {
+ return serviceComponent.getClusterId();
+ }
+
+ @Override
+ public String getServiceName() {
+ return serviceComponent.getServiceName();
+ }
+
+ @Override
+ public Map<String, Config> getConfigs() {
+ try {
+ readLock.lock();
+ return Collections.unmodifiableMap(configs);
+ }
+ finally {
+ readLock.unlock();
+ }
+ }
+
+ @Override
+ public void updateConfigs(Map<String, Config> configs) {
+ try {
+ writeLock.lock();
+ this.configs.putAll(configs);
+ }
+ finally {
+ writeLock.unlock();
+ }
+ }
+
+ @Override
+ public StackVersion getStackVersion() {
+ try {
+ readLock.lock();
+ return stackVersion;
+ }
+ finally {
+ readLock.unlock();
+ }
+ }
+
+ @Override
+ public void setStackVersion(StackVersion stackVersion) {
+ try {
+ writeLock.lock();
+ this.stackVersion = stackVersion;
+ }
+ finally {
+ writeLock.unlock();
+ }
+ }
+
+
+ @Override
+ public State getDesiredState() {
+ try {
+ readLock.lock();
+ return desiredState;
+ }
+ finally {
+ readLock.unlock();
+ }
+ }
+
+ @Override
+ public void setDesiredState(State state) {
+ try {
+ writeLock.lock();
+ this.desiredState = state;
+ }
+ finally {
+ writeLock.unlock();
+ }
+ }
+
+ @Override
+ public Map<String, Config> getDesiredConfigs() {
+ try {
+ readLock.lock();
+ return Collections.unmodifiableMap(desiredConfigs);
+ }
+ finally {
+ readLock.unlock();
+ }
+ }
+
+ @Override
+ public void updateDesiredConfigs(Map<String, Config> configs) {
+ try {
+ writeLock.lock();
+ this.desiredConfigs.putAll(configs);
+ }
+ finally {
+ writeLock.unlock();
+ }
+ }
+
+ @Override
+ public StackVersion getDesiredStackVersion() {
+ try {
+ readLock.lock();
+ return desiredStackVersion;
+ }
+ finally {
+ readLock.unlock();
+ }
+ }
+
+ @Override
+ public void setDesiredStackVersion(StackVersion stackVersion) {
+ try {
+ writeLock.lock();
+ this.desiredStackVersion = stackVersion;
+ }
+ finally {
+ writeLock.unlock();
+ }
+ }
+
+ private Map<String, String> getConfigVersions() {
+ try {
+ readLock.lock();
+ Map<String, String> configVersions = new HashMap<String, String>();
+ for (Config c : configs.values()) {
+ configVersions.put(c.getType(), c.getVersionTag());
+ }
+ return configVersions;
+ }
+ finally {
+ readLock.unlock();
+ }
+ }
+
+ @Override
+ public ServiceComponentHostResponse convertToResponse() {
+ try {
+ readLock.lock();
+ ServiceComponentHostResponse r = new ServiceComponentHostResponse(
+ serviceComponent.getClusterName(),
+ serviceComponent.getServiceName(),
+ serviceComponent.getName(),
+ hostName,
+ getConfigVersions(),
+ getState().toString(),
+ getStackVersion().getStackVersion(),
+ getDesiredState().toString());
+ return r;
+ }
+ finally {
+ readLock.unlock();
+ }
+ }
+
+ @Override
+ public String getClusterName() {
+ return serviceComponent.getClusterName();
+ }
+
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostInstallEvent.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostInstallEvent.java?rev=1395430&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostInstallEvent.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostInstallEvent.java Mon Oct 8 01:37:59 2012
@@ -0,0 +1,34 @@
+/**
+ * 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.state.svccomphost;
+
+import org.apache.ambari.server.state.ServiceComponentHostEvent;
+import org.apache.ambari.server.state.ServiceComponentHostEventType;
+
+public class ServiceComponentHostInstallEvent extends
+ ServiceComponentHostEvent {
+
+
+ public ServiceComponentHostInstallEvent(String serviceComponentName,
+ String hostName, long opTimestamp) {
+ super(ServiceComponentHostEventType.HOST_SVCCOMP_INSTALL,
+ serviceComponentName, hostName, opTimestamp);
+ }
+
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostOpFailedEvent.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostOpFailedEvent.java?rev=1395430&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostOpFailedEvent.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostOpFailedEvent.java Mon Oct 8 01:37:59 2012
@@ -0,0 +1,33 @@
+/**
+ * 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.state.svccomphost;
+
+import org.apache.ambari.server.state.ServiceComponentHostEvent;
+import org.apache.ambari.server.state.ServiceComponentHostEventType;
+
+public class ServiceComponentHostOpFailedEvent extends
+ ServiceComponentHostEvent {
+
+ public ServiceComponentHostOpFailedEvent(String serviceComponentName,
+ String hostName, long opTimestamp) {
+ super(ServiceComponentHostEventType.HOST_SVCCOMP_OP_FAILED,
+ serviceComponentName, hostName, opTimestamp);
+ // TODO Auto-generated constructor stub
+ }
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostOpInProgressEvent.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostOpInProgressEvent.java?rev=1395430&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostOpInProgressEvent.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostOpInProgressEvent.java Mon Oct 8 01:37:59 2012
@@ -0,0 +1,34 @@
+/**
+ * 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.state.svccomphost;
+
+import org.apache.ambari.server.state.ServiceComponentHostEvent;
+import org.apache.ambari.server.state.ServiceComponentHostEventType;
+
+public class ServiceComponentHostOpInProgressEvent extends
+ ServiceComponentHostEvent {
+
+ public ServiceComponentHostOpInProgressEvent(String serviceComponentName,
+ String hostName, long opTimestamp) {
+ super(ServiceComponentHostEventType.HOST_SVCCOMP_OP_IN_PROGRESS,
+ serviceComponentName, hostName, opTimestamp);
+ // TODO Auto-generated constructor stub
+ }
+
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostOpRestartedEvent.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostOpRestartedEvent.java?rev=1395430&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostOpRestartedEvent.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostOpRestartedEvent.java Mon Oct 8 01:37:59 2012
@@ -0,0 +1,34 @@
+/**
+ * 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.state.svccomphost;
+
+import org.apache.ambari.server.state.ServiceComponentHostEvent;
+import org.apache.ambari.server.state.ServiceComponentHostEventType;
+
+public class ServiceComponentHostOpRestartedEvent extends
+ ServiceComponentHostEvent {
+
+ public ServiceComponentHostOpRestartedEvent(String serviceComponentName,
+ String hostName, long opTimestamp) {
+ super(ServiceComponentHostEventType.HOST_SVCCOMP_OP_RESTART,
+ serviceComponentName, hostName, opTimestamp);
+ // TODO Auto-generated constructor stub
+ }
+
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostOpSucceededEvent.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostOpSucceededEvent.java?rev=1395430&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostOpSucceededEvent.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostOpSucceededEvent.java Mon Oct 8 01:37:59 2012
@@ -0,0 +1,34 @@
+/**
+ * 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.state.svccomphost;
+
+import org.apache.ambari.server.state.ServiceComponentHostEvent;
+import org.apache.ambari.server.state.ServiceComponentHostEventType;
+
+public class ServiceComponentHostOpSucceededEvent extends
+ ServiceComponentHostEvent {
+
+ public ServiceComponentHostOpSucceededEvent(String serviceComponentName,
+ String hostName, long opTimestamp) {
+ super(ServiceComponentHostEventType.HOST_SVCCOMP_OP_SUCCEEDED,
+ serviceComponentName, hostName, opTimestamp);
+ // TODO Auto-generated constructor stub
+ }
+
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostStartEvent.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostStartEvent.java?rev=1395430&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostStartEvent.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostStartEvent.java Mon Oct 8 01:37:59 2012
@@ -0,0 +1,34 @@
+/**
+ * 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.state.svccomphost;
+
+import org.apache.ambari.server.state.ServiceComponentHostEvent;
+import org.apache.ambari.server.state.ServiceComponentHostEventType;
+
+public class ServiceComponentHostStartEvent extends
+ ServiceComponentHostEvent {
+
+ public ServiceComponentHostStartEvent(String serviceComponentName,
+ String hostName, long opTimestamp) {
+ super(ServiceComponentHostEventType.HOST_SVCCOMP_START,
+ serviceComponentName, hostName, opTimestamp);
+ // TODO Auto-generated constructor stub
+ }
+
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostStopEvent.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostStopEvent.java?rev=1395430&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostStopEvent.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostStopEvent.java Mon Oct 8 01:37:59 2012
@@ -0,0 +1,34 @@
+/**
+ * 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.state.svccomphost;
+
+import org.apache.ambari.server.state.ServiceComponentHostEvent;
+import org.apache.ambari.server.state.ServiceComponentHostEventType;
+
+public class ServiceComponentHostStopEvent extends
+ ServiceComponentHostEvent {
+
+ public ServiceComponentHostStopEvent(String serviceComponentName,
+ String hostName, long opTimestamp) {
+ super(ServiceComponentHostEventType.HOST_SVCCOMP_STOP,
+ serviceComponentName, hostName, opTimestamp);
+ // TODO Auto-generated constructor stub
+ }
+
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostUninstallEvent.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostUninstallEvent.java?rev=1395430&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostUninstallEvent.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostUninstallEvent.java Mon Oct 8 01:37:59 2012
@@ -0,0 +1,34 @@
+/**
+ * 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.state.svccomphost;
+
+import org.apache.ambari.server.state.ServiceComponentHostEvent;
+import org.apache.ambari.server.state.ServiceComponentHostEventType;
+
+public class ServiceComponentHostUninstallEvent extends
+ ServiceComponentHostEvent {
+
+ public ServiceComponentHostUninstallEvent(String serviceComponentName,
+ String hostName, long opTimestamp) {
+ super(ServiceComponentHostEventType.HOST_SVCCOMP_UNINSTALL,
+ serviceComponentName, hostName, opTimestamp);
+ // TODO Auto-generated constructor stub
+ }
+
+}
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostWipeoutEvent.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostWipeoutEvent.java?rev=1395430&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostWipeoutEvent.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostWipeoutEvent.java Mon Oct 8 01:37:59 2012
@@ -0,0 +1,34 @@
+/**
+ * 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.state.svccomphost;
+
+import org.apache.ambari.server.state.ServiceComponentHostEvent;
+import org.apache.ambari.server.state.ServiceComponentHostEventType;
+
+public class ServiceComponentHostWipeoutEvent extends
+ ServiceComponentHostEvent {
+
+ public ServiceComponentHostWipeoutEvent(String serviceComponentName,
+ String hostName, long opTimestamp) {
+ super(ServiceComponentHostEventType.HOST_SVCCOMP_WIPEOUT,
+ serviceComponentName, hostName, opTimestamp);
+ // TODO Auto-generated constructor stub
+ }
+
+}
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyListAdapter.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyListAdapter.java?rev=1395430&r1=1395429&r2=1395430&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyListAdapter.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyListAdapter.java Mon Oct 8 01:37:59 2012
@@ -17,7 +17,6 @@
*/
package org.apache.ambari.server.utils;
-import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
@@ -25,24 +24,25 @@ import java.util.TreeMap;
import javax.xml.bind.annotation.adapters.XmlAdapter;
public class JaxbMapKeyListAdapter extends
- XmlAdapter<List<JaxbMapKeyList>, Map<String, List<String>>> {
+ XmlAdapter<JaxbMapKeyList[], Map<String, List<String>>> {
@Override
- public List<JaxbMapKeyList> marshal(Map<String, List<String>> map)
+ public JaxbMapKeyList[] marshal(Map<String, List<String>> map)
throws Exception {
if (map==null) {
return null;
}
- List<JaxbMapKeyList> list = new ArrayList<JaxbMapKeyList>() ;
+ JaxbMapKeyList[] list = new JaxbMapKeyList[map.size()] ;
+ int index = 0;
for (String key : map.keySet()) {
JaxbMapKeyList jaxbMap = new JaxbMapKeyList(key, map.get(key));
- list.add(jaxbMap);
+ list[index++] = jaxbMap;
}
return list;
}
@Override
- public Map<String, List<String>> unmarshal(List<JaxbMapKeyList> list)
+ public Map<String, List<String>> unmarshal(JaxbMapKeyList[] list)
throws Exception {
if (list == null) {
return null;
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyMap.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyMap.java?rev=1395430&r1=1395429&r2=1395430&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyMap.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyMap.java Mon Oct 8 01:37:59 2012
@@ -17,17 +17,15 @@
*/
package org.apache.ambari.server.utils;
-import java.util.List;
-
import javax.xml.bind.annotation.XmlElement;
public class JaxbMapKeyMap {
@XmlElement public String key;
- @XmlElement public List<JaxbMapKeyVal> value;
+ @XmlElement public JaxbMapKeyVal[] value;
private JaxbMapKeyMap() {}
- public JaxbMapKeyMap(String key, List<JaxbMapKeyVal> value)
+ public JaxbMapKeyMap(String key, JaxbMapKeyVal[] value)
{
this.key = key;
this.value = value;
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyMapAdapter.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyMapAdapter.java?rev=1395430&r1=1395429&r2=1395430&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyMapAdapter.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyMapAdapter.java Mon Oct 8 01:37:59 2012
@@ -25,27 +25,28 @@ import java.util.TreeMap;
import javax.xml.bind.annotation.adapters.XmlAdapter;
public class JaxbMapKeyMapAdapter extends
- XmlAdapter<List<JaxbMapKeyMap>, Map<String, Map<String, String>>> {
+ XmlAdapter<JaxbMapKeyMap[], Map<String, Map<String, String>>> {
private static JaxbMapKeyValAdapter mapAdapter = new JaxbMapKeyValAdapter();
@Override
- public List<JaxbMapKeyMap> marshal(Map<String, Map<String, String>> map)
+ public JaxbMapKeyMap[] marshal(Map<String, Map<String, String>> map)
throws Exception {
if (map == null) {
return null;
}
- List<JaxbMapKeyMap> list = new ArrayList<JaxbMapKeyMap>();
+ JaxbMapKeyMap[] list = new JaxbMapKeyMap[map.size()];
+ int index=0;
for (String key : map.keySet()) {
Map<String, String> value = map.get(key);
- List<JaxbMapKeyVal> keyValList = mapAdapter.marshal(value);
- list.add(new JaxbMapKeyMap(key, keyValList));
+ JaxbMapKeyVal[] keyValList = mapAdapter.marshal(value);
+ list[index++] = new JaxbMapKeyMap(key, keyValList);
}
return list;
}
@Override
- public Map<String, Map<String, String>> unmarshal(List<JaxbMapKeyMap> list)
+ public Map<String, Map<String, String>> unmarshal(JaxbMapKeyMap[] list)
throws Exception {
if (list == null) {
return null;
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyVal.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyVal.java?rev=1395430&r1=1395429&r2=1395430&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyVal.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyVal.java Mon Oct 8 01:37:59 2012
@@ -17,20 +17,13 @@
*/
package org.apache.ambari.server.utils;
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlType;
-@XmlRootElement
-@XmlAccessorType(XmlAccessType.FIELD)
-@XmlType(name = "", propOrder = {})
public class JaxbMapKeyVal {
@XmlElement public String key;
@XmlElement public String value;
- private JaxbMapKeyVal() {}
+ public JaxbMapKeyVal() {}
public JaxbMapKeyVal(String key, String value)
{
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyValAdapter.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyValAdapter.java?rev=1395430&r1=1395429&r2=1395430&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyValAdapter.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/JaxbMapKeyValAdapter.java Mon Oct 8 01:37:59 2012
@@ -17,31 +17,30 @@
*/
package org.apache.ambari.server.utils;
-import java.util.ArrayList;
-import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import javax.xml.bind.annotation.adapters.XmlAdapter;
public class JaxbMapKeyValAdapter extends
- XmlAdapter<List<JaxbMapKeyVal>, Map<String, String>> {
+ XmlAdapter<JaxbMapKeyVal[], Map<String, String>> {
@Override
- public List<JaxbMapKeyVal> marshal(Map<String, String> m) throws Exception {
+ public JaxbMapKeyVal[] marshal(Map<String, String> m) throws Exception {
if (m==null) {
return null;
}
- List<JaxbMapKeyVal> list = new ArrayList<JaxbMapKeyVal>() ;
+ JaxbMapKeyVal[] list = new JaxbMapKeyVal[m.size()] ;
+ int index = 0;
for (String key : m.keySet()) {
JaxbMapKeyVal jaxbMap = new JaxbMapKeyVal(key, m.get(key));
- list.add(jaxbMap);
+ list[index++] = jaxbMap;
}
return list;
}
@Override
- public Map<String, String> unmarshal(List<JaxbMapKeyVal> jm) throws Exception {
+ public Map<String, String> unmarshal(JaxbMapKeyVal[] jm) throws Exception {
if (jm == null) {
return null;
}
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/StageUtils.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/StageUtils.java?rev=1395430&r1=1395429&r2=1395430&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/StageUtils.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/StageUtils.java Mon Oct 8 01:37:59 2012
@@ -17,21 +17,35 @@
*/
package org.apache.ambari.server.utils;
-import java.net.InetSocketAddress;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
+import javax.xml.bind.JAXBException;
+
import org.apache.ambari.server.Role;
import org.apache.ambari.server.actionmanager.HostAction;
import org.apache.ambari.server.actionmanager.HostRoleCommand;
import org.apache.ambari.server.actionmanager.HostRoleStatus;
import org.apache.ambari.server.actionmanager.Stage;
import org.apache.ambari.server.agent.ExecutionCommand;
-import org.apache.ambari.server.state.live.svccomphost.ServiceComponentHostInstallEvent;
+import org.apache.ambari.server.state.svccomphost.ServiceComponentHostInstallEvent;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codehaus.jackson.JsonGenerationException;
+import org.codehaus.jackson.map.AnnotationIntrospector;
+import org.codehaus.jackson.map.JsonMappingException;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.SerializationConfig;
+import org.codehaus.jackson.xc.JaxbAnnotationIntrospector;
public class StageUtils {
+ private static Log LOG = LogFactory.getLog(StageUtils.class);
+
public static String getActionId(long requestId, long stageId) {
return requestId + "-" + stageId;
}
@@ -46,13 +60,17 @@ public class StageUtils {
//For testing only
public static Stage getATestStage(long requestId, long stageId) {
- InetSocketAddress sa = new InetSocketAddress(0);
- String hostname = sa.getAddress().getHostName();
+ String hostname;
+ try {
+ hostname = InetAddress.getLocalHost().getHostName();
+ } catch (UnknownHostException e) {
+ hostname = "host-dummy";
+ }
Stage s = new Stage(requestId, "/tmp", "cluster1");
s.setStageId(stageId);
HostAction ha = new HostAction(hostname);
long now = System.currentTimeMillis();
- HostRoleCommand hrc = new HostRoleCommand(Role.NAMENODE,
+ HostRoleCommand hrc = new HostRoleCommand("HDFS", Role.NAMENODE,
new ServiceComponentHostInstallEvent("NAMENODE", hostname, now));
hrc.setStatus(HostRoleStatus.PENDING);
ha.addHostRoleCommand(hrc);
@@ -77,7 +95,21 @@ public class StageUtils {
Map<String, String> roleParams = new TreeMap<String, String>();
roleParams.put("format", "false");
execCmd.addRoleCommand("NAMENODE", "INSTALL", roleParams);
+ try {
+ LOG.info("Command string = " + StageUtils.jaxbToString(execCmd));
+ } catch (Exception e) {
+ throw new RuntimeException("Could not get string from jaxb",e);
+ }
s.addHostAction(hostname, ha);
return s;
}
+
+ public static String jaxbToString(Object jaxbObj) throws JAXBException,
+ JsonGenerationException, JsonMappingException, IOException {
+ ObjectMapper mapper = new ObjectMapper();
+ AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
+ mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
+ mapper.configure(SerializationConfig.Feature.USE_ANNOTATIONS, true);
+ return mapper.writeValueAsString(jaxbObj);
+ }
}