2222import java .io .InputStreamReader ;
2323import java .lang .reflect .Field ;
2424import java .net .SocketTimeoutException ;
25- // import java.net.HttpURLConnection;
2625import java .net .URL ;
2726import java .security .SecureRandom ;
2827import java .security .cert .CertificateException ;
28+ import java .text .SimpleDateFormat ;
2929import java .util .ArrayList ;
3030import java .util .Arrays ;
3131import java .util .Calendar ;
@@ -5883,7 +5883,6 @@ public void setLockControllerListener(final LockControllerListener lockControlle
58835883
58845884 @ Override
58855885 public LicenseCheckerResponse checkLicense (LicenseCheckCmd cmd ) {
5886- logger .info ("License check started" );
58875886 Long hostId = cmd .getHostId ();
58885887 if (hostId == null ) {
58895888 throw new InvalidParameterValueException ("Host ID is required" );
@@ -5894,22 +5893,112 @@ public LicenseCheckerResponse checkLicense(LicenseCheckCmd cmd) {
58945893 throw new InvalidParameterValueException ("Host not found: " + hostId );
58955894 }
58965895
5897- return checkLicensesForHosts (List .of (host )).getResponses ().get (0 );
5898- }
5899- private List <HostVO > getHostsToCheck (Long hostId ) {
5900- if (hostId != null ) {
5901- SearchBuilder <HostVO > sb = _hostDao .createSearchBuilder ();
5902- sb .and ("id" , sb .entity ().getId (), SearchCriteria .Op .EQ );
5903- SearchCriteria <HostVO > sc = sb .create ();
5904- sc .setParameters ("id" , hostId );
5905- return _hostDao .search (sc , new Filter (HostVO .class , "id" , true ));
5896+ LicenseCheckerResponse response = new LicenseCheckerResponse ();
5897+ response .setHostId (hostId );
5898+ response .setObjectName ("licensecheck" );
5899+
5900+ try {
5901+ String ipAddress = host .getPrivateIpAddress ();
5902+ String licenseApiUrl = "https://" + ipAddress + ":8080/api/v1/license/isLicenseExpired" ;
5903+
5904+ HttpsURLConnection connection = null ;
5905+ try {
5906+ // SSL 설정
5907+ final SSLContext sslContext = SSLUtils .getSSLContext ();
5908+ sslContext .init (null , new TrustManager []{new TrustAllManager ()}, new SecureRandom ());
5909+
5910+ URL url = new URL (licenseApiUrl );
5911+ connection = (HttpsURLConnection ) url .openConnection ();
5912+ connection .setSSLSocketFactory (sslContext .getSocketFactory ());
5913+ connection .setHostnameVerifier ((hostname , session ) -> hostname .equals (ipAddress ));
5914+ connection .setDoOutput (true );
5915+ connection .setRequestMethod ("GET" );
5916+ connection .setConnectTimeout (10000 );
5917+ connection .setReadTimeout (180000 );
5918+ connection .setRequestProperty ("Accept" , "application/json" );
5919+ connection .setRequestProperty ("Content-Type" , "application/json" );
5920+
5921+ int responseCode = connection .getResponseCode ();
5922+
5923+ if (responseCode == 200 ) {
5924+ BufferedReader in = new BufferedReader (new InputStreamReader (connection .getInputStream ()));
5925+ StringBuilder responseData = new StringBuilder ();
5926+ String line ;
5927+ while ((line = in .readLine ()) != null ) {
5928+ responseData .append (line );
5929+ }
5930+ in .close ();
5931+
5932+ // JSON 응답 파싱
5933+ ObjectMapper mapper = new ObjectMapper ();
5934+ JsonNode jsonNode = mapper .readTree (responseData .toString ());
5935+
5936+ // 라이선스 정보 설정
5937+ if (jsonNode .has ("error" )) {
5938+ String errorMessage = jsonNode .get ("error" ).asText ();
5939+ response .setHasLicense (false );
5940+ response .setSuccess (false );
5941+ response .setExpiryDate (null );
5942+ } else {
5943+ boolean isExpired = jsonNode .get ("expired" ).asBoolean ();
5944+ String expiryDateStr = jsonNode .get ("expiry_date" ).asText ();
5945+
5946+ response .setSuccess (!isExpired );
5947+ response .setHasLicense (true );
5948+ if (expiryDateStr != null && !expiryDateStr .isEmpty ()) {
5949+ SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd" );
5950+ Date expiryDate = sdf .parse (expiryDateStr );
5951+ response .setExpiryDate (expiryDate );
5952+ }
5953+ }
5954+ } else {
5955+ response .setHasLicense (false );
5956+ response .setSuccess (false );
5957+ response .setExpiryDate (null );
5958+ }
5959+ } finally {
5960+ if (connection != null ) {
5961+ connection .disconnect ();
5962+ }
5963+ }
5964+ return response ;
5965+ } catch (Exception e ) {
5966+ throw new CloudRuntimeException ("라이선스 체크 실패: " + e .getMessage ());
59065967 }
5907- return _hostDao .listAll ();
59085968 }
5909- public ListResponse <LicenseCheckerResponse > listLicenseChecks (final LicenseCheckCmd cmd ) {
5910- final Long hostId = cmd .getHostId ();
5911- List <HostVO > hosts = getHostsToCheck (hostId );
5912- return checkLicensesForHosts (hosts );
5969+
5970+ private Date getLicenseExpiryDate (String apiUrl , String ipAddress ) throws Exception {
5971+ HttpsURLConnection connection = null ;
5972+ try {
5973+ final SSLContext sslContext = SSLUtils .getSSLContext ();
5974+ sslContext .init (null , new TrustManager []{new TrustAllManager ()}, new SecureRandom ());
5975+
5976+ URL url = new URL (apiUrl );
5977+ connection = (HttpsURLConnection ) url .openConnection ();
5978+ connection .setSSLSocketFactory (sslContext .getSocketFactory ());
5979+ connection .setHostnameVerifier ((hostname , session ) -> hostname .equals (ipAddress ));
5980+ connection .setDoOutput (true );
5981+ connection .setRequestMethod ("GET" );
5982+ connection .setConnectTimeout (10000 );
5983+ connection .setReadTimeout (180000 );
5984+ connection .setRequestProperty ("Accept" , "application/json" );
5985+ connection .setRequestProperty ("Content-Type" , "application/x-www-form-urlencoded" );
5986+
5987+ if (connection .getResponseCode () == 200 ) {
5988+ try (BufferedReader in = new BufferedReader (new InputStreamReader (connection .getInputStream ()))) {
5989+ String dateStr = in .readLine ();
5990+ if (dateStr != null && !dateStr .isEmpty ()) {
5991+ SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd" );
5992+ return sdf .parse (dateStr );
5993+ }
5994+ }
5995+ }
5996+ } finally {
5997+ if (connection != null ) {
5998+ connection .disconnect ();
5999+ }
6000+ }
6001+ return null ;
59136002 }
59146003
59156004 private ListResponse <LicenseCheckerResponse > checkLicensesForHosts (List <HostVO > hosts ) {
0 commit comments