Skip to content

Commit

Permalink
upstream: b=main,r=aa08f06d2c32f617d8cbaadf3d0d2a846cc81ab7,t=2024-02…
Browse files Browse the repository at this point in the history
…-09-1343-06314
  • Loading branch information
sonatype-zion committed Feb 9, 2024
1 parent 1027f68 commit f3c4273
Show file tree
Hide file tree
Showing 119 changed files with 1,886 additions and 1,463 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
package org.sonatype.nexus.blobstore.file.rest;

import java.util.Optional;

import javax.inject.Inject;
import javax.validation.Valid;
import javax.ws.rs.Consumes;
Expand Down Expand Up @@ -80,8 +79,9 @@ public void createFileBlobStore(@Valid final FileBlobStoreApiCreateRequest reque
@PUT
@Path("/file/{name}")
@Validate
public void updateFileBlobStore(@PathParam("name") final String name,
@Valid final FileBlobStoreApiUpdateRequest request)
public void updateFileBlobStore(
@PathParam("name") final String name,
@Valid final FileBlobStoreApiUpdateRequest request)
throws Exception
{
// Confirm that the blobstore name and type are the expected name and type
Expand All @@ -108,7 +108,7 @@ public FileBlobStoreApiModel getFileBlobStoreConfiguration(@PathParam("name") fi
private BlobStoreConfiguration getBlobStoreConfiguration(final String name) {
BlobStoreConfiguration configuration = Optional.ofNullable(blobStoreManager.get(name))
.map(BlobStore::getBlobStoreConfiguration)
.orElseThrow(BlobStoreResourceUtil::createBlobStoreNotFoundException);
.orElseThrow(() -> BlobStoreResourceUtil.createBlobStoreNotFoundException(FileBlobStore.TYPE, name));

if (!configuration.getType().equals(FileBlobStore.TYPE)) {
throw new WebApplicationMessageException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import java.util.List;
import java.util.Map;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.ws.rs.Consumes;
Expand Down Expand Up @@ -95,9 +94,8 @@ public BlobStoreResource(
@GET
public List<GenericBlobStoreApiResponse> listBlobStores() {
Map<String, BlobStore> blobstoresByName = blobStoreManager.getByName();
return store.list().stream()
.map(configuration -> new GenericBlobStoreApiResponse(configuration,
blobstoresByName.get(configuration.getName())))
return store.list().stream().map(
configuration -> new GenericBlobStoreApiResponse(configuration, blobstoresByName.get(configuration.getName())))
.collect(toList());
}

Expand All @@ -108,7 +106,7 @@ public List<GenericBlobStoreApiResponse> listBlobStores() {
@Path("/{name}")
public void deleteBlobStore(@PathParam("name") final String name) throws Exception {
if (!blobStoreManager.exists(name)) {
BlobStoreResourceUtil.throwBlobStoreNotFoundException();
BlobStoreResourceUtil.throwCreateBlobStoreNotFoundException("", name);
}
try {
blobStoreManager.delete(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,10 @@
*/
public class BlobStoreResourceUtil
{
public static WebApplicationMessageException createBlobStoreNotFoundException() {
return new WebApplicationMessageException(
NOT_FOUND,
"\"Unable to find blobstore\"",
APPLICATION_JSON
);
}

public static void throwBlobStoreNotFoundException() throws WebApplicationMessageException {
throw createBlobStoreNotFoundException();
}

/**
* Throws {@link BAD_REQUEST} exception in case when BlobStore manager could not perform operation
* (for example, blobstore is in use)
* Throws {@link BAD_REQUEST} exception in case when BlobStore manager could not perform operation (for example,
* blobstore is in use)
*
* @param message error message
* @throws WebApplicationMessageException
*/
Expand All @@ -48,4 +37,36 @@ public static void throwBlobStoreBadRequestException(final String message) throw
APPLICATION_JSON
);
}

/**
* Returns a {@link NOT_FOUND} WebApplicationMessageException when blobstore is not found.
*
* @param blobStoreType The type of the blobstore (e.g.: File, Group, S3, Azure Cloud Storage).
* @param blobStoreName The name of the blobstore.
* @return {@link WebApplicationMessageException}.
*/
public static WebApplicationMessageException createBlobStoreNotFoundException(
final String blobStoreType,
final String blobStoreName)
{
return new WebApplicationMessageException(
NOT_FOUND,
String.format("\"Unable to find %s '%s' blobstore\"", blobStoreType, blobStoreName),
APPLICATION_JSON
);
}

/**
* Throws a {@link NOT_FOUND} WebApplicationMessageException when blobstore is not found.
*
* @param blobStoreType The type of the blobstore (e.g.: File, Group, S3, Azure Cloud Storage).
* @param blobStoreName The name of the blobstore.
* @throws {@link WebApplicationMessageException}.
*/
public static void throwCreateBlobStoreNotFoundException(
final String blobStoreType,
final String blobStoreName)
{
throw createBlobStoreNotFoundException(blobStoreType, blobStoreName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public interface FeatureFlags

String REACT_PRIVILEGES_MODAL_ENABLED = "nexus.react.privileges.modal.enabled";

String REACT_PRIVILEGES_MODAL_NAMED = "${nexus.react.privileges.modal.enabled:-false}";
String REACT_PRIVILEGES_MODAL_NAMED = "${nexus.react.privileges.modal.enabled:-true}";

/**
* Feature flag to determine if we should include the repository sizes feature
Expand All @@ -130,9 +130,13 @@ public interface FeatureFlags

String REPOSITORY_SIZE_ENABLED_NAMED = "${nexus.repository.size:-false}";

String CONTENT_USAGE_ENABLED = "nexus.contentUsageMetrics.enabled";

String CONTENT_USAGE_ENABLED_NAMED = "${nexus.contentUsageMetrics.enabled:-true}";

String REACT_ROLES_MODAL_ENABLED = "nexus.react.roles.modal.enabled";

String REACT_ROLES_MODAL_NAMED = "${nexus.react.roles.modal.enabled:-false}";
String REACT_ROLES_MODAL_NAMED = "${nexus.react.roles.modal.enabled:-true}";

String BLOBSTORE_OWNERSHIP_CHECK_DISABLED_NAMED = "${nexus.blobstore.s3.ownership.check.disabled:-false}";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
package org.sonatype.nexus.datastore.mybatis;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectOutputStream;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
Expand All @@ -23,13 +26,14 @@

import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static com.google.common.base.Preconditions.checkNotNull;

/**
* Intended for use for reading from Quartz
* Abstract {@link TypeHandler} that supports serializing/deserializing Java objects to/from a byte array.
*/
public abstract class AbstractBytesTypeHandler<T>
extends BaseTypeHandler<T>
Expand Down Expand Up @@ -61,13 +65,13 @@ public final T getNullableResult(final CallableStatement cs, final int columnInd
}

@Override
public void setNonNullParameter(
public final void setNonNullParameter(
final PreparedStatement ps,
final int i,
final int parameterIndex,
final T parameter,
final JdbcType jdbcType) throws SQLException
{
throw new UnsupportedOperationException("Unimplemented");
ps.setBytes(parameterIndex, serialize(parameter));
}

/**
Expand All @@ -80,4 +84,16 @@ private T deserialize(final Optional<byte[]> blob) {
.map(this::deserialize)
.orElseGet(defaultValueSupplier::get);
}

private byte[] serialize(final T object) throws SQLException {
try (ByteArrayOutputStream buf = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(buf)) {
out.writeObject(object);
out.flush();
return buf.toByteArray();
}
catch (IOException e) {
throw new SQLException("Problem serializing: " + object.getClass().getName(), e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ public interface QuartzDAO
List<QuartzTaskStateData> getStates();

Optional<QuartzTaskStateData> getState(String jobName);

void updateJobDataMap(QuartzTaskStateData taskState);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
Expand All @@ -33,13 +32,15 @@
import org.sonatype.nexus.scheduling.spi.TaskResultStateStore;
import org.sonatype.nexus.transaction.Transactional;

import org.quartz.JobDataMap;
import org.quartz.JobKey;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.Trigger;

import static com.google.common.base.Preconditions.checkNotNull;
import static org.quartz.TriggerKey.triggerKey;
import static org.sonatype.nexus.quartz.internal.task.QuartzTaskUtils.updateJobData;

@Named
@Singleton
Expand All @@ -66,6 +67,14 @@ public Optional<TaskResultState> getState(final TaskInfo taskInfo) {
.map(jobStates -> aggregate(taskInfo, jobStates));
}

@Override
public void updateJobDataMap(final TaskInfo taskInfo) {
String jobName = ((QuartzTaskInfo) taskInfo).getJobKey().getName();
JobDataMap jobDataMap = new JobDataMap();
updateJobData(jobDataMap, taskInfo.getConfiguration());
doUpdateJobDataMap(jobName, jobDataMap);
}

@Transactional
protected List<QuartzTaskStateData> getQuartzStates() {
return dao().getStates();
Expand All @@ -76,6 +85,14 @@ protected Optional<QuartzTaskStateData> getQuartzState(final String taskId) {
return dao().getState(taskId);
}

@Transactional
protected void doUpdateJobDataMap(final String jobName, final JobDataMap jobDataMap) {
QuartzTaskStateData quartzTaskStateData = new QuartzTaskStateData();
quartzTaskStateData.setJobName(jobName);
quartzTaskStateData.setJobData(jobDataMap);
dao().updateJobDataMap(quartzTaskStateData);
}

private TaskResultState aggregate(final TaskInfo taskInfo, final List<QuartzTaskStateData> jobStates) {
TaskConfiguration taskConfiguration = jobStates.stream()
.map(QuartzTaskStateData::getJobData)
Expand Down Expand Up @@ -106,6 +123,6 @@ private TaskResultState aggregate(final TaskInfo taskInfo, final List<QuartzTask
.anyMatch("EXECUTING"::equals);

return new TaskResultState(taskConfiguration.getId(), running ? TaskState.RUNNING : TaskState.WAITING,
nextFireTime, taskConfiguration.getLastRunState());
nextFireTime, taskConfiguration.getLastRunState(), taskConfiguration.getProgress());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.sonatype.nexus.quartz.internal.orient;

import java.util.Optional;
import javax.inject.Named;
import javax.inject.Singleton;

import org.sonatype.nexus.scheduling.TaskInfo;
import org.sonatype.nexus.scheduling.spi.TaskResultState;
import org.sonatype.nexus.scheduling.spi.TaskResultStateStore;

@Named
@Singleton
public class OrientTaskResultStateStoreImpl
implements TaskResultStateStore
{
@Override
public Optional<TaskResultState> getState(final TaskInfo taskInfo) {
// functionality not supported in orient
return Optional.empty();
}

@Override
public void updateJobDataMap(final TaskInfo taskInfo) {
// functionality not supported in orient
}

@Override
public boolean isSupported() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private void doExecute() throws Exception {

// create TaskConfiguration, and using that the Task
final TaskConfiguration config = configurationOf(context.getJobDetail());
task = taskFactory.create(config);
task = taskFactory.create(config, taskInfo);
// after this point, cancellation will be handled okay too

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ public static TaskConfiguration configurationOf(final JobDataMap jobDataMap) {
* Saves {@link TaskConfiguration} back to the given {@link JobDetail}.
*/
public static void updateJobData(final JobDetail jobDetail, final TaskConfiguration taskConfiguration) {
JobDataMap jobDataMap = jobDetail.getJobDataMap();
updateJobData(jobDetail.getJobDataMap(), taskConfiguration);
}

public static void updateJobData(final JobDataMap jobDataMap, final TaskConfiguration taskConfiguration) {
taskConfiguration.asMap().forEach((key, value) -> {
if (TaskConfiguration.REMOVE_ATTRIBUTE_MARKER.equals(value)) {
jobDataMap.remove(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,8 @@
WHERE D.job_name = #{value};
</select>

<update id="updateJobDataMap" parameterType="QuartzTaskStateData">
UPDATE qrtz_job_details SET job_data = #{jobData} WHERE job_name = #{jobName};
</update>

</mapper>
2 changes: 1 addition & 1 deletion components/nexus-rapture/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@fortawesome/free-solid-svg-icons": "5.11.2",
"@fortawesome/react-fontawesome": "0.1.4",
"@sonatype/nexus-ui-plugin": "workspace:*",
"@sonatype/react-shared-components": "12.10.3",
"@sonatype/react-shared-components": "13.1.6",
"@xstate/inspect": "0.4.1",
"axios": "0.21.4",
"core-js": "3.28.0",
Expand Down
Loading

0 comments on commit f3c4273

Please sign in to comment.