Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #9251: Infamous "Server cannot be contacted at this time" when trying to access node details of a deleted node #1291

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,37 +98,28 @@ class ShowNodeDetailsFromNode(
private[this] val uuidGen = RudderConfig.stringUuidGenerator
private[this] val nodeRepo = RudderConfig.woNodeRepository
private[this] val asyncDeploymentAgent = RudderConfig.asyncDeploymentAgent
private[this] val configService = RudderConfig.configService
private[this] var nodeInfo = nodeInfoService.getNodeInfo(nodeId) match {
case Full(Some(info)) => info
case eb : EmptyBox =>
val e = eb ?~! s"Could not get Node '${nodeId.value}' details"
logger.error(e.messageChain)
throw new Exception(e.messageChain)
case Full(None) =>
val error = s"Could not get Node '${nodeId.value}' details because it does not exist"
logger.error(error)
throw new Exception(error)
}
private[this] val configService = RudderConfig.configService
private[this] var boxNodeInfo = nodeInfoService.getNodeInfo(nodeId)

def extendsAt = SnippetExtensionKey(classOf[ShowNodeDetailsFromNode].getSimpleName)

def complianceModeEditForm = {
def complianceModeEditForm(nodeInfo : NodeInfo) = {
val (globalMode, nodeMode) = {
val modes = getHeartBeat
val modes = getHeartBeat(nodeInfo)
(modes.map(_._1),modes.map(_._2))
}

new ComplianceModeEditForm(
nodeMode
, saveHeart
, saveHeart(nodeInfo)
, () => Unit
, globalMode
)
}
def getHeartBeat : Box[(GlobalComplianceMode,NodeComplianceMode)] = {
def getHeartBeat(nodeInfo : NodeInfo) : Box[(GlobalComplianceMode,NodeComplianceMode)] = {
for {
globalMode <- configService.rudder_compliance_mode()

} yield {
// If heartbeat is not overriden, we revert to the default one
val defaultHeartBeat = HeartbeatConfiguration(false, globalMode.heartbeatPeriod)
Expand All @@ -138,10 +129,10 @@ class ShowNodeDetailsFromNode(
}
}

def saveHeart(complianceMode : NodeComplianceMode) : Box[Unit] = {
def saveHeart(nodeInfo : NodeInfo)( complianceMode : NodeComplianceMode) : Box[Unit] = {
val heartbeatConfiguration = HeartbeatConfiguration(complianceMode.overrideGlobal, complianceMode.heartbeatPeriod)
val modId = ModificationId(uuidGen.newUuid)
nodeInfo = nodeInfo.copy( nodeInfo.node.copy( nodeReportingConfiguration = nodeInfo.node.nodeReportingConfiguration.copy(heartbeatConfiguration = Some(heartbeatConfiguration))))
boxNodeInfo = Full(Some(nodeInfo.copy( nodeInfo.node.copy( nodeReportingConfiguration = nodeInfo.node.nodeReportingConfiguration.copy(heartbeatConfiguration = Some(heartbeatConfiguration))))))
for {
result <- nodeRepo.updateNode(nodeInfo.node, modId, CurrentUser.getActor, None)
} yield {
Expand All @@ -151,9 +142,9 @@ class ShowNodeDetailsFromNode(

def agentPolicyModeEditForm = new AgentPolicyModeEditForm()

def agentScheduleEditForm = new AgentScheduleEditForm(
() => getSchedule
, saveSchedule
def agentScheduleEditForm(nodeInfo : NodeInfo) = new AgentScheduleEditForm(
() => getSchedule(nodeInfo)
, saveSchedule(nodeInfo)
, () => Unit
, () => Some(getGlobalSchedule)
)
Expand All @@ -176,14 +167,14 @@ class ShowNodeDetailsFromNode(
}

val emptyInterval = AgentRunInterval(Some(false), 5, 0, 0, 0) // if everything fails, we fall back to the default entry
def getSchedule : Box[AgentRunInterval] = {
def getSchedule(nodeInfo : NodeInfo) : Box[AgentRunInterval] = {
Full( nodeInfo.nodeReportingConfiguration.agentRunInterval.getOrElse(getGlobalSchedule.getOrElse(emptyInterval)))
}

def saveSchedule(schedule: AgentRunInterval) : Box[Unit] = {
def saveSchedule(nodeInfo : NodeInfo)( schedule: AgentRunInterval) : Box[Unit] = {
val modId = ModificationId(uuidGen.newUuid)
val user = CurrentUser.getActor
nodeInfo = nodeInfo.copy( nodeInfo.node.copy( nodeReportingConfiguration = nodeInfo.node.nodeReportingConfiguration.copy(agentRunInterval = Some(schedule))))
boxNodeInfo = Full(Some(nodeInfo.copy( nodeInfo.node.copy( nodeReportingConfiguration = nodeInfo.node.nodeReportingConfiguration.copy(agentRunInterval = Some(schedule))))))
for {
oldNode <- nodeInfoService.getNode(nodeId)
result <- nodeRepo.updateNode(nodeInfo.node, modId, user, None)
Expand All @@ -210,7 +201,7 @@ class ShowNodeDetailsFromNode(
}

private[this] def privateDisplay(withinPopup : Boolean = false, displayCompliance : Boolean = false) : NodeSeq = {
nodeInfoService.getNodeInfo(nodeId) match {
boxNodeInfo match {
case Full(None) =>
<div class="error">Node with id {nodeId.value} was not found</div>
case eb:EmptyBox =>
Expand Down Expand Up @@ -275,8 +266,8 @@ class ShowNodeDetailsFromNode(
"#reportsDetails *" #> reportDisplayer.asyncDisplay(node) &
"#logsDetails *" #> logDisplayer.asyncDisplay(node.id)&
"#node_parameters -*" #> agentPolicyModeEditForm.cfagentPolicyModeConfiguration &
"#node_parameters -*" #> agentScheduleEditForm.cfagentScheduleConfiguration &
"#node_parameters *+" #> complianceModeEditForm.complianceModeConfiguration &
"#node_parameters -*" #> agentScheduleEditForm(node).cfagentScheduleConfiguration&
"#node_parameters *+" #> complianceModeEditForm(node).complianceModeConfiguration &
"#extraHeader" #> DisplayNode.showExtraHeader(inventory) &
"#extraContent" #> DisplayNode.showExtraContent(Some(node), inventory) &
"#node_tabs [id]" #> s"details_${id}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,11 @@ object DisplayNode extends Loggable {
displayTabVideos(jsId, sm) ::
Nil

<div id={htmlId(jsId,"details_")} class="sInventory tabsv ui-tabs ui-widget ui-widget-content ui-corner-all ui-tabs-vertical ui-helper-clearfix arrondis">
<ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all arrondisleft">{mainTabDeclaration}</ul>
val tabId = htmlId(jsId,"hardware_details_")
<div id={tabId} class="sInventory tabsv ui-tabs-vertical">
<ul>{mainTabDeclaration}</ul>
{tabContent.flatten}
</div>
</div> ++ Script(OnLoad(JsRaw(s"$$('#${tabId}').tabs()")))
}

/**
Expand Down Expand Up @@ -355,26 +356,27 @@ object DisplayNode extends Loggable {
}

val deleteButton : NodeSeq= {
sm.node.main.status match {
case AcceptedInventory =>
<div class="tw-bs">
<div id={deleteNodePopupHtmlId} class="modal fade" />
<div id={errorPopupHtmlId} class="modal fade" />
<div id={successPopupHtmlId} class="modal fade" />
</div>
<lift:authz role="node_write">
{
if(!isRootNode(sm.node.main.id)) {
<div class="tw-bs">
<div class="col-xs-12">
{ showDeleteButton(sm.node.main.id) }
</div>
sm.node.main.status match {
case AcceptedInventory =>
<div class="tw-bs">
<div id={deleteNodePopupHtmlId} class="modal fade" />
<div id={errorPopupHtmlId} class="modal fade" />
<div id={successPopupHtmlId} class="modal fade" />
</div>
<lift:authz role="node_write">
{
if(!isRootNode(sm.node.main.id)) {
<div class="tw-bs">
<div class="col-xs-12">
{ showDeleteButton(sm.node.main.id) }
</div>
} else {NodeSeq.Empty}
}
</lift:authz>
case _ => NodeSeq.Empty
} }
</div>
} else {NodeSeq.Empty}
}
</lift:authz>
case _ => NodeSeq.Empty
}
}

<div id="nodeDetails" >
<h3> Node characteristics</h3>
Expand Down Expand Up @@ -926,8 +928,9 @@ object DisplayNode extends Loggable {
</button>
</div>
</div>
</div> ;

</div>
JsRaw(s"updateHashString('nodeId', undefined); forceParseHashtag()") &
SetHtml("serverDetails", NodeSeq.Empty) &
JsRaw( """$('#successPopupHtmlId').bsModal('hide');""") &
SetHtml(successPopupHtmlId, popupHtml) &
JsRaw( s""" callPopupWithTimeout(200,"${successPopupHtmlId}") """)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ class SearchNodes extends StatefulSnippet with Loggable {
}
val nodeDetails = new ShowNodeDetailsFromNode(new NodeId(nodeId), groupLibrary).display(false, displayCompliance)
SetHtml("serverDetails", nodeDetails)
case _ => Noop
case _ =>
SetHtml("serverDetails", NodeSeq.Empty)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ app.controller('auditmodeCtrl', function ($scope, $http, $location, $timeout, co
}
};
});

app.config(function($locationProvider) {
$locationProvider.html5Mode(true);
})

function getNodeId(){
var nodeId;
try {
Expand Down
4 changes: 2 additions & 2 deletions rudder-web/src/main/webapp/style/rudder/rudder-jquery-ui.css
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@


/* autocomplete.css */
.ui-autocomplete-loading { background: white url('../images/themes/ui-lightness/images/ui-anim_basic_16x16.gif') right center no-repeat; }
.ui-autocomplete-loading { background: white url('../jquery-ui/images/ui-anim_basic_16x16.gif') right center no-repeat; }

.ui-menu {
float: none;
Expand Down Expand Up @@ -353,7 +353,7 @@ input .ui-button {

/* Interaction Cues -*/
.ui-state-highlight, .ui-widget-content .ui-state-highlight {
background: #ffe45c url(../jquery-ui/images/ui-bg_highlight-soft_75_ffe45c_1x100.png) 50% top repeat-x;
background: #cccccc url(../jquery-ui/images/ui-bg_highlight-soft_75_cccccc_1x100.png) 50% top repeat-x;
color: #363636;
border: none;
}
Expand Down