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

Implemented DRA-388-use-kaltura-client. #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed
- bump sbforge-parent to v25

- Switched to using ds-kaltura client. Removed Kaltura client implementation and kaltura integration unittest. Less code in ds-image. Removed integration yaml from aegis.

=======
## [1.3.1](https://github.com/kb-dk/ds-image/releases/tag/ds-image-1.3.1) - 2024-02-23
Expand Down
17 changes: 11 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@
</dependency>

<!-- Client for ds-license. This will also require the org.openapitools dependency-->


<!--For getting thumbnails from Kaltura -->
<dependency>
<groupId>dk.kb.kaltura</groupId>
<artifactId>ds-kaltura</artifactId>
<version>1.1</version>
<type>jar</type>
</dependency>


<dependency>
<groupId>dk.kb.license</groupId>
<artifactId>ds-license</artifactId>
Expand Down Expand Up @@ -115,12 +126,6 @@
<version>1.8</version>
</dependency>

<!--For getting thumbnails from Kaltura -->
<dependency>
<groupId>com.kaltura</groupId>
<artifactId>kalturaApiClient</artifactId>
<version>19.3.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-xml-provider</artifactId>
Expand Down
106 changes: 0 additions & 106 deletions src/main/java/dk/kb/image/kaltura/DsKalturaClient.java

This file was deleted.

45 changes: 26 additions & 19 deletions src/main/java/dk/kb/image/util/KalturaUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,24 @@
import org.slf4j.LoggerFactory;

import dk.kb.image.config.ServiceConfig;
import dk.kb.image.kaltura.DsKalturaClient;

import dk.kb.image.model.v1.ThumbnailsDto;
import dk.kb.kaltura.client.DsKalturaClient;
import dk.kb.util.webservice.exception.InvalidArgumentServiceException;

/**
* <p>
* This class will instantiate a static KalturaClient that will be reused between calls.
* The client will refresh session at a given interval. This will avoid session accumulation at Kaltura.
* <p>
*
*/
public class KalturaUtil {

private static final Logger log = LoggerFactory.getLogger(KalturaUtil.class);
private static DsKalturaClient clientInstance = null;
private static long lastSessionStart=0;
private static long reloadIntervalInMillis=1L*24*60*60*1000; // 1 day

private static DsKalturaClient clientInstance = null;
private static long reloadIntervalSeconds=86400; //1 day

/**
*
* Example url to the sprite with all thumbnails:<br>
Expand All @@ -42,16 +49,16 @@ public static ThumbnailsDto getThumbnails(String fileId,Integer numberOfSlices,
ThumbnailsDto thumbnails = new ThumbnailsDto();
String kalturaUrl= ServiceConfig.getConfig().getString("kaltura.url");
Integer partnerId = ServiceConfig.getConfig().getInteger("kaltura.partnerId");
DsKalturaClient client = getClientInstance();

DsKalturaClient client = getClient();
String kalturaId = client.getKulturaInternalId(fileId);

if (kalturaId == null) {
throw new InvalidArgumentServiceException("FileId not found at Kaltura:"+fileId);
}
log.debug("ReferenceId lookup at kaltura resolved to internalId {} -> {}",fileId,kalturaId);
String baseUrl=kalturaUrl+"/p/"+partnerId+"/thumbnail/entry_id/"+kalturaId;

if (width != null && width.intValue() > 0) {
baseUrl=baseUrl+"/width/"+width;
}
Expand All @@ -77,22 +84,22 @@ public static ThumbnailsDto getThumbnails(String fileId,Integer numberOfSlices,
return thumbnails;
}


public synchronized static DsKalturaClient getClientInstance() throws IOException{
if (System.currentTimeMillis()-lastSessionStart >= reloadIntervalInMillis) {

public static DsKalturaClient getClient() throws IOException{

//Create client first time.
if (clientInstance == null) {
//Create the client
String kalturaUrl= ServiceConfig.getConfig().getString("kaltura.url");
String adminSecret = ServiceConfig.getConfig().getString("kaltura.adminSecret"); //Must not be shared or exposed.
Integer partnerId = ServiceConfig.getConfig().getInteger("kaltura.partnerId");
String userId = ServiceConfig.getConfig().getString("kaltura.userId");
DsKalturaClient client = new DsKalturaClient(kalturaUrl,userId,partnerId,adminSecret);
clientInstance=client;
log.info("Started a new Kaltura session");
lastSessionStart=System.currentTimeMillis(); //Reset timer
return clientInstance;
DsKalturaClient newClientInstance = new DsKalturaClient(kalturaUrl,userId,partnerId,adminSecret,reloadIntervalSeconds);
log.info("Started a new Kaltura session");
clientInstance= newClientInstance;
return clientInstance; //new clienty
}
return clientInstance; //Reuse existing connection.

return clientInstance; //reuse
}

}
48 changes: 0 additions & 48 deletions src/test/java/dk/kb/image/kaltura/KalturaApiIntegrationTest.java

This file was deleted.