## p4get-replicationConfig ## aaron bockelie function p4get-replicationState {param($clusterName) $topology = p4get-replicationTopology #get the topology xml framework $configuration = p4get "configure show allservers" #get the server configuration $nodeSelectArray = $topology.parent.children | %{$_.hostname} #create an array of children to append data to. foreach ($hostname in $nodeSelectArray) { $p4ReplicationState = $null #clear state for each server. $p4replParamNames = $null #need to clear each run to get a consistent result. Otherwise sometimes a non functioning node may report empty counters and data. $nodeIndex = ($nodeSelectArray.indexof($hostname)) #get the array index of our list of children nodes $p4configParameters = $configuration | ?{$_.servername -eq $hostname} | Select-Object name,value #get the configuration object and select params we want. try { $p4ReplicationState = p4get-replicaHostState $hostname #get the replication state for this node. As soon as the state is grabbed, it's probably out of date since the command starts a pull. } catch { write-error $error[0] #return the error stack. } foreach ($parameter in $p4configParameters) #roll through the static configuration parameters pulled from p4 configure relevant to this replica node { $topology.parent.children[$nodeIndex].p4config.SetAttribute($parameter.name,$parameter.value) #add the attribute nodes from the p4 config node. } $topology.parent.children[$nodeIndex].p4config.SetAttribute("hostname",$hostname) #add a hostname for ease of identifying a group of configs. #get index of parameters from replication state if ($p4ReplicationState) { $p4replParamNames = $p4ReplicationState | gm | ?{$_.MemberType -eq "NoteProperty"} | %{$_.name} #get a clean list of parameters from the replication state } foreach ($parameter in $p4replParamNames) #just insert the parameters matching noteproperty { $topology.parent.children[$nodeIndex].p4replstate.SetAttribute($parameter,$p4ReplicationState.$parameter) #use the parameter noteproperty names to reference each property and add to xml properties. } $topology.parent.children[$nodeIndex].p4replstate.SetAttribute("hostname",$hostname)#add a hostname for ease of identifying a group of replication states. } $topology #return the topology. } ## p4get-replicationtopology ## aaron bockelie function p4get-replicationTopology {param($clusterName,[switch]$all) if (!$env:depotsxml) { write-error "Could not locate depots.xml configuration file." break } $static = ([xml](gc $env:depotsxml)) if ($all) { $static.perforce.cluster } else { if ($clusterName) { $result = $static.perforce.cluster | ?{$_.name -match $clusterName} if ($result) { $result } else { write-error "No cluster found named $clusterName" } } else { if ($env:p4server) { $result = $static.perforce.cluster | ?{$_.name -eq ($static.perforce.depot | ?{$_.name -eq $env:p4server}).clusterName} if ($result) { $result } } else { write-warning "Not logged in via p4login. Returning topology of all replica groups." $static.perforce.cluster } } } } ## p4get-replicaHostState ## aaron bockelie function p4get-replicaHostState {param($clusterMember) function getReplState #internal function to pull replication state and fix timedate stamp in resultant data { $servercheck = p4get-server #get state of logged in $replTopology = p4get-replicationTopology -clusterName ($static.perforce.depot | ?{$_.name -eq $env:p4server} | %{$_.clusterName}) #fetch the topology matching this server. if ($replTopology.parent.hostname -notcontains $servercheck.server) #if the master in the topology does not match this server return state { $object = p4get "pull -l -j" $object.replicaTime = convertUnixTime $object.replicaTime $object.replicaStatefileModified = convertUnixTime $object.replicaStatefileModified $object } else { #if the server master matches logged in server, write a warning. write-warning "Cannot pull replication state on master server." } } if (!$env:depotsxml) #look for depots.xml, it's key to repl topology { write-error "Could not locate depots.xml configuration file." break } $originalServer = $env:p4server #store original server in case we're logged into a master server (can't pull repl state from master) $servercheck = p4get-server #get state of logged in if ($servercheck.pingsuccess.equals($true)) #if we're valid login { $static = ([xml](gc $env:depotsxml)) #parse xml object if ($clusterMember) #if the clustermember switch is specified, query that specific server. { $null = p4sudo $clusterMember 2>&1#sign into target getReplState #get state $null = p4sudo $originalserver 2>&1 #return to original server signin } else { getReplState } } }