Skip to content

Instantly share code, notes, and snippets.

@oluies
Created February 26, 2015 21:12
Show Gist options
  • Save oluies/35cf997f07c6ca70895f to your computer and use it in GitHub Desktop.
Save oluies/35cf997f07c6ca70895f to your computer and use it in GitHub Desktop.
getMQStatus wrapper
import java.util.{Enumeration, HashMap}
import com.ibm.mq.constants.{CMQC, MQConstants, CMQCFC}
import com.ibm.mq.headers.pcf.{PCFMessage,PCFParameter}
import scala.collection.JavaConverters._
object Main extends App {
val pcfCM: PCF_CommonMethods = new PCF_CommonMethods
try {
if (pcfCM.ParseParameters(args)) {
pcfCM.CreateAgent(args.length)
val x: MQStatus = getMQStatus(pcfCM)
println(x)
pcfCM.DestroyAgent
}
}
catch {
case e: Exception => {
pcfCM.DisplayException(e)
}
}
type MQStatusType = Int
case class MQStatus(
name: String,
status: Int,
connections: Int,
cmdServerStatus: Int,
chInitStatus: Int,
installationName: String,
installationPath: String,
installationDescription: String,
LDAPConnectionStatus: String,
permitStandby: Boolean,
logPath: String,
currentLogExtentName: Option[String],
restartLogExtentName: Option[String],
mediaLogExtentName: Option[String],
startDate: Option[String],
startTime: Option[String]
)
def getMQStatus(pcfCM:PCF_CommonMethods ): MQStatus = {
val request: PCFMessage = new PCFMessage(CMQCFC.MQCMD_INQUIRE_Q_MGR_STATUS)
request.addParameter(CMQCFC.MQIACF_Q_MGR_STATUS_ATTRS, Array[Int](CMQCFC.MQIACF_ALL))
val responses: Array[PCFMessage] = pcfCM.agent.send(request)
val resp:Iterator[(Int,String)] = for{ p <- responses(0).getParameters.asScala
pc = p.asInstanceOf[PCFParameter]
} yield pc.getParameter -> pc.getStringValue
val respMap: Map[Int,String] = resp.toMap
// m2 foreach println
// (2015,(MQCA_Q_MGR_NAME,mq02 ))
// (1149,(MQIACF_Q_MGR_STATUS,2))
// (1230,(MQIACF_CONNECTION_COUNT,22))
// (1233,(MQIACF_CMD_SERVER_STATUS,2))
// (1232,(MQIACF_CHINIT_STATUS,2))
// (2116,(MQCA_INSTALLATION_NAME,Installation1))
// (2117,(MQCA_INSTALLATION_PATH,C:\Program Files\IBM\WebSphere MQ))
// (2115,(MQCA_INSTALLATION_DESC,))
// (1409,(MQIACF_LDAP_CONNECTION_STATUS,0))
// (1325,(MQIACF_PERMIT_STANDBY,0))
// (3074,(MQCACF_LOG_PATH,C:\ProgramData\IBM\MQ\log\mq02\active\))
// (3071,(MQCACF_CURRENT_LOG_EXTENT_NAME,S0000000.LOG))
// (3072,(MQCACF_RESTART_LOG_EXTENT_NAME,S0000000.LOG))
// (3073,(MQCACF_MEDIA_LOG_EXTENT_NAME,S0000000.LOG))
// (3175,(MQCACF_Q_MGR_START_DATE,2015-02-24 ))
// (3176,(MQCACF_Q_MGR_START_TIME,09.50.47))
MQStatus(
name = respMap.getOrElse(CMQC.MQCA_Q_MGR_NAME,"Unknown").trim,
status = respMap.getOrElse(CMQCFC.MQIACF_Q_MGR_STATUS,"4").toInt,
connections = respMap.getOrElse(CMQCFC.MQIACF_CONNECTION_COUNT,"0").toInt,
cmdServerStatus = respMap.getOrElse(CMQCFC.MQIACF_CMD_SERVER_STATUS,"0").toInt,
chInitStatus = respMap.getOrElse(CMQCFC.MQIACF_CHINIT_STATUS,"0").toInt,
installationName = respMap.getOrElse(CMQC.MQCA_INSTALLATION_NAME,""),
installationPath = respMap.getOrElse(CMQC.MQCA_INSTALLATION_PATH,""),
installationDescription = respMap.getOrElse(CMQC.MQCA_INSTALLATION_DESC,""),
LDAPConnectionStatus = respMap.getOrElse(CMQCFC.MQIACF_LDAP_CONNECTION_STATUS,""),
permitStandby = if( respMap.getOrElse(CMQCFC.MQIACF_PERMIT_STANDBY,0) == 0 ) false else true,
logPath = respMap.getOrElse(CMQCFC.MQCACF_LOG_PATH,""),
currentLogExtentName = respMap.get(CMQCFC.MQCACF_CURRENT_LOG_EXTENT_NAME),
restartLogExtentName = respMap.get(CMQCFC.MQCACF_RESTART_LOG_EXTENT_NAME),
mediaLogExtentName = respMap.get(CMQCFC.MQCACF_MEDIA_LOG_EXTENT_NAME),
startDate = respMap.get(CMQCFC.MQCACF_Q_MGR_START_DATE),
startTime = respMap.get(CMQCFC.MQCACF_Q_MGR_START_TIME)
)
}
}
object MQChannelStatus {
type MQStatusType = Int
/////////////////////////////////////////////////////////
// MQ Channel Status
//
// Stopped/Paused 6, 8
// Initializing/Stopping 4, 13
// Starting 2
// Retrying 5
// Requesting 7
// Binding 1
// Running 3
sealed abstract class Status(
val id : MQStatusType,
val name : String) extends Ordered[Status] {
def compare(that: Status) = this.id - that.id
override def toString = name
}
case object Running extends Status(3,"Running")
case object Stopped extends Status(6,"Stopped")
case object Retrying extends Status(5,"Retrying")
case object Paused extends Status(8,"Paused")
case object Initializing extends Status(4,"Initializing")
case object Stopping extends Status(13,"Stopping")
case object Starting extends Status(2,"Starting")
case object Requesting extends Status(7,"Requesting")
case object Binding extends Status(1,"Binding")
case object Unknown extends Status(666,"Unknown")
def fromInt(value:Int): Status = value match {
case 6 => Stopped
case 8 => Paused
case 4 => Initializing
case 13 => Stopping
case 2 => Starting
case 5 => Retrying
case 7 => Requesting
case 1 => Binding
case 3 => Running
case _ => Unknown
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment