|
|
@@ -131,12 +131,12 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
|
|
|
State.INSTALLED,
|
|
|
ServiceComponentHostEventType.HOST_SVCCOMP_OP_SUCCEEDED,
|
|
|
new ServiceComponentHostOpCompletedTransition())
|
|
|
-
|
|
|
+
|
|
|
.addTransition(State.INSTALLED,
|
|
|
State.INSTALLED,
|
|
|
ServiceComponentHostEventType.HOST_SVCCOMP_OP_SUCCEEDED,
|
|
|
new ServiceComponentHostOpCompletedTransition())
|
|
|
-
|
|
|
+
|
|
|
.addTransition(State.INSTALLING,
|
|
|
State.INSTALLING,
|
|
|
ServiceComponentHostEventType.HOST_SVCCOMP_OP_IN_PROGRESS,
|
|
|
@@ -202,7 +202,7 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
|
|
|
State.STARTING,
|
|
|
ServiceComponentHostEventType.HOST_SVCCOMP_OP_IN_PROGRESS,
|
|
|
new ServiceComponentHostOpInProgressTransition())
|
|
|
-
|
|
|
+
|
|
|
.addTransition(State.STARTING,
|
|
|
State.STARTING,
|
|
|
ServiceComponentHostEventType.HOST_SVCCOMP_START,
|
|
|
@@ -211,7 +211,7 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
|
|
|
State.STARTED,
|
|
|
ServiceComponentHostEventType.HOST_SVCCOMP_STARTED,
|
|
|
new ServiceComponentHostOpCompletedTransition())
|
|
|
-
|
|
|
+
|
|
|
.addTransition(State.STARTING,
|
|
|
State.INSTALLED,
|
|
|
ServiceComponentHostEventType.HOST_SVCCOMP_OP_FAILED,
|
|
|
@@ -383,7 +383,7 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
|
|
|
State.INSTALLING,
|
|
|
ServiceComponentHostEventType.HOST_SVCCOMP_INSTALL,
|
|
|
new ServiceComponentHostOpStartedTransition())
|
|
|
-
|
|
|
+
|
|
|
.addTransition(State.INSTALLING,
|
|
|
State.INSTALLING,
|
|
|
ServiceComponentHostEventType.HOST_SVCCOMP_OP_IN_PROGRESS,
|
|
|
@@ -557,56 +557,44 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
|
|
|
|
|
|
|
|
|
private void resetLastOpInfo() {
|
|
|
- clusterGlobalLock.readLock().lock();
|
|
|
+ writeLock.lock();
|
|
|
try {
|
|
|
- try {
|
|
|
- writeLock.lock();
|
|
|
- setLastOpStartTime(-1);
|
|
|
- setLastOpLastUpdateTime(-1);
|
|
|
- setLastOpEndTime(-1);
|
|
|
- } finally {
|
|
|
- writeLock.unlock();
|
|
|
- }
|
|
|
+ setLastOpStartTime(-1);
|
|
|
+ setLastOpLastUpdateTime(-1);
|
|
|
+ setLastOpEndTime(-1);
|
|
|
} finally {
|
|
|
- clusterGlobalLock.readLock().unlock();
|
|
|
+ writeLock.unlock();
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
private void updateLastOpInfo(ServiceComponentHostEventType eventType,
|
|
|
long time) {
|
|
|
- clusterGlobalLock.readLock().lock();
|
|
|
+ writeLock.lock();
|
|
|
try {
|
|
|
- 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:
|
|
|
- case HOST_SVCCOMP_STOPPED:
|
|
|
- case HOST_SVCCOMP_STARTED:
|
|
|
- setLastOpLastUpdateTime(time);
|
|
|
- setLastOpEndTime(time);
|
|
|
- break;
|
|
|
- case HOST_SVCCOMP_OP_IN_PROGRESS:
|
|
|
- setLastOpLastUpdateTime(time);
|
|
|
- break;
|
|
|
- }
|
|
|
- } finally {
|
|
|
- writeLock.unlock();
|
|
|
+ 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:
|
|
|
+ case HOST_SVCCOMP_STOPPED:
|
|
|
+ case HOST_SVCCOMP_STARTED:
|
|
|
+ setLastOpLastUpdateTime(time);
|
|
|
+ setLastOpEndTime(time);
|
|
|
+ break;
|
|
|
+ case HOST_SVCCOMP_OP_IN_PROGRESS:
|
|
|
+ setLastOpLastUpdateTime(time);
|
|
|
+ break;
|
|
|
}
|
|
|
} finally {
|
|
|
- clusterGlobalLock.readLock().unlock();
|
|
|
+ writeLock.unlock();
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@AssistedInject
|
|
|
@@ -615,13 +603,13 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
|
|
|
injector.injectMembers(this);
|
|
|
|
|
|
if (serviceComponent.isClientComponent()) {
|
|
|
- this.stateMachine = clientStateMachineFactory.make(this);
|
|
|
+ stateMachine = clientStateMachineFactory.make(this);
|
|
|
} else {
|
|
|
- this.stateMachine = daemonStateMachineFactory.make(this);
|
|
|
+ stateMachine = daemonStateMachineFactory.make(this);
|
|
|
}
|
|
|
|
|
|
this.serviceComponent = serviceComponent;
|
|
|
- this.clusterGlobalLock = serviceComponent.getClusterGlobalLock();
|
|
|
+ clusterGlobalLock = serviceComponent.getClusterGlobalLock();
|
|
|
|
|
|
stateEntity = new HostComponentStateEntity();
|
|
|
stateEntity.setClusterId(serviceComponent.getClusterId());
|
|
|
@@ -646,14 +634,14 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- this.host = clusters.getHost(hostName);
|
|
|
+ host = clusters.getHost(hostName);
|
|
|
} catch (AmbariException e) {
|
|
|
//TODO exception?
|
|
|
LOG.error("Host '{}' was not found" + hostName);
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
|
|
|
- this.resetLastOpInfo();
|
|
|
+ resetLastOpInfo();
|
|
|
}
|
|
|
|
|
|
@AssistedInject
|
|
|
@@ -663,21 +651,21 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
|
|
|
Injector injector) {
|
|
|
injector.injectMembers(this);
|
|
|
this.serviceComponent = serviceComponent;
|
|
|
- this.clusterGlobalLock = serviceComponent.getClusterGlobalLock();
|
|
|
+ clusterGlobalLock = serviceComponent.getClusterGlobalLock();
|
|
|
|
|
|
this.desiredStateEntity = desiredStateEntity;
|
|
|
this.stateEntity = stateEntity;
|
|
|
|
|
|
//TODO implement State Machine init as now type choosing is hardcoded in above code
|
|
|
if (serviceComponent.isClientComponent()) {
|
|
|
- this.stateMachine = clientStateMachineFactory.make(this);
|
|
|
+ stateMachine = clientStateMachineFactory.make(this);
|
|
|
} else {
|
|
|
- this.stateMachine = daemonStateMachineFactory.make(this);
|
|
|
+ stateMachine = daemonStateMachineFactory.make(this);
|
|
|
}
|
|
|
- this.stateMachine.setCurrentState(stateEntity.getCurrentState());
|
|
|
+ stateMachine.setCurrentState(stateEntity.getCurrentState());
|
|
|
|
|
|
try {
|
|
|
- this.host = clusters.getHost(stateEntity.getHostName());
|
|
|
+ host = clusters.getHost(stateEntity.getHostName());
|
|
|
} catch (AmbariException e) {
|
|
|
//TODO exception? impossible due to database restrictions
|
|
|
LOG.error("Host '{}' was not found " + stateEntity.getHostName());
|
|
|
@@ -689,18 +677,9 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
|
|
|
|
|
|
@Override
|
|
|
public State getState() {
|
|
|
- clusterGlobalLock.readLock().lock();
|
|
|
- try {
|
|
|
- readLock.lock();
|
|
|
- try {
|
|
|
- return stateMachine.getCurrentState();
|
|
|
- } finally {
|
|
|
- readLock.unlock();
|
|
|
- }
|
|
|
- } finally {
|
|
|
- clusterGlobalLock.readLock().unlock();
|
|
|
- }
|
|
|
-
|
|
|
+ // there's no reason to lock around the state machine for this SCH since
|
|
|
+ // the state machine is synchronized
|
|
|
+ return stateMachine.getCurrentState();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -743,8 +722,8 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
|
|
|
} catch (InvalidStateTransitionException e) {
|
|
|
LOG.debug("Can't handle ServiceComponentHostEvent event at"
|
|
|
+ " current state"
|
|
|
- + ", serviceComponentName=" + this.getServiceComponentName()
|
|
|
- + ", hostName=" + this.getHostName()
|
|
|
+ + ", serviceComponentName=" + getServiceComponentName()
|
|
|
+ + ", hostName=" + getHostName()
|
|
|
+ ", currentState=" + oldState
|
|
|
+ ", eventType=" + event.getType()
|
|
|
+ ", event=" + event);
|
|
|
@@ -760,8 +739,8 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
|
|
|
if (!oldState.equals(getState())) {
|
|
|
if (LOG.isDebugEnabled()) {
|
|
|
LOG.debug("ServiceComponentHost transitioned to a new state"
|
|
|
- + ", serviceComponentName=" + this.getServiceComponentName()
|
|
|
- + ", hostName=" + this.getHostName()
|
|
|
+ + ", serviceComponentName=" + getServiceComponentName()
|
|
|
+ + ", hostName=" + getHostName()
|
|
|
+ ", oldState=" + oldState
|
|
|
+ ", currentState=" + getState()
|
|
|
+ ", eventType=" + event.getType().name()
|
|
|
@@ -772,48 +751,23 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
|
|
|
|
|
|
@Override
|
|
|
public String getServiceComponentName() {
|
|
|
- clusterGlobalLock.readLock().lock();
|
|
|
- try {
|
|
|
- readLock.lock();
|
|
|
- try {
|
|
|
- return serviceComponent.getName();
|
|
|
- } finally {
|
|
|
- readLock.unlock();
|
|
|
- }
|
|
|
- } finally {
|
|
|
- clusterGlobalLock.readLock().unlock();
|
|
|
- }
|
|
|
+ return serviceComponent.getName();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String getHostName() {
|
|
|
- clusterGlobalLock.readLock().lock();
|
|
|
- try {
|
|
|
- readLock.lock();
|
|
|
- try {
|
|
|
- return host.getHostName();
|
|
|
- } finally {
|
|
|
- readLock.unlock();
|
|
|
- }
|
|
|
- } finally {
|
|
|
- clusterGlobalLock.readLock().unlock();
|
|
|
- }
|
|
|
+ return host.getHostName();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @return the lastOpStartTime
|
|
|
*/
|
|
|
public long getLastOpStartTime() {
|
|
|
- clusterGlobalLock.readLock().lock();
|
|
|
+ readLock.lock();
|
|
|
try {
|
|
|
- readLock.lock();
|
|
|
- try {
|
|
|
- return lastOpStartTime;
|
|
|
- } finally {
|
|
|
- readLock.unlock();
|
|
|
- }
|
|
|
+ return lastOpStartTime;
|
|
|
} finally {
|
|
|
- clusterGlobalLock.readLock().unlock();
|
|
|
+ readLock.unlock();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -821,16 +775,11 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
|
|
|
* @param lastOpStartTime the lastOpStartTime to set
|
|
|
*/
|
|
|
public void setLastOpStartTime(long lastOpStartTime) {
|
|
|
- clusterGlobalLock.readLock().lock();
|
|
|
+ writeLock.lock();
|
|
|
try {
|
|
|
- writeLock.lock();
|
|
|
- try {
|
|
|
- this.lastOpStartTime = lastOpStartTime;
|
|
|
- } finally {
|
|
|
- writeLock.unlock();
|
|
|
- }
|
|
|
+ this.lastOpStartTime = lastOpStartTime;
|
|
|
} finally {
|
|
|
- clusterGlobalLock.readLock().unlock();
|
|
|
+ writeLock.unlock();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -838,16 +787,11 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
|
|
|
* @return the lastOpEndTime
|
|
|
*/
|
|
|
public long getLastOpEndTime() {
|
|
|
- clusterGlobalLock.readLock().lock();
|
|
|
+ readLock.lock();
|
|
|
try {
|
|
|
- readLock.lock();
|
|
|
- try {
|
|
|
- return lastOpEndTime;
|
|
|
- } finally {
|
|
|
- readLock.unlock();
|
|
|
- }
|
|
|
+ return lastOpEndTime;
|
|
|
} finally {
|
|
|
- clusterGlobalLock.readLock().unlock();
|
|
|
+ readLock.unlock();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -855,16 +799,11 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
|
|
|
* @param lastOpEndTime the lastOpEndTime to set
|
|
|
*/
|
|
|
public void setLastOpEndTime(long lastOpEndTime) {
|
|
|
- clusterGlobalLock.readLock().lock();
|
|
|
+ writeLock.lock();
|
|
|
try {
|
|
|
- writeLock.lock();
|
|
|
- try {
|
|
|
- this.lastOpEndTime = lastOpEndTime;
|
|
|
- } finally {
|
|
|
- writeLock.unlock();
|
|
|
- }
|
|
|
+ this.lastOpEndTime = lastOpEndTime;
|
|
|
} finally {
|
|
|
- clusterGlobalLock.readLock().unlock();
|
|
|
+ writeLock.unlock();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -872,16 +811,11 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
|
|
|
* @return the lastOpLastUpdateTime
|
|
|
*/
|
|
|
public long getLastOpLastUpdateTime() {
|
|
|
- clusterGlobalLock.readLock().lock();
|
|
|
+ readLock.lock();
|
|
|
try {
|
|
|
- readLock.lock();
|
|
|
- try {
|
|
|
- return lastOpLastUpdateTime;
|
|
|
- } finally {
|
|
|
- readLock.unlock();
|
|
|
- }
|
|
|
+ return lastOpLastUpdateTime;
|
|
|
} finally {
|
|
|
- clusterGlobalLock.readLock().unlock();
|
|
|
+ readLock.unlock();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -889,250 +823,157 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
|
|
|
* @param lastOpLastUpdateTime the lastOpLastUpdateTime to set
|
|
|
*/
|
|
|
public void setLastOpLastUpdateTime(long lastOpLastUpdateTime) {
|
|
|
- clusterGlobalLock.readLock().lock();
|
|
|
+ writeLock.lock();
|
|
|
try {
|
|
|
- writeLock.lock();
|
|
|
- try {
|
|
|
- this.lastOpLastUpdateTime = lastOpLastUpdateTime;
|
|
|
- } finally {
|
|
|
- writeLock.unlock();
|
|
|
- }
|
|
|
+ this.lastOpLastUpdateTime = lastOpLastUpdateTime;
|
|
|
} finally {
|
|
|
- clusterGlobalLock.readLock().unlock();
|
|
|
+ writeLock.unlock();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public long getClusterId() {
|
|
|
- clusterGlobalLock.readLock().lock();
|
|
|
- try {
|
|
|
- readLock.lock();
|
|
|
- try {
|
|
|
- return serviceComponent.getClusterId();
|
|
|
- } finally {
|
|
|
- readLock.unlock();
|
|
|
- }
|
|
|
- } finally {
|
|
|
- clusterGlobalLock.readLock().unlock();
|
|
|
- }
|
|
|
+ return serviceComponent.getClusterId();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String getServiceName() {
|
|
|
- clusterGlobalLock.readLock().lock();
|
|
|
- try {
|
|
|
- readLock.lock();
|
|
|
- try {
|
|
|
- return serviceComponent.getServiceName();
|
|
|
- } finally {
|
|
|
- readLock.unlock();
|
|
|
- }
|
|
|
- } finally {
|
|
|
- clusterGlobalLock.readLock().unlock();
|
|
|
- }
|
|
|
+ return serviceComponent.getServiceName();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public StackId getStackVersion() {
|
|
|
- clusterGlobalLock.readLock().lock();
|
|
|
+ readLock.lock();
|
|
|
try {
|
|
|
- readLock.lock();
|
|
|
- try {
|
|
|
- return gson.fromJson(stateEntity.getCurrentStackVersion(), StackId.class);
|
|
|
- } finally {
|
|
|
- readLock.unlock();
|
|
|
- }
|
|
|
+ return gson.fromJson(stateEntity.getCurrentStackVersion(), StackId.class);
|
|
|
} finally {
|
|
|
- clusterGlobalLock.readLock().unlock();
|
|
|
+ readLock.unlock();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void setStackVersion(StackId stackVersion) {
|
|
|
- clusterGlobalLock.readLock().lock();
|
|
|
+ writeLock.lock();
|
|
|
try {
|
|
|
- writeLock.lock();
|
|
|
- try {
|
|
|
- stateEntity.setCurrentStackVersion(gson.toJson(stackVersion));
|
|
|
- saveIfPersisted();
|
|
|
- } finally {
|
|
|
- writeLock.unlock();
|
|
|
- }
|
|
|
+ stateEntity.setCurrentStackVersion(gson.toJson(stackVersion));
|
|
|
+ saveIfPersisted();
|
|
|
} finally {
|
|
|
- clusterGlobalLock.readLock().unlock();
|
|
|
+ writeLock.unlock();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public State getDesiredState() {
|
|
|
- clusterGlobalLock.readLock().lock();
|
|
|
+ readLock.lock();
|
|
|
try {
|
|
|
- readLock.lock();
|
|
|
- try {
|
|
|
- return desiredStateEntity.getDesiredState();
|
|
|
- } finally {
|
|
|
- readLock.unlock();
|
|
|
- }
|
|
|
+ return desiredStateEntity.getDesiredState();
|
|
|
} finally {
|
|
|
- clusterGlobalLock.readLock().unlock();
|
|
|
+ readLock.unlock();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void setDesiredState(State state) {
|
|
|
- clusterGlobalLock.readLock().lock();
|
|
|
+ writeLock.lock();
|
|
|
try {
|
|
|
- writeLock.lock();
|
|
|
- try {
|
|
|
- desiredStateEntity.setDesiredState(state);
|
|
|
- saveIfPersisted();
|
|
|
- } finally {
|
|
|
- writeLock.unlock();
|
|
|
- }
|
|
|
+ desiredStateEntity.setDesiredState(state);
|
|
|
+ saveIfPersisted();
|
|
|
} finally {
|
|
|
- clusterGlobalLock.readLock().unlock();
|
|
|
+ writeLock.unlock();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public StackId getDesiredStackVersion() {
|
|
|
- clusterGlobalLock.readLock().lock();
|
|
|
+ readLock.lock();
|
|
|
try {
|
|
|
- readLock.lock();
|
|
|
- try {
|
|
|
- return gson.fromJson(desiredStateEntity.getDesiredStackVersion(), StackId.class);
|
|
|
- } finally {
|
|
|
- readLock.unlock();
|
|
|
- }
|
|
|
+ return gson.fromJson(desiredStateEntity.getDesiredStackVersion(),
|
|
|
+ StackId.class);
|
|
|
} finally {
|
|
|
- clusterGlobalLock.readLock().unlock();
|
|
|
+ readLock.unlock();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void setDesiredStackVersion(StackId stackVersion) {
|
|
|
- clusterGlobalLock.readLock().lock();
|
|
|
+ writeLock.lock();
|
|
|
try {
|
|
|
- writeLock.lock();
|
|
|
- try {
|
|
|
- desiredStateEntity.setDesiredStackVersion(gson.toJson(stackVersion));
|
|
|
- saveIfPersisted();
|
|
|
- } finally {
|
|
|
- writeLock.unlock();
|
|
|
- }
|
|
|
+ desiredStateEntity.setDesiredStackVersion(gson.toJson(stackVersion));
|
|
|
+ saveIfPersisted();
|
|
|
} finally {
|
|
|
- clusterGlobalLock.readLock().unlock();
|
|
|
+ writeLock.unlock();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public HostComponentAdminState getComponentAdminState() {
|
|
|
- clusterGlobalLock.readLock().lock();
|
|
|
+ readLock.lock();
|
|
|
try {
|
|
|
- readLock.lock();
|
|
|
- try {
|
|
|
- HostComponentAdminState adminState = desiredStateEntity.getAdminState();
|
|
|
- if (adminState == null
|
|
|
- && !serviceComponent.isClientComponent() && !serviceComponent.isMasterComponent()) {
|
|
|
- adminState = HostComponentAdminState.INSERVICE;
|
|
|
- }
|
|
|
- return adminState;
|
|
|
- } finally {
|
|
|
- readLock.unlock();
|
|
|
+ HostComponentAdminState adminState = desiredStateEntity.getAdminState();
|
|
|
+ if (adminState == null && !serviceComponent.isClientComponent()
|
|
|
+ && !serviceComponent.isMasterComponent()) {
|
|
|
+ adminState = HostComponentAdminState.INSERVICE;
|
|
|
}
|
|
|
+ return adminState;
|
|
|
} finally {
|
|
|
- clusterGlobalLock.readLock().unlock();
|
|
|
+ readLock.unlock();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void setComponentAdminState(HostComponentAdminState attribute) {
|
|
|
- clusterGlobalLock.readLock().lock();
|
|
|
+ writeLock.lock();
|
|
|
try {
|
|
|
- writeLock.lock();
|
|
|
- try {
|
|
|
- desiredStateEntity.setAdminState(attribute);
|
|
|
- saveIfPersisted();
|
|
|
- } finally {
|
|
|
- writeLock.unlock();
|
|
|
- }
|
|
|
+ desiredStateEntity.setAdminState(attribute);
|
|
|
+ saveIfPersisted();
|
|
|
} finally {
|
|
|
- clusterGlobalLock.readLock().unlock();
|
|
|
+ writeLock.unlock();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public ServiceComponentHostResponse convertToResponse() {
|
|
|
- clusterGlobalLock.readLock().lock();
|
|
|
+ readLock.lock();
|
|
|
try {
|
|
|
- readLock.lock();
|
|
|
- try {
|
|
|
- ServiceComponentHostResponse r = new ServiceComponentHostResponse(
|
|
|
- serviceComponent.getClusterName(),
|
|
|
- serviceComponent.getServiceName(),
|
|
|
- serviceComponent.getName(),
|
|
|
- getHostName(),
|
|
|
- getState().toString(),
|
|
|
- getStackVersion().getStackId(),
|
|
|
- getDesiredState().toString(),
|
|
|
- getDesiredStackVersion().getStackId(),
|
|
|
- getComponentAdminState());
|
|
|
-
|
|
|
- r.setActualConfigs(actualConfigs);
|
|
|
+ ServiceComponentHostResponse r = new ServiceComponentHostResponse(
|
|
|
+ serviceComponent.getClusterName(), serviceComponent.getServiceName(),
|
|
|
+ serviceComponent.getName(), getHostName(), getState().toString(),
|
|
|
+ getStackVersion().getStackId(), getDesiredState().toString(),
|
|
|
+ getDesiredStackVersion().getStackId(), getComponentAdminState());
|
|
|
|
|
|
- try {
|
|
|
- r.setStaleConfig(helper.isStaleConfigs(this));
|
|
|
- } catch (Exception e) {
|
|
|
- LOG.error("Could not determine stale config", e);
|
|
|
- }
|
|
|
+ r.setActualConfigs(actualConfigs);
|
|
|
|
|
|
- return r;
|
|
|
- } finally {
|
|
|
- readLock.unlock();
|
|
|
+ try {
|
|
|
+ r.setStaleConfig(helper.isStaleConfigs(this));
|
|
|
+ } catch (Exception e) {
|
|
|
+ LOG.error("Could not determine stale config", e);
|
|
|
}
|
|
|
+
|
|
|
+ return r;
|
|
|
} finally {
|
|
|
- clusterGlobalLock.readLock().unlock();
|
|
|
+ readLock.unlock();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String getClusterName() {
|
|
|
- clusterGlobalLock.readLock().lock();
|
|
|
- try {
|
|
|
- readLock.lock();
|
|
|
- try {
|
|
|
- return serviceComponent.getClusterName();
|
|
|
- } finally {
|
|
|
- readLock.unlock();
|
|
|
- }
|
|
|
- } finally {
|
|
|
- clusterGlobalLock.readLock().unlock();
|
|
|
- }
|
|
|
-
|
|
|
+ return serviceComponent.getClusterName();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void debugDump(StringBuilder sb) {
|
|
|
- clusterGlobalLock.readLock().lock();
|
|
|
+ readLock.lock();
|
|
|
try {
|
|
|
- readLock.lock();
|
|
|
- try {
|
|
|
- sb.append("ServiceComponentHost={ hostname=").append(getHostName())
|
|
|
- .append(", serviceComponentName=").append(serviceComponent.getName())
|
|
|
- .append(", clusterName=").append(serviceComponent.getClusterName())
|
|
|
- .append(", serviceName=").append(serviceComponent.getServiceName())
|
|
|
- .append(", desiredStackVersion=").append(getDesiredStackVersion())
|
|
|
- .append(", desiredState=").append(getDesiredState())
|
|
|
- .append(", stackVersion=").append(getStackVersion())
|
|
|
- .append(", state=").append(getState())
|
|
|
- .append(" }");
|
|
|
- } finally {
|
|
|
- readLock.unlock();
|
|
|
- }
|
|
|
+ sb.append("ServiceComponentHost={ hostname=").append(getHostName()).append(
|
|
|
+ ", serviceComponentName=").append(serviceComponent.getName()).append(
|
|
|
+ ", clusterName=").append(serviceComponent.getClusterName()).append(
|
|
|
+ ", serviceName=").append(serviceComponent.getServiceName()).append(
|
|
|
+ ", desiredStackVersion=").append(getDesiredStackVersion()).append(
|
|
|
+ ", desiredState=").append(getDesiredState()).append(", stackVersion=").append(
|
|
|
+ getStackVersion()).append(", state=").append(getState()).append(" }");
|
|
|
} finally {
|
|
|
- clusterGlobalLock.readLock().unlock();
|
|
|
+ readLock.unlock();
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -1153,12 +994,23 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
|
|
|
|
|
|
@Override
|
|
|
public void persist() {
|
|
|
- clusterGlobalLock.readLock().lock();
|
|
|
+ boolean clusterWriteLockAcquired = false;
|
|
|
+ if (!persisted) {
|
|
|
+ clusterGlobalLock.writeLock().lock();
|
|
|
+ clusterWriteLockAcquired = true;
|
|
|
+ }
|
|
|
+
|
|
|
try {
|
|
|
writeLock.lock();
|
|
|
try {
|
|
|
if (!persisted) {
|
|
|
+ // persist the new cluster topology and then release the cluster lock
|
|
|
+ // as it has no more bearing on the rest of this persist() method
|
|
|
persistEntities();
|
|
|
+ clusterGlobalLock.writeLock().unlock();
|
|
|
+ clusterWriteLockAcquired = false;
|
|
|
+
|
|
|
+ // these shoudl still be done with the internal lock
|
|
|
refresh();
|
|
|
host.refresh();
|
|
|
serviceComponent.refresh();
|
|
|
@@ -1170,9 +1022,10 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
|
|
|
writeLock.unlock();
|
|
|
}
|
|
|
} finally {
|
|
|
- clusterGlobalLock.readLock().unlock();
|
|
|
+ if (clusterWriteLockAcquired) {
|
|
|
+ clusterGlobalLock.writeLock().unlock();
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Transactional
|
|
|
@@ -1204,33 +1057,27 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public void refresh() {
|
|
|
- clusterGlobalLock.readLock().lock();
|
|
|
+ writeLock.lock();
|
|
|
try {
|
|
|
- writeLock.lock();
|
|
|
- try {
|
|
|
- if (isPersisted()) {
|
|
|
- HostComponentStateEntityPK pk = new HostComponentStateEntityPK();
|
|
|
- HostComponentDesiredStateEntityPK dpk = new HostComponentDesiredStateEntityPK();
|
|
|
- pk.setClusterId(getClusterId());
|
|
|
- pk.setComponentName(getServiceComponentName());
|
|
|
- pk.setServiceName(getServiceName());
|
|
|
- pk.setHostName(getHostName());
|
|
|
- dpk.setClusterId(getClusterId());
|
|
|
- dpk.setComponentName(getServiceComponentName());
|
|
|
- dpk.setServiceName(getServiceName());
|
|
|
- dpk.setHostName(getHostName());
|
|
|
- stateEntity = hostComponentStateDAO.findByPK(pk);
|
|
|
- desiredStateEntity = hostComponentDesiredStateDAO.findByPK(dpk);
|
|
|
- hostComponentStateDAO.refresh(stateEntity);
|
|
|
- hostComponentDesiredStateDAO.refresh(desiredStateEntity);
|
|
|
- }
|
|
|
- } finally {
|
|
|
- writeLock.unlock();
|
|
|
+ if (isPersisted()) {
|
|
|
+ HostComponentStateEntityPK pk = new HostComponentStateEntityPK();
|
|
|
+ HostComponentDesiredStateEntityPK dpk = new HostComponentDesiredStateEntityPK();
|
|
|
+ pk.setClusterId(getClusterId());
|
|
|
+ pk.setComponentName(getServiceComponentName());
|
|
|
+ pk.setServiceName(getServiceName());
|
|
|
+ pk.setHostName(getHostName());
|
|
|
+ dpk.setClusterId(getClusterId());
|
|
|
+ dpk.setComponentName(getServiceComponentName());
|
|
|
+ dpk.setServiceName(getServiceName());
|
|
|
+ dpk.setHostName(getHostName());
|
|
|
+ stateEntity = hostComponentStateDAO.findByPK(pk);
|
|
|
+ desiredStateEntity = hostComponentDesiredStateDAO.findByPK(dpk);
|
|
|
+ hostComponentStateDAO.refresh(stateEntity);
|
|
|
+ hostComponentDesiredStateDAO.refresh(desiredStateEntity);
|
|
|
}
|
|
|
} finally {
|
|
|
- clusterGlobalLock.readLock().unlock();
|
|
|
+ writeLock.unlock();
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Transactional
|
|
|
@@ -1244,19 +1091,21 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
|
|
|
@Override
|
|
|
public boolean canBeRemoved() {
|
|
|
clusterGlobalLock.readLock().lock();
|
|
|
+ boolean schLockAcquired = false;
|
|
|
try {
|
|
|
- readLock.lock();
|
|
|
- try {
|
|
|
-
|
|
|
- return (getState().isRemovableState());
|
|
|
+ // if unable to read, then writers are writing; cannot remove SCH
|
|
|
+ schLockAcquired = readLock.tryLock();
|
|
|
+ if (!schLockAcquired) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- } finally {
|
|
|
+ return (getState().isRemovableState());
|
|
|
+ } finally {
|
|
|
+ if (schLockAcquired) {
|
|
|
readLock.unlock();
|
|
|
}
|
|
|
- } finally {
|
|
|
clusterGlobalLock.readLock().unlock();
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -1269,7 +1118,7 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
|
|
|
removeEntities();
|
|
|
persisted = false;
|
|
|
}
|
|
|
- clusters.getCluster(this.getClusterName()).removeServiceComponentHost(this);
|
|
|
+ clusters.getCluster(getClusterName()).removeServiceComponentHost(this);
|
|
|
} catch (AmbariException ex) {
|
|
|
if (LOG.isDebugEnabled()) {
|
|
|
LOG.error(ex.getMessage());
|
|
|
@@ -1301,7 +1150,7 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
|
|
|
|
|
|
hostComponentDesiredStateDAO.removeByPK(desiredPK);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public void updateActualConfigs(Map<String, Map<String, String>> configTags) {
|
|
|
Map<Long, ConfigGroup> configGroupMap;
|
|
|
@@ -1314,165 +1163,120 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- clusterGlobalLock.readLock().lock();
|
|
|
+ writeLock.lock();
|
|
|
try {
|
|
|
- writeLock.lock();
|
|
|
- try {
|
|
|
- LOG.debug("Updating actual config tags: " + configTags);
|
|
|
- actualConfigs = new HashMap<String, HostConfig>();
|
|
|
-
|
|
|
- for (Entry<String, Map<String, String>> entry : configTags.entrySet()) {
|
|
|
- String type = entry.getKey();
|
|
|
- Map<String, String> values = new HashMap<String, String>(entry.getValue());
|
|
|
-
|
|
|
- String tag = values.get(ConfigHelper.CLUSTER_DEFAULT_TAG);
|
|
|
- values.remove(ConfigHelper.CLUSTER_DEFAULT_TAG);
|
|
|
-
|
|
|
- HostConfig hc = new HostConfig();
|
|
|
- hc.setDefaultVersionTag(tag);
|
|
|
- actualConfigs.put(type, hc);
|
|
|
-
|
|
|
- if (!values.isEmpty()) {
|
|
|
- for (Entry<String, String> overrideEntry : values.entrySet()) {
|
|
|
- Long groupId = Long.parseLong(overrideEntry.getKey());
|
|
|
- hc.getConfigGroupOverrides().put(groupId, overrideEntry.getValue());
|
|
|
- if (!configGroupMap.containsKey(groupId)) {
|
|
|
- LOG.debug("Config group does not exist, id = " + groupId);
|
|
|
- }
|
|
|
+ LOG.debug("Updating actual config tags: " + configTags);
|
|
|
+ actualConfigs = new HashMap<String, HostConfig>();
|
|
|
+
|
|
|
+ for (Entry<String, Map<String, String>> entry : configTags.entrySet()) {
|
|
|
+ String type = entry.getKey();
|
|
|
+ Map<String, String> values = new HashMap<String, String>(
|
|
|
+ entry.getValue());
|
|
|
+
|
|
|
+ String tag = values.get(ConfigHelper.CLUSTER_DEFAULT_TAG);
|
|
|
+ values.remove(ConfigHelper.CLUSTER_DEFAULT_TAG);
|
|
|
+
|
|
|
+ HostConfig hc = new HostConfig();
|
|
|
+ hc.setDefaultVersionTag(tag);
|
|
|
+ actualConfigs.put(type, hc);
|
|
|
+
|
|
|
+ if (!values.isEmpty()) {
|
|
|
+ for (Entry<String, String> overrideEntry : values.entrySet()) {
|
|
|
+ Long groupId = Long.parseLong(overrideEntry.getKey());
|
|
|
+ hc.getConfigGroupOverrides().put(groupId, overrideEntry.getValue());
|
|
|
+ if (!configGroupMap.containsKey(groupId)) {
|
|
|
+ LOG.debug("Config group does not exist, id = " + groupId);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- } finally {
|
|
|
- writeLock.unlock();
|
|
|
}
|
|
|
} finally {
|
|
|
- clusterGlobalLock.readLock().unlock();
|
|
|
+ writeLock.unlock();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public Map<String, HostConfig> getActualConfigs() {
|
|
|
- clusterGlobalLock.readLock().lock();
|
|
|
+ readLock.lock();
|
|
|
try {
|
|
|
- readLock.lock();
|
|
|
- try {
|
|
|
- return actualConfigs;
|
|
|
- } finally {
|
|
|
- readLock.unlock();
|
|
|
- }
|
|
|
+ return actualConfigs;
|
|
|
} finally {
|
|
|
- clusterGlobalLock.readLock().unlock();
|
|
|
+ readLock.unlock();
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public HostState getHostState() {
|
|
|
- clusterGlobalLock.readLock().lock();
|
|
|
+ readLock.lock();
|
|
|
try {
|
|
|
- readLock.lock();
|
|
|
- try {
|
|
|
- return host.getState();
|
|
|
- } finally {
|
|
|
- readLock.unlock();
|
|
|
- }
|
|
|
+ return host.getState();
|
|
|
} finally {
|
|
|
- clusterGlobalLock.readLock().unlock();
|
|
|
+ readLock.unlock();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public void setMaintenanceState(MaintenanceState state) {
|
|
|
- clusterGlobalLock.readLock().lock();
|
|
|
+ writeLock.lock();
|
|
|
try {
|
|
|
- writeLock.lock();
|
|
|
- try {
|
|
|
- desiredStateEntity.setMaintenanceState(state);
|
|
|
- saveIfPersisted();
|
|
|
- } finally {
|
|
|
- writeLock.unlock();
|
|
|
- }
|
|
|
+ desiredStateEntity.setMaintenanceState(state);
|
|
|
+ saveIfPersisted();
|
|
|
} finally {
|
|
|
- clusterGlobalLock.readLock().unlock();
|
|
|
+ writeLock.unlock();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public MaintenanceState getMaintenanceState() {
|
|
|
- clusterGlobalLock.readLock().lock();
|
|
|
+ readLock.lock();
|
|
|
try {
|
|
|
- readLock.lock();
|
|
|
- try {
|
|
|
- return desiredStateEntity.getMaintenanceState();
|
|
|
- } finally {
|
|
|
- readLock.unlock();
|
|
|
- }
|
|
|
+ return desiredStateEntity.getMaintenanceState();
|
|
|
} finally {
|
|
|
- clusterGlobalLock.readLock().unlock();
|
|
|
+ readLock.unlock();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
public void setProcesses(List<Map<String, String>> procs) {
|
|
|
- clusterGlobalLock.readLock().lock();
|
|
|
+ writeLock.lock();
|
|
|
try {
|
|
|
- writeLock.lock();
|
|
|
- try {
|
|
|
- processes = Collections.unmodifiableList(procs);
|
|
|
- } finally {
|
|
|
- writeLock.unlock();
|
|
|
- }
|
|
|
+ processes = Collections.unmodifiableList(procs);
|
|
|
} finally {
|
|
|
- clusterGlobalLock.readLock().unlock();
|
|
|
+ writeLock.unlock();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- @Override
|
|
|
+
|
|
|
+ @Override
|
|
|
public List<Map<String, String>> getProcesses() {
|
|
|
- clusterGlobalLock.readLock().lock();
|
|
|
+ readLock.lock();
|
|
|
try {
|
|
|
- readLock.lock();
|
|
|
- try {
|
|
|
- return processes;
|
|
|
- } finally {
|
|
|
- readLock.unlock();
|
|
|
- }
|
|
|
+ return processes;
|
|
|
} finally {
|
|
|
- clusterGlobalLock.readLock().unlock();
|
|
|
+ readLock.unlock();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public boolean isRestartRequired() {
|
|
|
- clusterGlobalLock.readLock().lock();
|
|
|
+ readLock.lock();
|
|
|
try {
|
|
|
- readLock.lock();
|
|
|
- try {
|
|
|
- return desiredStateEntity.isRestartRequired();
|
|
|
- } finally {
|
|
|
- readLock.unlock();
|
|
|
- }
|
|
|
+ return desiredStateEntity.isRestartRequired();
|
|
|
} finally {
|
|
|
- clusterGlobalLock.readLock().unlock();
|
|
|
+ readLock.unlock();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void setRestartRequired(boolean restartRequired) {
|
|
|
- clusterGlobalLock.readLock().lock();
|
|
|
+ writeLock.lock();
|
|
|
try {
|
|
|
- writeLock.lock();
|
|
|
- try {
|
|
|
- desiredStateEntity.setRestartRequired(restartRequired);
|
|
|
- saveIfPersisted();
|
|
|
- helper.invalidateStaleConfigsCache(this);
|
|
|
- } finally {
|
|
|
- writeLock.unlock();
|
|
|
- }
|
|
|
+ desiredStateEntity.setRestartRequired(restartRequired);
|
|
|
+ saveIfPersisted();
|
|
|
+ helper.invalidateStaleConfigsCache(this);
|
|
|
} finally {
|
|
|
- clusterGlobalLock.readLock().unlock();
|
|
|
+ writeLock.unlock();
|
|
|
}
|
|
|
}
|
|
|
}
|