Skip to content

Commit

Permalink
feat(connect): show Camel icon for Camel JBang in Discover
Browse files Browse the repository at this point in the history
  • Loading branch information
tadayosi committed Dec 20, 2024
1 parent a64ae7f commit 9912567
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 28 deletions.
39 changes: 12 additions & 27 deletions packages/hawtio/src/plugins/connect/discover/Discover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ import React, { useContext, useEffect, useState } from 'react'
import { ADD, UPDATE } from '../connections'
import { ConnectContext } from '../context'
import { log } from '../globals'
import javaLogo from '../img/java-logo.svg'
import jettyLogo from '../img/jetty-logo.svg'
import tomcatLogo from '../img/tomcat-logo.svg'
import { Agent, Jvm, discoverService } from './discover-service'

export const Discover: React.FunctionComponent = () => {
Expand Down Expand Up @@ -223,20 +220,10 @@ export const Discover: React.FunctionComponent = () => {
)
}

const PRODUCT_LOGO: Record<string, string> = {
jetty: jettyLogo,
tomcat: tomcatLogo,
generic: javaLogo,
}

export const AgentCard: React.FunctionComponent<{
agent: Agent
connect: (conn: Connection) => void
}> = ({ agent, connect }) => {
const productLogo = (agent: Agent) => {
return PRODUCT_LOGO[agent.server_product?.toLowerCase() ?? 'generic'] ?? PRODUCT_LOGO.generic
}

const title = discoverService.hasName(agent) ? (
`${agent.server_vendor} ${agent.server_product} ${agent.server_version}`
) : (
Expand All @@ -247,16 +234,15 @@ export const AgentCard: React.FunctionComponent<{
<Card isCompact id={`connect-discover-agent-card-${agent.agent_id}`}>
<CardHeader
actions={{
actions: (
<>
<Label color='blue'>Agent</Label>
</>
),
actions: <Label color='blue'>Agent</Label>,
hasNoOffset: false,
className: undefined,
}}
>
<img src={productLogo(agent)} alt={agent.server_product} style={{ maxWidth: '30px', paddingRight: '0.5rem' }} />
<img
src={discoverService.productLogo(agent)}
alt={agent.server_product}
style={{ maxWidth: '30px', paddingRight: '0.5rem' }}
/>
<CardTitle style={{ whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{title}</CardTitle>
</CardHeader>
<CardBody>
Expand Down Expand Up @@ -334,16 +320,15 @@ export const JvmCard: React.FunctionComponent<{
<Card isCompact id={`connect-discover-jvm-card-${jvm.id}`}>
<CardHeader
actions={{
actions: (
<>
<Label color='green'>JVM</Label>
</>
),
actions: <Label color='green'>JVM</Label>,
hasNoOffset: false,
className: undefined,
}}
>
<img src={PRODUCT_LOGO.generic} alt={jvm.alias} style={{ maxWidth: '30px', paddingRight: '0.5rem' }} />
<img
src={discoverService.productLogoJvm(jvm)}
alt={jvm.alias}
style={{ maxWidth: '30px', paddingRight: '0.5rem' }}
/>
<CardTitle style={{ whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
{jvm.alias}
</CardTitle>
Expand Down
29 changes: 28 additions & 1 deletion packages/hawtio/src/plugins/connect/discover/discover-service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Connection, INITIAL_CONNECTION, connectService, jolokiaService, workspace } from '@hawtiosrc/plugins/shared'
import { isBlank } from '@hawtiosrc/util/strings'
import { log } from '../globals'
import camelLogo from '../img/camel-logo.svg'
import javaLogo from '../img/java-logo.svg'
import jettyLogo from '../img/jetty-logo.svg'
import tomcatLogo from '../img/tomcat-logo.svg'

/**
* @see https://jolokia.org/reference/html/manual/jolokia_mbeans.html#mbean-discovery
Expand All @@ -22,7 +26,7 @@ export type Agent = {
}

/**
* @see https://github.com/hawtio/hawtio/blob/3.x/plugins/hawtio-local-jvm-mbean/src/main/java/io/hawt/jvm/local/VMDescriptorDTO.java
* @see https://github.com/hawtio/hawtio/blob/4.x/plugins/hawtio-local-jvm-mbean/src/main/java/io/hawt/jvm/local/VMDescriptorDTO.java
*/
export type Jvm = {
id: string
Expand All @@ -35,6 +39,13 @@ export type Jvm = {
path: string | null
}

export const PRODUCT_LOGO: Record<string, string> = {
camel: camelLogo,
jetty: jettyLogo,
tomcat: tomcatLogo,
generic: javaLogo,
}

class DiscoverService {
hasDiscoveryMBean(): Promise<boolean> {
return workspace.treeContainsDomainAndProperties('jolokia', { type: 'Discovery' })
Expand Down Expand Up @@ -92,6 +103,22 @@ class DiscoverService {
return [agent.server_vendor, agent.server_product, agent.server_version].every(s => !isBlank(s))
}

productLogo(agent: Agent): string {
// Special handling for Camel
if (agent.command?.startsWith('main.CamelJBang')) {
return PRODUCT_LOGO.camel!
}
return PRODUCT_LOGO[agent.server_product?.toLowerCase() ?? 'generic'] ?? PRODUCT_LOGO.generic!
}

productLogoJvm(jvm: Jvm): string {
// Special handling for Camel
if (jvm.displayName.startsWith('main.CamelJBang')) {
return PRODUCT_LOGO.camel!
}
return PRODUCT_LOGO.generic!
}

agentToConnection(agent: Agent): Connection {
const conn = {
...INITIAL_CONNECTION,
Expand Down
7 changes: 7 additions & 0 deletions packages/hawtio/src/plugins/connect/img/camel-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9912567

Please sign in to comment.