text:
package provider

import (
	"net/http"

	"github.com/go-openapi/swag"
	"github.com/openshift/assisted-service/internal/common"
	"github.com/openshift/assisted-service/internal/featuresupport"
	"github.com/openshift/assisted-service/models"
	"github.com/pkg/errors"
)

func isPlatformBM(platform *models.Platform) bool {
	return platform != nil && *platform.Type == models.PlatformTypeBaremetal
}

func isPlatformNone(platform *models.Platform) bool {
	return platform != nil && *platform.Type == models.PlatformTypeNone
}

func isClusterPlatformNone(cluster *common.Cluster) bool {
	return cluster != nil && isPlatformNone(cluster.Platform)
}

func isPlatformExternal(platform *models.Platform) bool {
	return platform != nil && *platform.Type == models.PlatformTypeOci
}

func isUMNAllowedForPlatform(platform *models.Platform) bool {
	if platform == nil {
		return true
	}

	switch *platform.Type {
	case models.PlatformTypeBaremetal, models.PlatformTypeNutanix:
		return false
	}
	return true
}

func isUMNMandatoryForPlatform(platform *models.Platform) bool {
	if platform == nil {
		return true
	}

	if *platform.Type == models.PlatformTypeNone || isPlatformExternal(platform) {
		return true
	}

	return false
}

func isClusterPlatformBM(cluster *common.Cluster) bool {
	return cluster != nil && isPlatformBM(cluster.Platform)
}

func isUMNAllowedForCluster(cluster *common.Cluster) bool {
	return cluster != nil && isUMNAllowedForPlatform(cluster.Platform)
}

func isUMNMandatoryForCluster(cluster *common.Cluster) bool {
	return cluster != nil && isUMNMandatoryForPlatform(cluster.Platform)
}

func CheckPlatformWrongParamsInput(platform *models.Platform, userManagedNetworking *bool, cluster *common.Cluster) error {
	// check if platform compatibility with UMN
	if platform != nil && userManagedNetworking != nil {
		userManagedNetworkingStatus := "enabled"
		if !*userManagedNetworking {
			userManagedNetworkingStatus = "disabled"
		}
		if (!*userManagedNetworking && isUMNMandatoryForPlatform(platform)) || (*userManagedNetworking && !isUMNAllowedForPlatform(platform)) {
			return common.NewApiError(http.StatusBadRequest, errors.Errorf("Can't set %s platform with user-managed-networking %s", *platform.Type, userManagedNetworkingStatus))
		}
	}

	// If current cluster platform is different than baremetal/none, and we want to set the cluster platform to one
	// of those platforms, that might cause the cluster to be in wrong state (baremetal + umn enabled, none + umn disabled)
	// In those cases return bad request
	if userManagedNetworking == nil &&
		cluster != nil &&
		platform != nil &&
		*cluster.HighAvailabilityMode == models.ClusterHighAvailabilityModeFull && // no need to check SNO, it will be validated later in the update/creation
		(!(isClusterPlatformBM(cluster) && isPlatformNone(platform)) &&
			!(isClusterPlatformNone(cluster) && isPlatformBM(platform))) {

		if !isUMNAllowedForPlatform(platform) && swag.BoolValue(cluster.UserManagedNetworking) {
			return common.NewApiError(http.StatusBadRequest, errors.Errorf("Can't set %s platform with user-managed-networking enabled", *platform.Type))
		}

		if isUMNMandatoryForPlatform(platform) && !swag.BoolValue(cluster.UserManagedNetworking) {
			return common.NewApiError(http.StatusBadRequest, errors.Errorf("Can't set %s platform with user-managed-networking disabled", *platform.Type))
		}
	}

	return nil
}

func doesPlatformAllowUMNOrCMN(platform *models.Platform, cluster *common.Cluster) bool {
	if platform != nil && isUMNAllowedForPlatform(platform) && !isUMNMandatoryForPlatform(platform) {
		return true
	}

	if platform == nil && isUMNAllowedForCluster(cluster) && !isUMNMandatoryForCluster(cluster) {
		return true
	}

	return false
}

func createPlatformFromType(platformType models.PlatformType) *models.Platform {
	platform := &models.Platform{
		Type: &platformType,
	}
	return updatePlatformIsExternal(platform)
}

func updatePlatformIsExternal(platform *models.Platform) *models.Platform {
	if platform == nil {
		return nil
	}
	platform.IsExternal = swag.Bool(isPlatformExternal(platform))

	return platform
}

func getUpdateParamsForPlatformBM(platform *models.Platform, userManagedNetworking *bool, cluster *common.Cluster) (*models.Platform, *bool, error) {
	if !swag.BoolValue(userManagedNetworking) && (platform == nil || isPlatformBM(platform)) {
		// Platform is already baremetal, nothing to do
		return nil, nil, nil
	}

	if (platform != nil && isPlatformNone(platform)) || (swag.BoolValue(userManagedNetworking) && platform == nil) {
		return createPlatformFromType(models.PlatformTypeNone), swag.Bool(true), nil
	}

	return updatePlatformIsExternal(platform), userManagedNetworking, nil
}

func getUpdateParamsForPlatformUMNMandatory(platform *models.Platform, userManagedNetworking *bool, cluster *common.Cluster) (*models.Platform, *bool, error) {
	if (userManagedNetworking == nil || *userManagedNetworking) && isUMNMandatoryForPlatform(platform) {
		// userManagedNetworking is already set to true, nothing to do
		if platform == nil || *cluster.Platform.Type == *platform.Type {
			return nil, nil, nil
		} else {
			return createPlatformFromType(*platform.Type), nil, nil
		}
	}

	if *cluster.HighAvailabilityMode == models.ClusterHighAvailabilityModeNone {
		if !swag.BoolValue(userManagedNetworking) || (platform != nil && !isUMNMandatoryForPlatform(platform)) {
			return nil, nil, common.NewApiError(http.StatusBadRequest, errors.New("disabling User Managed Networking or setting platform different than none or oci platforms is not allowed in single node Openshift"))
		}
	}

	if !swag.BoolValue(userManagedNetworking) {
		if platform == nil || isPlatformBM(platform) {
			if cluster.CPUArchitecture != common.X86CPUArchitecture &&
				!featuresupport.IsFeatureAvailable(models.FeatureSupportLevelIDCLUSTERMANAGEDNETWORKING, cluster.OpenshiftVersion, swag.String(cluster.CPUArchitecture)) {
				return nil, nil, common.NewApiError(http.StatusBadRequest, errors.New("disabling User Managed Networking or setting Bare-Metal platform is not allowed for clusters with non-x86_64 CPU architecture"))
			}

			return createPlatformFromType(models.PlatformTypeBaremetal), swag.Bool(false), nil
		}
	}

	return updatePlatformIsExternal(platform), userManagedNetworking, nil
}

func GetActualUpdateClusterPlatformParams(platform *models.Platform, userManagedNetworking *bool, cluster *common.Cluster) (*models.Platform, *bool, error) {
	if platform == nil && userManagedNetworking == nil {
		return nil, nil, nil
	}

	if err := CheckPlatformWrongParamsInput(platform, userManagedNetworking, cluster); err != nil {
		return nil, nil, err
	}

	if doesPlatformAllowUMNOrCMN(platform, cluster) {
		return updatePlatformIsExternal(platform), userManagedNetworking, nil
	}

	if isClusterPlatformBM(cluster) {
		return getUpdateParamsForPlatformBM(platform, userManagedNetworking, cluster)
	} else if isUMNMandatoryForCluster(cluster) {
		return getUpdateParamsForPlatformUMNMandatory(platform, userManagedNetworking, cluster)
	} else if platform == nil && !isUMNAllowedForCluster(cluster) && swag.BoolValue(userManagedNetworking) {
		return nil, nil, common.NewApiError(http.StatusBadRequest, errors.Errorf("User-managed-networking is not supported with platform %s", common.PlatformTypeValue(cluster.Platform.Type)))
	}

	return updatePlatformIsExternal(platform), userManagedNetworking, nil
}

func GetClusterPlatformByHighAvailabilityMode(platform *models.Platform, userManagedNetworking *bool, highAvailabilityMode *string) (*models.Platform, *bool, error) {
	if swag.StringValue(highAvailabilityMode) == models.ClusterHighAvailabilityModeFull {
		if (platform == nil || isPlatformBM(platform)) && !swag.BoolValue(userManagedNetworking) {
			return createPlatformFromType(models.PlatformTypeBaremetal), swag.Bool(false), nil
		}

		if swag.BoolValue(userManagedNetworking) || platform == nil || isUMNMandatoryForPlatform(platform) {
			if platform == nil {
				// default to None platform
				return createPlatformFromType(models.PlatformTypeNone), swag.Bool(true), nil
			} else {
				return updatePlatformIsExternal(platform), swag.Bool(true), nil
			}
		}
	} else { // *highAvailabilityMode == models.ClusterHighAvailabilityModeNone
		if isPlatformBM(platform) {
			return nil, nil, common.NewApiError(http.StatusBadRequest, errors.Errorf("Can't set %s platform on single node OpenShift", *platform.Type))
		}

		if userManagedNetworking != nil && !*userManagedNetworking {
			return nil, nil, common.NewApiError(http.StatusBadRequest, errors.New("Can't disable user-managed-networking on single node OpenShift"))
		}

		if isPlatformNone(platform) || isPlatformExternal(platform) {
			return updatePlatformIsExternal(platform), swag.Bool(true), nil
		}

		return createPlatformFromType(models.PlatformTypeNone), swag.Bool(true), nil
	}
	return nil, nil, common.NewApiError(http.StatusBadRequest, errors.Errorf("Got invalid platform (%s) and/or user-managed-networking (%v)", *platform.Type, userManagedNetworking))
}

func GetActualCreateClusterPlatformParams(platform *models.Platform, userManagedNetworking *bool, highAvailabilityMode *string, cpuArchitecture string) (*models.Platform, *bool, error) {
	if err := CheckPlatformWrongParamsInput(platform, userManagedNetworking, nil); err != nil {
		return nil, nil, err
	}

	if cpuArchitecture == models.ClusterCPUArchitectureS390x || cpuArchitecture == models.ClusterCPUArchitecturePpc64le {
		if userManagedNetworking != nil && !*userManagedNetworking {
			return nil, nil, common.NewApiError(http.StatusBadRequest, errors.Errorf("Can't disable User Managed Networking on %s architecture", cpuArchitecture))
		} else if platform != nil && !isPlatformNone(platform) {
			return nil, nil, common.NewApiError(http.StatusBadRequest, errors.Errorf("Can't set %s platform on %s architecture", *platform.Type, cpuArchitecture))
		}
		return createPlatformFromType(models.PlatformTypeNone), swag.Bool(true), nil
	}

	if platform != nil && !isPlatformBM(platform) && !isUMNMandatoryForPlatform(platform) {
		return updatePlatformIsExternal(platform), userManagedNetworking, nil
	}
	return GetClusterPlatformByHighAvailabilityMode(platform, userManagedNetworking, highAvailabilityMode)
}

func GetPlatformFeatureID(platformType models.PlatformType) models.FeatureSupportLevelID {
	switch platformType {
	case models.PlatformTypeOci:
		return models.FeatureSupportLevelIDEXTERNALPLATFORMOCI
	case models.PlatformTypeVsphere:
		return models.FeatureSupportLevelIDVSPHEREINTEGRATION
	case models.PlatformTypeNutanix:
		return models.FeatureSupportLevelIDNUTANIXINTEGRATION
	default:
		return "" // Return empty string on platform without a feature support ID
	}
}

repository: openshift/assisted-service

repo_name: openshift/assisted-service


text:
DESCRIPTION = "QtiPi Image"

inherit core-image populate_sdk_qt5

IMAGE_FEATURES += "package-management ssh-server-openssh tools-debug"

# Add 1 GB of rootfs size
IMAGE_ROOTFS_EXTRA_SPACE = "1048576"

# System tools
IMAGE_INSTALL += " \
    systemd-analyze \
    openssh-sftp-server \
    avahi-daemon \
"

# Pi specific packages
IMAGE_INSTALL += " \
    rpi-gpio \
"

# Some useful Qt packages
IMAGE_INSTALL += "qtipi-bundle"

# Example application
IMAGE_INSTALL += "touchpoints"

license: MIT

repository: QtiPi/meta-qtipi

license_type: permissive

repo_name: QtiPi/meta-qtipi

branch_name: refs/heads/master

gha_license_id: MIT

gha_language: BitBake

extension: bb


text:
// Copyright © 2022 Dell Inc. or its subsidiaries. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//      http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

package e2e

import (
	"context"
	"fmt"
	"math/rand"
	"strconv"
	"strings"
	"time"

	"github.com/onsi/ginkgo"
	"github.com/onsi/gomega"
	v1 "k8s.io/api/core/v1"
	storagev1 "k8s.io/api/storage/v1"
	apierrors "k8s.io/apimachinery/pkg/api/errors"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	clientset "k8s.io/client-go/kubernetes"
	"k8s.io/kubectl/pkg/drain"
	"k8s.io/kubernetes/test/e2e/framework"
	fpod "k8s.io/kubernetes/test/e2e/framework/pod"
	fss "k8s.io/kubernetes/test/e2e/framework/statefulset"
)

var mountPath = "/data"

var _ = ginkgo.Describe("[csi-adv-fsg] Nodes Scale-up and Scale-down", func() {

	f := framework.NewDefaultFramework("e2e-scale-nodes")

	// prevent annoying psp warning
	f.SkipPrivilegedPSPBinding = true

	var (
		namespace string
		client    clientset.Interface
	)
	ginkgo.BeforeEach(func() {
		namespace = getNamespaceToRunTests(f)
		client = f.ClientSet
		bootstrap()
	})

	ginkgo.AfterEach(func() {
		_, cancel := context.WithCancel(context.Background())
		defer cancel()
		ginkgo.By(fmt.Sprintf("Deleting all statefulsets in namespace: %v", namespace))
		fss.DeleteAllStatefulSets(client, namespace)
	})

	/*
		Test performs following operations

		Steps
		1. Create a storage class.
		3. Create busybox statefulsets with 3 replicas.
		4. Wait until all Pods are ready and PVCs are bounded with PV.
		5. Cordon and drain the node
		6. Wait for the STS pods to reschedule on the available nodes
		7. Scale down statefulsets to 2 replicas.
		8. Uncordon the node
		9. Scale up statefulsets to 3 replicas.
		10. Scale down statefulsets to 0 replicas.
		11. Delete all PVCs from the tests namespace.
		12. Delete the storage class.
	*/
	ginkgo.It("[csi-adv-fsg] Statefulset with Nodes Scale-up and Scale-down", func() {
		curtime := time.Now().Unix()
		randomValue := rand.Int()
		val := strconv.FormatInt(int64(randomValue), 10)
		val = string(val[1:3])
		curtimestring := strconv.FormatInt(curtime, 10)
		scName := "fsgroup-sc-default-" + curtimestring + val

		ctx, cancel := context.WithCancel(context.Background())
		defer cancel()

		dh := drain.Helper{
			Ctx:                 ctx,
			Client:              client,
			Force:               true,
			DeleteEmptyDirData:  true,
			DisableEviction:     true,
			IgnoreAllDaemonSets: true,
			Out:                 ginkgo.GinkgoWriter,
			ErrOut:              ginkgo.GinkgoWriter,
		}

		framework.Logf("Fetch the Node Details")
		nodes, err := client.CoreV1().Nodes().List(ctx, metav1.ListOptions{})
		gomega.Expect(err).NotTo(gomega.HaveOccurred())

		testParameters[testParameters["scParamStoragePoolKey"]] = testParameters["scParamStoragePoolValue"]
		testParameters[testParameters["scParamStorageSystemKey"]] = testParameters["scParamStorageSystemValue"]
		testParameters[testParameters["scParamFsTypeKey"]] = testParameters["scParamFsTypeValue"]

		sc, err := createStorageClass(client, testParameters, nil, "",
			storagev1.VolumeBindingWaitForFirstConsumer,
			false, scName)
		gomega.Expect(err).NotTo(gomega.HaveOccurred())

		defer func() {
			err := client.StorageV1().StorageClasses().Delete(ctx, sc.Name, *metav1.NewDeleteOptions(0))
			gomega.Expect(err).NotTo(gomega.HaveOccurred())
		}()

		statefulset := GetStatefulSetFromManifest(namespace)
		ginkgo.By("Creating statefulset")

		statefulset.Spec.VolumeClaimTemplates[len(statefulset.Spec.VolumeClaimTemplates)-1].Spec.AccessModes[0] =
			v1.ReadWriteOnce

		statefulset.Spec.VolumeClaimTemplates[len(statefulset.Spec.VolumeClaimTemplates)-1].
			Annotations["volume.beta.kubernetes.io/storage-class"] = scName
		CreateStatefulSet(namespace, statefulset, client)

		defer func() {
			ginkgo.By(fmt.Sprintf("Deleting all statefulsets in namespace: %v", namespace))
			fss.DeleteAllStatefulSets(client, namespace)
		}()

		replicas := *(statefulset.Spec.Replicas)
		// Waiting for pods status to be Ready
		fss.WaitForStatusReadyReplicas(client, statefulset, replicas)

		gomega.Expect(fss.CheckMount(client, statefulset, mountPath)).NotTo(gomega.HaveOccurred())

		ssPodsBeforeScaleDown := fss.GetPodList(client, statefulset)
		gomega.Expect(ssPodsBeforeScaleDown.Items).NotTo(gomega.BeEmpty(),
			fmt.Sprintf("Unable to get list of Pods from the Statefulset: %v", statefulset.Name))
		gomega.Expect(len(ssPodsBeforeScaleDown.Items) == int(replicas)).To(gomega.BeTrue(),
			"Number of Pods in the statefulset should match with number of replicas")

		// Get the list of Volumes attached to Pods before scale down
		for _, sspod := range ssPodsBeforeScaleDown.Items {
			_, err := client.CoreV1().Pods(namespace).Get(ctx, sspod.Name, metav1.GetOptions{})
			gomega.Expect(err).NotTo(gomega.HaveOccurred())
			for _, volumespec := range sspod.Spec.Volumes {
				if volumespec.PersistentVolumeClaim != nil {
					pv := getPvFromClaim(client, statefulset.Namespace, volumespec.PersistentVolumeClaim.ClaimName)
					gomega.Expect(pv).NotTo(gomega.BeNil())
				}
			}
		}

		var nodeToCordon *v1.Node
		for _, node := range nodes.Items {
			if strings.Contains(node.Name, "master") || strings.Contains(node.Name, "control") {
				continue
			} else {
				nodeToCordon = &node
				ginkgo.By("Cordoning of node: " + node.Name)
				err = drain.RunCordonOrUncordon(&dh, &node, true)
				gomega.Expect(err).NotTo(gomega.HaveOccurred())
				ginkgo.By("Draining of node: " + node.Name)
				err = drain.RunNodeDrain(&dh, node.Name)
				gomega.Expect(err).NotTo(gomega.HaveOccurred())
				break
			}
		}

		framework.Logf("Allow pods to reschedule on different nodes")
		// Waiting for pods status to be Ready
		fss.WaitForStatusReadyReplicas(client, statefulset, replicas)
		gomega.Expect(fss.CheckMount(client, statefulset, mountPath)).NotTo(gomega.HaveOccurred())

		ginkgo.By(fmt.Sprintf("Scaling down statefulsets to number of Replica: %v", replicas-1))
		_, scaledownErr := fss.Scale(client, statefulset, replicas-1)
		gomega.Expect(scaledownErr).NotTo(gomega.HaveOccurred())
		fss.WaitForStatusReadyReplicas(client, statefulset, replicas-1)
		ssPodsAfterScaleDown := fss.GetPodList(client, statefulset)
		gomega.Expect(ssPodsAfterScaleDown.Items).NotTo(gomega.BeEmpty(),
			fmt.Sprintf("Unable to get list of Pods from the Statefulset: %v", statefulset.Name))
		gomega.Expect(len(ssPodsAfterScaleDown.Items) == int(replicas-1)).To(gomega.BeTrue(),
			"Number of Pods in the statefulset should match with number of replicas")

		// After scale down, verify vSphere volumes are detached from deleted pods
		ginkgo.By("Verify Volumes are detached from Nodes after Statefulsets is scaled down")
		for _, sspod := range ssPodsBeforeScaleDown.Items {
			_, err := client.CoreV1().Pods(namespace).Get(ctx, sspod.Name, metav1.GetOptions{})
			if err != nil {
				gomega.Expect(apierrors.IsNotFound(err), gomega.BeTrue())
				for _, volumespec := range sspod.Spec.Volumes {
					if volumespec.PersistentVolumeClaim != nil {
						pv := getPvFromClaim(client, statefulset.Namespace, volumespec.PersistentVolumeClaim.ClaimName)
						// pv not nil check
						gomega.Expect(pv).NotTo(gomega.BeNil())
						framework.Logf("Volume %q is not detached from the node %q",
							pv.Spec.CSI.VolumeHandle, sspod.Spec.NodeName)
					}
				}
			}
		}

		// After scale down, verify the attached volumes match
		for _, sspod := range ssPodsAfterScaleDown.Items {
			_, err := client.CoreV1().Pods(namespace).Get(ctx, sspod.Name, metav1.GetOptions{})
			gomega.Expect(err).NotTo(gomega.HaveOccurred())
			for _, volumespec := range sspod.Spec.Volumes {
				if volumespec.PersistentVolumeClaim != nil {
					pv := getPvFromClaim(client, statefulset.Namespace, volumespec.PersistentVolumeClaim.ClaimName)
					gomega.Expect(pv).NotTo(gomega.BeNil())
				}
			}
		}

		ginkgo.By("Uncordoning of node: " + nodeToCordon.Name)
		err = drain.RunCordonOrUncordon(&dh, nodeToCordon, false)
		gomega.Expect(err).NotTo(gomega.HaveOccurred())

		replicas += 2
		ginkgo.By(fmt.Sprintf("Scaling up statefulsets to number of Replica: %v", replicas))
		_, scaleupErr := fss.Scale(client, statefulset, replicas)
		gomega.Expect(scaleupErr).NotTo(gomega.HaveOccurred())
		fss.WaitForStatusReplicas(client, statefulset, replicas)
		fss.WaitForStatusReadyReplicas(client, statefulset, replicas)

		ssPodsAfterScaleUp := fss.GetPodList(client, statefulset)
		gomega.Expect(ssPodsAfterScaleUp.Items).NotTo(gomega.BeEmpty(),
			fmt.Sprintf("Unable to get list of Pods from the Statefulset: %v", statefulset.Name))
		gomega.Expect(len(ssPodsAfterScaleUp.Items) == int(replicas)).To(gomega.BeTrue(),
			"Number of Pods in the statefulset should match with number of replicas")

		// After scale up, verify all vSphere volumes are attached to node VMs.
		ginkgo.By("Verify all volumes are attached to Nodes after Statefulsets is scaled up")
		for _, sspod := range ssPodsAfterScaleUp.Items {
			err := fpod.WaitForPodRunningInNamespace(client, &sspod)
			gomega.Expect(err).NotTo(gomega.HaveOccurred())
			pod, perr := client.CoreV1().Pods(namespace).Get(ctx, sspod.Name, metav1.GetOptions{})
			gomega.Expect(perr).NotTo(gomega.HaveOccurred())
			for _, volumespec := range pod.Spec.Volumes {
				if volumespec.PersistentVolumeClaim != nil {
					pv := getPvFromClaim(client, statefulset.Namespace, volumespec.PersistentVolumeClaim.ClaimName)
					_, cancel := context.WithCancel(context.Background())
					defer cancel()
					gomega.Expect(pv).NotTo(gomega.BeNil())
				}
			}
		}

		replicas = 0
		ginkgo.By(fmt.Sprintf("Scaling down statefulsets to number of Replica: %v", replicas))
		_, scaledownErr = fss.Scale(client, statefulset, replicas)
		gomega.Expect(scaledownErr).NotTo(gomega.HaveOccurred())
		fss.WaitForStatusReplicas(client, statefulset, replicas)
		ssPodsAfterScaleDown = fss.GetPodList(client, statefulset)
		gomega.Expect(len(ssPodsAfterScaleDown.Items) == int(replicas)).To(gomega.BeTrue(),
			"Number of Pods in the statefulset should match with number of replicas")
	})
})

repository: dell/csi-powerflex

repo_name: dell/csi-powerflex

branch_name: refs/heads/main

gha_language: Go

extension: go


text:
SUMMARY = "RPB Initramfs image for kernel boot testing"
DESCRIPTION = "Small image capable of booting a device."
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"

BAD_RECOMMENDATIONS += "busybox-syslog"

IMAGE_FSTYPES = "${INITRAMFS_FSTYPES} ${INITRAMFS_FSTYPES}.u-boot"

# Do not pollute the initrd image with rootfs features
IMAGE_FEATURES = ""

# List of packages to install
IMAGE_INSTALL = "\
  base-passwd \
  bash \
  busybox \
  bzip2 \
  dhcp-client \
  dosfstools \
  e2fsprogs \
  e2fsprogs-mke2fs \
  gptfdisk \
  gzip \
  rpb-boot-initramfs \
  net-tools \
  parted \
  tar \
  u-boot-mkimage \
  udev \
  wget \
  "

# Keep extra language files from being installed
IMAGE_LINGUAS = ""

IMAGE_ROOTFS_SIZE = "8192"

inherit core-image


text:
DESCRIPTION = "GMyth is a library to access MythTV backend services."
LICENSE = "LGPLv2"
HOMEPAGE = "http://gmyth.sourceforge.net/wiki/index.php/Main_Page"

PR = "r3"

DEPENDS = "glib-2.0 mysql gmyth libupnp"

SRC_URI = "${SOURCEFORGE_MIRROR}/gmyth/${PN}_0.7-indt1.tar.gz"
S = "${WORKDIR}/${PN}"

inherit autotools

do_compile_append() {
        sed -i -e s:${STAGING_DIR_TARGET}::g \
               -e s,Version:,Version:\ 0\.7\.0,g \
               -e s:/${TARGET_SYS}::g \
               -e s:clinkc::g \
                  gmyth-upnp.pc
}

do_install_append() {
        mv ${D}/${bindir}/test ${D}/${bindir}/gmyth-upnp-test
}

SRC_URI[md5sum] = "29e58ea47e1548d70e4498cabca249a6"
SRC_URI[sha256sum] = "f028ae7b331fdac9e5e70e4827fe1bcfa0274a9539e4224a9a49441776b2b517"

repository: overo/overo-oe-natty

repo_name: overo/overo-oe-natty

branch_name: HEAD


text:
package conpass

import (
	"fmt"
	"io"
	"log"

	"github.com/mblarer/conpass/segment"
)

// Responder represents a CONPASS agent in the responder role.
type Responder struct {
	// Filter is the segment filter according to which the Responder gives
	// consent to certain segments or combinations of segments.
	Filter segment.Filter
	// Verbose is a flag which makes the Responder more verbose if true.
	Verbose bool
}

// NegotiateOver makes the Responder negotiate consent over a given bytestream.
// If the negotiation is successful, the method returns the set of segments
// that have bilateral consent. Otherwise, an error is returned.
func (agent Responder) NegotiateOver(stream io.ReadWriter) (segment.SegmentSet, error) {
	segsin, accsegs, srcIA, dstIA, err := segment.ReadSegments(stream, []segment.Segment{})
	if err != nil {
		return segment.SegmentSet{}, err
	}
	if agent.Verbose {
		log.Println("request contains", len(segsin), "segments:")
		for _, segment := range segsin {
			fmt.Println(" ", segment)
		}
	}
	segsetout := agent.Filter.Filter(segment.SegmentSet{
		Segments: accsegs,
		SrcIA:    srcIA,
		DstIA:    dstIA,
	})
	if agent.Verbose {
		log.Println("responding with", len(segsetout.Segments), "segments:")
		for _, segment := range segsetout.Segments {
			fmt.Println(" ", segment)
		}
	}
	segment.WriteSegments(stream, segsetout.Segments, segsin, srcIA, dstIA)
	return segsetout, nil
}

repository: mblarer/conpass

repo_name: mblarer/conpass


text:
SUMMARY = "A small weston gtk3 demo image for Star64"

require star64-image-minimal.bb

IMAGE_FEATURES += "splash package-management ssh-server-dropbear hwcodecs weston"

LICENSE = "MIT"

IMAGE_INSTALL:append = "  \
    packagegroup-gnome-desktop \
    packagegroup-gnome-apps \
"


text:
@proceedings{ws-2012-speech,
    title = "Proceedings of the Third Workshop on Speech and Language Processing for Assistive Technologies",
    editor = {Alexandersson, Jan  and
      Ljungl{\"o}f, Peter  and
      McCoy, Kathleen F.  and
      Roark, Brian  and
      Waller, Annalu},
    month = jun,
    year = "2012",
    address = "Montr{\'e}al, Canada",
    publisher = "Association for Computational Linguistics",
    url = "https://www.aclweb.org/anthology/W12-2900",
}
@inproceedings{ljunglof-etal-2012-free,
    title = "A free and open-source tool that reads movie subtitles aloud",
    author = {Ljungl{\"o}f, Peter  and
      Derbring, Sandra  and
      Olsson, Maria},
    booktitle = "Proceedings of the Third Workshop on Speech and Language Processing for Assistive Technologies",
    month = jun,
    year = "2012",
    address = "Montr{\'e}al, Canada",
    publisher = "Association for Computational Linguistics",
    url = "https://www.aclweb.org/anthology/W12-2901",
    pages = "1--4",
}
@inproceedings{szekely-etal-2012-winktalk,
    title = "{W}ink{T}alk: a demonstration of a multimodal speech synthesis platform linking facial expressions to expressive synthetic voices",
    author = "Sz{\'e}kely, {\'E}va  and
      Ahmed, Zeeshan  and
      Cabral, Jo{\~a}o P.  and
      Carson-Berndsen, Julie",
    booktitle = "Proceedings of the Third Workshop on Speech and Language Processing for Assistive Technologies",
    month = jun,
    year = "2012",
    address = "Montr{\'e}al, Canada",
    publisher = "Association for Computational Linguistics",
    url = "https://www.aclweb.org/anthology/W12-2902",
    pages = "5--8",
}
@inproceedings{mitchell-sproat-2012-discourse,
    title = "Discourse-Based Modeling for {AAC}",
    author = "Mitchell, Margaret  and
      Sproat, Richard",
    booktitle = "Proceedings of the Third Workshop on Speech and Language Processing for Assistive Technologies",
    month = jun,
    year = "2012",
    address = "Montr{\'e}al, Canada",
    publisher = "Association for Computational Linguistics",
    url = "https://www.aclweb.org/anthology/W12-2903",
    pages = "9--18",
}
@inproceedings{trinh-etal-2012-applying,
    title = "Applying Prediction Techniques to Phoneme-based {AAC} Systems",
    author = "Trinh, Ha  and
      Waller, Annalu  and
      Vertanen, Keith  and
      Kristensson, Per Ola  and
      Hanson, Vicki L.",
    booktitle = "Proceedings of the Third Workshop on Speech and Language Processing for Assistive Technologies",
    month = jun,
    year = "2012",
    address = "Montr{\'e}al, Canada",
    publisher = "Association for Computational Linguistics",
    url = "https://www.aclweb.org/anthology/W12-2904",
    pages = "19--27",
}
@inproceedings{wiegand-patel-2012-non,
    title = "Non-Syntactic Word Prediction for {AAC}",
    author = "Wiegand, Karl  and
      Patel, Rupal",
    booktitle = "Proceedings of the Third Workshop on Speech and Language Processing for Assistive Technologies",
    month = jun,
    year = "2012",
    address = "Montr{\'e}al, Canada",
    publisher = "Association for Computational Linguistics",
    url = "https://www.aclweb.org/anthology/W12-2905",
    pages = "28--36",
}
@inproceedings{green-etal-2012-assisting,
    title = "Assisting Social Conversation between Persons with {A}lzheimer{'}s Disease and their Conversational Partners",
    author = "Green, Nancy  and
      Guinn, Curry  and
      Smith, Ronnie",
    booktitle = "Proceedings of the Third Workshop on Speech and Language Processing for Assistive Technologies",
    month = jun,
    year = "2012",
    address = "Montr{\'e}al, Canada",
    publisher = "Association for Computational Linguistics",
    url = "https://www.aclweb.org/anthology/W12-2906",
    pages = "37--46",
}
@inproceedings{rudzicz-etal-2012-communication,
    title = "Communication strategies for a computerized caregiver for individuals with {A}lzheimer{'}s disease",
    author = "Rudzicz, Frank  and
      Wilson, Rozanne  and
      Mihailidis, Alex  and
      Rochon, Elizabeth  and
      Leonard, Carol",
    booktitle = "Proceedings of the Third Workshop on Speech and Language Processing for Assistive Technologies",
    month = jun,
    year = "2012",
    address = "Montr{\'e}al, Canada",
    publisher = "Association for Computational Linguistics",
    url = "https://www.aclweb.org/anthology/W12-2907",
    pages = "47--55",
}
@inproceedings{lohmann-etal-2012-generating,
    title = "Generating Situated Assisting Utterances to Facilitate Tactile-Map Understanding: A Prototype System",
    author = "Lohmann, Kris  and
      Eichhorn, Ole  and
      Baumann, Timo",
    booktitle = "Proceedings of the Third Workshop on Speech and Language Processing for Assistive Technologies",
    month = jun,
    year = "2012",
    address = "Montr{\'e}al, Canada",
    publisher = "Association for Computational Linguistics",
    url = "https://www.aclweb.org/anthology/W12-2908",
    pages = "56--65",
}
@inproceedings{lu-huenerfauth-2012-learning,
    title = "Learning a Vector-Based Model of {A}merican Sign Language Inflecting Verbs from Motion-Capture Data",
    author = "Lu, Pengfei  and
      Huenerfauth, Matt",
    booktitle = "Proceedings of the Third Workshop on Speech and Language Processing for Assistive Technologies",
    month = jun,
    year = "2012",
    address = "Montr{\'e}al, Canada",
    publisher = "Association for Computational Linguistics",
    url = "https://www.aclweb.org/anthology/W12-2909",
    pages = "66--74",
}
@inproceedings{bott-etal-2012-hybrid,
    title = "A Hybrid System for {S}panish Text Simplification",
    author = "Bott, Stefan  and
      Saggion, Horacio  and
      Figueroa, David",
    booktitle = "Proceedings of the Third Workshop on Speech and Language Processing for Assistive Technologies",
    month = jun,
    year = "2012",
    address = "Montr{\'e}al, Canada",
    publisher = "Association for Computational Linguistics",
    url = "https://www.aclweb.org/anthology/W12-2910",
    pages = "75--84",
}

repository: emorynlp/nlprankings

repo_name: emorynlp/nlprankings

gha_license_id: NOASSERTION

gha_language: TeX

extension: bib


text:
package webdriver

import (
	"errors"
	"fmt"
	"github.com/sclevine/agouti/core/internal/api"
	"github.com/sclevine/agouti/core/internal/page"
	"github.com/sclevine/agouti/core/internal/session"
	"github.com/sclevine/agouti/core/internal/types"
)

type Driver struct {
	Service service
	pages   []types.Page
}

type service interface {
	Start() error
	Stop()
	CreateSession(capabilities map[string]interface{}) (*session.Session, error)
}

func (d *Driver) Start() error {
	if err := d.Service.Start(); err != nil {
		return fmt.Errorf("failed to start service: %s", err)
	}

	return nil
}

func (d *Driver) Stop() {
	for _, openPage := range d.pages {
		openPage.Destroy()
	}

	d.Service.Stop()
	return
}

func (d *Driver) Page(browserName ...string) (types.Page, error) {
	capabilites := map[string]interface{}{}
	if len(browserName) == 1 {
		capabilites["browserName"] = browserName[0]
	} else if len(browserName) > 1 {
		return nil, errors.New("too many arguments")
	}

	pageSession, err := d.Service.CreateSession(capabilites)
	if err != nil {
		return nil, fmt.Errorf("failed to generate page: %s", err)
	}

	pageClient := &api.Client{Session: pageSession}
	newPage := &page.Page{Client: pageClient}
	d.pages = append(d.pages, newPage)
	return newPage, nil
}

repository: hiremaga/agouti

repo_name: hiremaga/agouti


text:
require swupdate.inc
require swupdate_tools.inc

DEFAULT_PREFERENCE = "-1"

# If a recipe sets SRCREV to ${AUTOREV}, bitbake tries
# a git ls-remote. This breaks when a mirror is built
# and BB_NO_NETWORK is set.
# To work-around the issue, sets the revision for the git
# version to a fix commit (not relevant)
# In casethe _git version is chosen, sets the revision
# to TOT to test with last commit-id.
def version_git(d):
    version = d.getVar("PREFERRED_VERSION_%s" % d.getVar('PN', False), False)
    if version is not None and "git" in version:
        return d.getVar('AUTOREV', False)
    else:
        return "c0fec16b3fc82b0db12d8ac58be7055ed1b8d439"

SRCREV ?= '${@version_git(d)}'


text:
package _1042

import (
	. "github.com/godcong/leetcode/common"
)

func gardenNoAdj(n int, paths [][]int) []int {

}

repository: godcong/leetcode

repo_name: godcong/leetcode


text:
package types

import (
	"testing"
	"time"

	"github.com/stretchr/testify/require"
	tmtypes "github.com/tendermint/tendermint/types"

	sdk "github.com/cosmos/cosmos-sdk/types"
)

func TestRewardPeriodsValidate(t *testing.T) {
	now := time.Now()

	testCases := []struct {
		msg           string
		rewardPeriods RewardPeriods
		expPass       bool
	}{
		{
			"valid",
			RewardPeriods{
				NewRewardPeriod("bnb", now, now.Add(time.Hour), sdk.NewCoin("bnb", sdk.OneInt()), now, 10),
			},
			true,
		},
		{
			"zero start time",
			RewardPeriods{
				{Start: time.Time{}},
			},
			false,
		},
		{
			"zero end time",
			RewardPeriods{
				{Start: now, End: time.Time{}},
			},
			false,
		},
		{
			"zero end time",
			RewardPeriods{
				{Start: now, End: time.Time{}},
			},
			false,
		},
		{
			"start time > end time",
			RewardPeriods{
				{
					Start: now.Add(time.Hour),
					End:   now,
				},
			},
			false,
		},
		{
			"invalid reward",
			RewardPeriods{
				{
					Start:  now,
					End:    now.Add(time.Hour),
					Reward: sdk.Coin{Denom: "", Amount: sdk.ZeroInt()},
				},
			},
			false,
		},
		{
			"zero claim end time",
			RewardPeriods{
				{
					Start:    now,
					End:      now.Add(time.Hour),
					Reward:   sdk.NewCoin("bnb", sdk.OneInt()),
					ClaimEnd: time.Time{},
				},
			},
			false,
		},
		{
			"zero claim time lock",
			RewardPeriods{
				{
					Start:         now,
					End:           now.Add(time.Hour),
					Reward:        sdk.NewCoin("bnb", sdk.OneInt()),
					ClaimEnd:      now,
					ClaimTimeLock: 0,
				},
			},
			false,
		},
		{
			"invalid denom",
			RewardPeriods{
				{
					Start:         now,
					End:           now.Add(time.Hour),
					Reward:        sdk.NewCoin("bnb", sdk.OneInt()),
					ClaimEnd:      now,
					ClaimTimeLock: 10,
					Denom:         "",
				},
			},
			false,
		},
		{
			"duplicate reward period",
			RewardPeriods{
				NewRewardPeriod("bnb", now, now.Add(time.Hour), sdk.NewCoin("bnb", sdk.OneInt()), now, 10),
				NewRewardPeriod("bnb", now, now.Add(time.Hour), sdk.NewCoin("bnb", sdk.OneInt()), now, 10),
			},
			false,
		},
	}

	for _, tc := range testCases {
		err := tc.rewardPeriods.Validate()
		if tc.expPass {
			require.NoError(t, err, tc.msg)
		} else {
			require.Error(t, err, tc.msg)
		}
	}
}

func TestClaimPeriodsValidate(t *testing.T) {
	now := time.Now()

	testCases := []struct {
		msg          string
		claimPeriods ClaimPeriods
		expPass      bool
	}{
		{
			"valid",
			ClaimPeriods{
				NewClaimPeriod("bnb", 10, now, 100),
			},
			true,
		},
		{
			"invalid ID",
			ClaimPeriods{
				{ID: 0},
			},
			false,
		},
		{
			"zero end time",
			ClaimPeriods{
				{ID: 10, End: time.Time{}},
			},
			false,
		},
		{
			"zero time lock",
			ClaimPeriods{
				{ID: 10, End: now, TimeLock: 0},
			},
			false,
		},
		{
			"start time > end time",
			ClaimPeriods{
				{ID: 10, End: now, TimeLock: 0},
			},
			false,
		},
		{
			"invalid denom",
			ClaimPeriods{
				{ID: 10, End: now, TimeLock: 100, Denom: ""},
			},
			false,
		},
		{
			"duplicate reward period",
			ClaimPeriods{
				NewClaimPeriod("bnb", 10, now, 100),
				NewClaimPeriod("bnb", 10, now, 100),
			},
			false,
		},
	}

	for _, tc := range testCases {
		err := tc.claimPeriods.Validate()
		if tc.expPass {
			require.NoError(t, err, tc.msg)
		} else {
			require.Error(t, err, tc.msg)
		}
	}
}

func TestClaimsValidate(t *testing.T) {
	mockPrivKey := tmtypes.NewMockPV()
	pubkey, err := mockPrivKey.GetPubKey()
	require.NoError(t, err)
	owner := sdk.AccAddress(pubkey.Address())

	testCases := []struct {
		msg     string
		claims  Claims
		expPass bool
	}{
		{
			"valid",
			Claims{
				NewClaim(owner, sdk.NewCoin("bnb", sdk.OneInt()), "bnb", 10),
			},
			true,
		},
		{
			"invalid owner",
			Claims{
				{Owner: nil},
			},
			false,
		},
		{
			"invalid reward",
			Claims{
				{
					Owner:  owner,
					Reward: sdk.Coin{Denom: "", Amount: sdk.ZeroInt()},
				},
			},
			false,
		},
		{
			"zero claim period id",
			Claims{
				{
					Owner:         owner,
					Reward:        sdk.NewCoin("bnb", sdk.OneInt()),
					ClaimPeriodID: 0,
				},
			},
			false,
		},
		{
			"invalid denom",
			Claims{
				{
					Owner:         owner,
					Reward:        sdk.NewCoin("bnb", sdk.OneInt()),
					ClaimPeriodID: 10,
					Denom:         "",
				},
			},
			false,
		},
		{
			"duplicate reward period",
			Claims{
				NewClaim(owner, sdk.NewCoin("bnb", sdk.OneInt()), "bnb", 10),
				NewClaim(owner, sdk.NewCoin("bnb", sdk.OneInt()), "bnb", 10),
			},
			false,
		},
	}

	for _, tc := range testCases {
		err := tc.claims.Validate()
		if tc.expPass {
			require.NoError(t, err, tc.msg)
		} else {
			require.Error(t, err, tc.msg)
		}
	}
}

repository: neukind/jpyx

repo_name: neukind/jpyx


text:
// Copyright 2020 Clivern. All rights reserved.
// Use of this source code is governed by the MIT
// license that can be found in the LICENSE file.

package agent

import (
	"time"

	"github.com/clivern/walrus/core/module"
	"github.com/clivern/walrus/core/service"

	log "github.com/sirupsen/logrus"
	"github.com/spf13/viper"
)

// Heartbeat function
func Heartbeat() {
	httpClient := service.NewHTTPClient(30)
	agent := module.NewAgent(httpClient)

	for {
		log.Info(`Agent heartbeat`)

		err := agent.Heartbeat()

		if err != nil {
			log.WithFields(log.Fields{
				"error": err.Error(),
			}).Error(`Error while calling tower`)

			time.Sleep(time.Duration(viper.GetInt("agent.tower.pingInterval")) * time.Second)
			continue
		}

		time.Sleep(time.Duration(viper.GetInt("agent.tower.pingInterval")) * time.Second)
	}
}

repository: hyeio/Walrus

repo_name: hyeio/Walrus


text:
---
---

@Article{fire5050147,
    AUTHOR = {Marsha, Amy and Larkin, Narasimhan K.},
    TITLE = {Evaluating Satellite Fire Detection Products and an Ensemble Approach for Estimating Burned Area in the United States},
    JOURNAL = {Fire},
    VOLUME = {5},
    YEAR = {2022},
    NUMBER = {5},
    ARTICLE-NUMBER = {147},
    URL = {https://www.mdpi.com/2571-6255/5/5/147},
    ISSN = {2571-6255},
    ABSTRACT = {Fire location and burning area are essential parameters for estimating fire emissions. However, ground-based fire data (such as fire perimeters from incident reports) are often not available with the timeliness required for real-time forecasting. Fire detection products derived from satellite instruments such as the GOES-16 Advanced Baseline Imager or MODIS, on the other hand, are available in near real-time. Using a ground fire dataset of 2699 fires during 2017–2019, we fit a series of linear models that use multiple satellite fire detection products (HMS aggregate fire product, GOES-16, MODIS, and VIIRS) to assess the ability of satellite data to detect and estimate total burned area. It was found that on average models fit with fire detections from GOES-16 products performed better than those developed from other satellites in the study (modelled R2 = 0.84 and predictive R2 = 0.88). However, no single satellite product was found to best estimate incident burned area, highlighting the need for an ensemble approach. With our proposed modelling ensemble, we demonstrate its ability to estimate burned area and suggest its further use in daily fire tracking and emissions-modeling frameworks.},
    DOI = {10.3390/fire5050147},
    bibtex_show={true},
    selected={true},
    preview={Evaluating-satellite-fire-detection-products-and-an-ensemble-approach-for-estimating-burned-area-in-the-United-States.png}
}

@article{doi:10.1080/10962247.2021.1891994,
    author = {Susan M. O'Neill and Minghui Diao and Sean Raffuse and Mohammad Al-Hamdan and Muhammad Barik and Yiqin Jia and Steve Reid and Yufei Zou and Daniel Tong and J. Jason West and Joseph Wilkins and Amy Marsha and Frank Freedman and Jason Vargo and Narasimhan K. Larkin and Ernesto Alvarado and Patti Loesche},
    title = {A multi-analysis approach for estimating regional health impacts from the 2017 Northern California wildfires},
    journal = {Journal of the Air \& Waste Management Association},
    volume = {71},
    number = {7},
    pages = {791-814},
    year  = {2021},
    publisher = {Taylor & Francis},
    doi = {10.1080/10962247.2021.1891994},
    URL = {https://doi.org/10.1080/10962247.2021.1891994},
    abstract = {Smoke impacts from large wildfires are mounting, and the projection is for more such events in the future as the one experienced October 2017 in Northern California, and subsequently in 2018 and 2020. Further, the evidence is growing about the health impacts from these events which are also difficult to simulate. Therefore, we simulated air quality conditions using a suite of remotely-sensed data, surface observational data, chemical transport modeling with WRF-CMAQ, one data fusion, and three machine learning methods to arrive at datasets useful to air quality and health impact analyses. To demonstrate these analyses, we estimated the health impacts from smoke impacts during wildfires in October 8â20, 2017, in Northern California, when over 7 million people were exposed to Unhealthy to Very Unhealthy air quality conditions. We investigated using the 5-min available GOES-16 fire detection data to simulate timing of fire activity to allocate emissions hourly for the WRF-CMAQ system. Interestingly, this approach did not necessarily improve overall results, however it was key to simulating the initial 12-hr explosive fire activity and smoke impacts. To improve these results, we applied one data fusion and three machine learning algorithms. We also had a unique opportunity to evaluate results with temporary monitors deployed specifically for wildfires, and performance was markedly different. For example, at the permanent monitoring locations, the WRF-CMAQ simulations had a Pearson correlation of 0.65, and the data fusion approach improved this (Pearson correlationÂ =Â 0.95), while at the temporary monitor locations across all cases, the best Pearson correlation was 0.5. Overall, WRF-CMAQ simulations were biased high and the geostatistical methods were biased low. Finally, we applied the optimized PM2.5 exposure estimate in an exposure-response function. Estimated mortality attributable to PM2.5 exposure during the smoke episode was 83 (95\% CI: 0, 196) with 47\% attributable to wildland fire smoke.Implications: Large wildfires in the United States and in particular California are becoming increasingly common. Associated with these large wildfires are air quality and health impact to millions of people from the smoke. We simulated air quality conditions using a suite of remotely-sensed data, surface observational data, chemical transport modeling, one data fusion, and three machine learning methods to arrive at datasets useful to air quality and health impact analyses from the October 2017 Northern California wildfires. Temporary monitors deployed for the wildfires provided an important model evaluation dataset. Total estimated regional mortality attributable to PM2.5 exposure during the smoke episode was 83 (95\% confidence interval: 0, 196) with 47\% of these deaths attributable to the wildland fire smoke. This illustrates the profound effect that even a 12-day exposure to wildland fire smoke can have on human health. },
    bibtex_show={true},
    preview={A-multi-analysis-approach-for-estimating-regional-health-impacts-from-the-2017-Northern-California-wildfires.png}
}

@article{doi:10.1086/713038,
    author = {Marsha, Amy and Steel, E. Ashley and Fullerton, Aimee H.},
    title = {Modeling thermal metrics of importance for native vs non-native fish across stream networks to provide insight for watershed-scale fisheries management},
    journal = {Freshwater Science},
    volume = {40},
    number = {1},
    pages = {120-137},
    year = {2021},
    doi = {10.1086/713038},
    URL = {https://doi.org/10.1086/713038},
    abstract = {Water temperatures on river networks fluctuate in time and over space. This variation creates complex thermal regimes through which fishes move over the course of their lives. Using water temperature data collected every 30 min for 6 y at 45 locations throughout the Snoqualmie River Basin, Washington, USA, we developed a set of metrics representing facets of the thermal regime important to native Chinook Salmon (Oncorhynchus tshawytscha) and Bull Trout (Salvelinus confluentus) and to non-native Largemouth Bass (Micropterus salmoides) during multiple life-history stages. We modeled these facets using spatial stream network models (SSNMs) built from covariates describing landform, land use, and climate to better understand the potential ecological drivers of thermal habitats for these fishes. The explanatory power (predictive r2) of the final SSNMs ranged from 23 to 97\%, with at least Âœ the models >69\%. The best models tended to include climate and landform covariates, with elevation and mean annual air temperature most often included. The relative contribution of each SSNM component differed by species: thermal metric models for Chinook Salmon tended to have a covariate- and site-based structure, those for Bull Trout tended to have a yearly structure, and those for Largemouth Bass tended to have a spatial structure. We applied our models to map the thermal landscape in ways that should be of particular interest to fish managers. Given the challenging lack of empirical data for rare fish species or fish species that are currently not present, we illustrate how the proliferation of fine-scale temperature data can be leveraged to provide ecological insight. For example, we identified several tributaries and small low-elevation reaches as areas potentially worthy of protection efforts for Chinook Salmon, and we identified the mainstem Snoqualmie River as an area of potential interaction between native salmon and non-native bass. },
    bibtex_show={true},
    preview={Modeling-thermal-metrics-of-importance-for-native-vs-non-native-fish-across-stream-networks-to-provide-insight-for-watershed-scale-fisheries-management.png}
}

@article{doi:10.1080/10962247.2019.1640808,
    author = {Amy Marsha and Narasimhan K. Larkin},
    title = {A statistical model for predicting PM2.5 for the western United States},
    journal = {Journal of the Air \& Waste Management Association},
    volume = {69},
    number = {10},
    pages = {1215-1229},
    year  = {2019},
    publisher = {Taylor & Francis},
    doi = {10.1080/10962247.2019.1640808},
    URL = {https://doi.org/10.1080/10962247.2019.1640808},
    abstract = {A new statistical model for predicting daily ground level fine scale particulate matter (PM2.5) concentrations at monitoring sites in the western United States was developed and tested operationally during the 2016 and 2017 wildfire seasons. The model is site-specific, using a multiple linear regression schema that relies on the previous dayâs PM2.5 value, along with fire and smoke related variables from satellite observations. Fire variables include fire radiative power (FRP) and the National Fire Danger Rating System Energy Release Component index. Smoke variables, in addition to ground monitored PM2.5, include aerosol optical depth (AOD) and smoke plume perimeters from the National Oceanic and Atmospheric Administrationâs Hazard Mapping System. The overall statistical model was inspired by a similar system developed for British Columbia (BC) by the BC Center for Disease Control, but it has been heavily modified and adapted to work in the United States. On average, our statistical model was able to explain 78\% of the variance in daily ground level PM2.5. A novel method for implementation of this model as an operational forecast system was also developed and was tested and used during the 2016 and 2017 wildfire seasons. This method focused on producing a continuously-updating prediction that incorporated the latest information available throughout the day, including both updated remote sensing data and real-time PM2.5 observations. The diurnal pattern of performance of this model shows that even a few hours of data early in the morning can substantially improve model performance.Implications: Wildfire smoke events produce significant air quality impacts across the western United States each year impacting millions. We present and evaluate a statistical model for making updating predictions of fine particulate (PM2.5) levels during smoke events. These predictions run hourly and are being used by smoke incident specialists assigned to wildfire operations, and may be of interest to public health officials, air quality regulators, and the public. Predictions based on this model will be available on the web for the 2019 western U.S. wildfire season this summer. },
    bibtex_show={true},
    selected={true},
    preview={A-statistical-model-for-predicting-PM25-for-the-western-United-States.png}
}

@article{doi:10.1139/cjfas-2018-0244,
    author = {Steel, E. Ashley and Marsha, Amy and Fullerton, Aimee H. and Olden, Julian D. and Larkin, Narasimhan K. and Lee, Se-Yeun and Ferguson, Akida},
    title = {Thermal landscapes in a changing climate: biological implications of water temperature patterns in an extreme year},
    journal = {Canadian Journal of Fisheries and Aquatic Sciences},
    volume = {76},
    number = {10},
    pages = {1740-1756},
    year = {2019},
    doi = {10.1139/cjfas-2018-0244},
    URL = {https://doi.org/10.1139/cjfas-2018-0244},
    abstract = {Record-breaking droughts and high temperatures in 2015 across the Pacific Northwest, USA, provide an opportunistic glimpse into potential future thermal regimes of rivers and their implications for freshwater fishes. We applied spatial stream network models to data collected every 30 min for 4 years at 42 sites on the Snoqualmie River (Washington, United States) to compare water temperature patterns, summarized with relevance to particular life stages of native and nonnative fishes, in 2015 with more typical conditions (2012â2014). Although 2015 conditions were drier and warmer than what had been observed since 1960, patterns were neither consistent over the year nor on the network. Some locations showed dramatic increases in air and water temperature, whereas others had temperatures that differed little from typical years; these results contrasted with existing forecasts of future thermal landscapes. If we will observe years like 2015 more frequently in the future, we can expect conditions to be less favorable to native, cool-water fishes such as Chinook salmon (Oncorhynchus tshawytscha) and bull trout (Salvelinus confluentus) but beneficial to warm-water nonnative species such as largemouth bass (Micropterus salmoides). },
    bibtex_show={true},
    selected={true},
    preview={Thermal-landscapes-in-a-changing-climate-biological-implications-of-water-temperature-patterns-in-an-extreme-year-alt.png}
}

@Article{Marsha2018,
    author={Marsha, Amy
        and Sain, S. R.
        and Heaton, M. J.
        and Monaghan, A. J.
        and Wilhelmi, O. V.},
    title={Influences of climatic and population changes on heat-related mortality in Houston, Texas, USA},
    journal={Climatic Change},
    year={2018},
    month={Feb},
    day={01},
    volume={146},
    number={3},
    pages={471-485},
    abstract={Extreme heat is a significant public health challenge in urban environments that disproportionally impacts vulnerable members of society. In this research, demographic, economic and climate projections are brought together with a statistical approach linking extreme heat and mortality in Houston, Texas. The sensitivity of heat-related non-accidental mortality to future changes of demographics, income and climate is explored. We compare climate change outcomes associated with two different Representative Concentration Pathways (RCPs), RCP4.5 and RCP8.5, which describe alternate future scenarios for greenhouse gas emissions and concentrations. For each RCP, we explore demographic and economic scenarios for two plausible Shared Socioeconomic Pathways (SSPs), SSP3 and SSP5. Our findings suggest that non-accidental mortality in 2061--2080 may increase for all combinations of RCP and SSP scenarios compared to a historical reference period spanning 1991--2010. Notably, increased heat-related non-accidental mortality is associated with changes in the size and age of the population, but the degree of sensitivity is highly uncertain given the breadth of plausible socioeconomic scenarios. Beyond socioeconomic changes, climate change is also important. For each socioeconomic scenario, non-accidental mortality associated with the lower emissions RCP4.5 scenario is projected to be 50 {\%} less than mortality projected under the higher emissions RCP8.5 scenario.},
    issn={1573-1480},
    doi={10.1007/s10584-016-1775-1},
    url={https://doi.org/10.1007/s10584-016-1775-1},
    bibtex_show={true},
    preview={Influences-of-climatic-and-population-changes-on-heat-related-mortality-in-Houston-Texas-USA.png}
}

@article{MARSHA201811,
    title = {Monitoring riverine thermal regimes on stream networks: Insights into spatial sampling designs from the Snoqualmie River, WA},
    journal = {Ecological Indicators},
    volume = {84},
    pages = {11-26},
    year = {2018},
    issn = {1470-160X},
    doi = {https://doi.org/10.1016/j.ecolind.2017.08.028},
    url = {https://www.sciencedirect.com/science/article/pii/S1470160X17305186},
    author = {Amy Marsha and E. Ashley Steel and Aimee H. Fullerton and Colin Sowder},
    keywords = {Water temperature, SSNM, Streams, Rivers, Spatial autocorrelation, Monitoring},
    abstract = {Understanding, predicting, and managing the spatiotemporal complexity of stream thermal regimes requires monitoring strategies designed specifically to make inference about spatiotemporal variability on the whole stream network. Moreover, monitoring can be tailored to capture particular facets of this complex thermal landscape that may be important indicators for species and life stages of management concern. We applied spatial stream network models (SSNMs) to an empirical dataset of water temperature from the Snoqualmie River watershed, WA, and use results to provide guidance with respect to necessary sample size, location of new sites, and selection of a modeling approach. As expected, increasing the number of monitoring stations improved both predictive precision and the ability to estimate covariates of stream temperature; however, even relatively small numbers of monitoring stations, n=20, did an adequate job when well-distributed and when used to build models with only a few covariates. In general, winter data were easier to model and, across seasons, mean temperatures were easier to model than summer maximums, winter minimums, or variance. Adding new sites was advantageous but we did not observe major differences in model performance for particular new site locations. Adding sites from parts of the river network with thermal regimes which differed from the rest of the network, and which were therefore highly influential, improved nearby predictions but reduced model-estimated precision of predictions in the rest of the network. Lastly, using models which accounted for the network-based spatial correlation between observations made it much more likely that estimated prediction confidence intervals covered the true parameter; the exact form of the spatial correlation made little difference. By incorporating spatial structure between observations, SSNMs are particularly valuable for accurate estimation of prediction uncertainty at unmeasured locations. Based on our results, we make the following suggestions for designing water temperature monitoring arrays: (1) make use of pilot data when possible; (2) maintain a distribution of monitors across the stream network (i.e., over space and across the full range of covariates); (3) maintain multiple spatial clusters for more accurately estimating correlation of nearby sites; (4) if sites are to be added, prioritize capturing a range of covariates over adding new tributaries; (5) maintain a sensor array in winter; and (6) expect reduced accuracy and precision when predicting metrics other than means.},
    bibtex_show={true},
    preview={Monitoring-riverine-thermal-regimes-on-stream-networks-insights-into-spatial-sampling-designs-from-the-Snoqualmie-River-WA.png}
}


text:
package misc

import (
	"fmt"
	"testing"
)

func TestMakeMd5(t *testing.T) {
	pass := "admin"
	fmt.Println(MakeMd5(pass))
}


text:
@article{pmid24420553,
 author = {Stergiou, G. S.  and Asayama, K.  and Thijs, L.  and Kollias, A.  and Niiranen, T. J.  and Hozawa, A.  and Boggia, J.  and Johansson, J. K.  and Ohkubo, T.  and Tsuji, I.  and Jula, A. M.  and Imai, Y.  and Staessen, J. A. },
 journal = {Hypertension},
 keywords = {intarticle},
 month = {Apr},
 number = {4},
 pages = {675--682},
 title = {Prognosis of white-coat and masked hypertension: International Database of HOme blood pressure in relation to Cardiovascular Outcome},
 volume = {63},
 year = {2014}
}

repository: hypertensioncenter/academic-kickstart

repo_name: hypertensioncenter/academic-kickstart


text:
%# -*- coding: utf-8-unix -*-

@inproceedings{Defining-Privacy-for-Data,
  title={Defining privacy for data mining},
  author={Clifton, Chris and Kantarcioglu, Murat and Vaidya, Jaideep},
  booktitle={National Science Foundation Workshop on Next Generation Data Mining},
  volume={1},
  number={26},
  pages={1},
  year={2002},
  organization={Citeseer}
}
@article{l-diversity,
  title={l-diversity: Privacy beyond k-anonymity},
  author={Machanavajjhala, Ashwin and Kifer, Daniel and Gehrke, Johannes and Venkitasubramaniam, Muthuramakrishnan},
  journal={ACM Transactions on Knowledge Discovery from Data (TKDD)},
  volume={1},
  number={1},
  pages={3},
  year={2007},
  publisher={ACM}
}

@article{dp-summary,
  title={面向数据库应用的隐私保护研究综述},
  author={周水庚 and 李丰 and 陶宇飞 and 肖小奎},
  journal={计算机学报},
  volume={32},
  number={5},
  pages={847--861},
  year={2009}
}

@inproceedings{m-Invariance,
  title={M-invariance: towards privacy preserving re-publication of dynamic datasets},
  author={Xiao, Xiaokui and Tao, Yufei},
  booktitle={Proceedings of the 2007 ACM SIGMOD international conference on Management of data},
  pages={689--700},
  year={2007},
  organization={ACM}
}

@inproceedings{clustering,
  title={Privacy-preserving k-means clustering over vertically partitioned data},
  author={Vaidya, Jaideep and Clifton, Chris},
  booktitle={Proceedings of the ninth ACM SIGKDD international conference on Knowledge discovery and data mining},
  pages={206--215},
  year={2003},
  organization={ACM}
}

@inproceedings{multidimensional-k-anonymity,
  title={Mondrian multidimensional k-anonymity},
  author={LeFevre, Kristen and DeWitt, David J and Ramakrishnan, Raghu},
  booktitle={Data Engineering, 2006. ICDE'06. Proceedings of the 22nd International Conference on},
  pages={25--25},
  year={2006},
  organization={IEEE}
}

@inproceedings{closeness,
  title={t-closeness: Privacy beyond k-anonymity and l-diversity},
  author={Li, Ninghui and Li, Tiancheng and Venkatasubramanian, Suresh},
  booktitle={Data Engineering, 2007. ICDE 2007. IEEE 23rd International Conference on},
  pages={106--115},
  year={2007},
  organization={IEEE}
}

@article{Distributed-Privacy,
  title={Distributed privacy-preserving aggregation of metering data in smart grids},
  author={Rottondi, Cristina and Verticale, Giacomo and Krauss, Christopher},
  journal={Selected Areas in Communications, IEEE Journal on},
  volume={31},
  number={7},
  pages={1342--1354},
  year={2013},
  publisher={IEEE}
}

@book{distortion,
  title={An integrated framework for database privacy protection},
  author={Chang, LiWu and Moskowitz, Ira S},
  year={2001},
  publisher={Springer}
}

@inproceedings{secret,
  title={How to generate and exchange secrets},
  author={Yao, Andrew},
  booktitle={Foundations of Computer Science, 1986., 27th Annual Symposium on},
  pages={162--167},
  year={1986},
  organization={IEEE}
}

@article{generalization,
  title={Achieving k-anonymity privacy protection using generalization and suppression},
  author={Sweeney, Latanya},
  journal={International Journal of Uncertainty, Fuzziness and Knowledge-Based Systems},
  volume={10},
  number={05},
  pages={571--588},
  year={2002},
  publisher={World Scientific}
}

@incollection{dwork1,
  title={Differential privacy},
  author={Dwork, Cynthia},
  booktitle={Encyclopedia of Cryptography and Security},
  pages={338--340},
  year={2011},
  publisher={Springer}
}

@incollection{dwork2,
  title={Differential privacy: A survey of results},
  author={Dwork, Cynthia},
  booktitle={Theory and applications of models of computation},
  pages={1--19},
  year={2008},
  publisher={Springer}
}

@incollection{Dwork-Calibrating,
  title={Calibrating noise to sensitivity in private data analysis},
  author={Dwork, Cynthia and McSherry, Frank and Nissim, Kobbi and Smith, Adam},
  booktitle={Theory of cryptography},
  pages={265--284},
  year={2006},
  publisher={Springer}
}

@inproceedings{2007mechanism,
  title={Mechanism design via differential privacy},
  author={McSherry, Frank and Talwar, Kunal},
  booktitle={Foundations of Computer Science, 2007. FOCS'07. 48th Annual IEEE Symposium on},
  pages={94--103},
  year={2007},
  organization={IEEE}
}

@article{interactive,
  title={Low-rank mechanism: Optimizing batch queries under differential privacy},
  author={Yuan, Ganzhao and Zhang, Zhenjie and Winslett, Marianne and Xiao, Xiaokui and Yang, Yin and Hao, Zhifeng},
  journal={Proceedings of the VLDB Endowment},
  volume={5},
  number={11},
  pages={1352--1363},
  year={2012},
  publisher={VLDB Endowment}
}

@article{non-interactive,
  title={A learning theory approach to noninteractive database privacy},
  author={Blum, Avrim and Ligett, Katrina and Roth, Aaron},
  journal={Journal of the ACM (JACM)},
  volume={60},
  number={2},
  pages={12},
  year={2013},
  publisher={ACM}
}

@article{k-anonymity,
  title={k-anonymity: A model for protecting privacy},
  author={Sweeney, Latanya},
  journal={International Journal of Uncertainty, Fuzziness and Knowledge-Based Systems},
  volume={10},
  number={05},
  pages={557--570},
  year={2002},
  publisher={World Scientific}
}

@article{dom,
  title={隐私保护中 K-匿名模型的综述},
  author={岑婷婷 and 韩建民 and 王基一 and 李细雨},
  journal={计算机工程与应用},
  volume={44},
  number={4},
  pages={130--134},
  year={2008}
}

@article{decision-tree,
  title={Induction of decision trees},
  author={Quinlan, J. Ross},
  journal={Machine learning},
  volume={1},
  number={1},
  pages={81--106},
  year={1986},
  publisher={Springer}
}

@book{c45,
  title={C4. 5: programs for machine learning},
  author={Quinlan, J Ross},
  year={2014},
  publisher={Elsevier}
}

@book{cart,
  title={Classification and regression trees},
  author={Breiman, Leo and Friedman, Jerome and Stone, Charles J and Olshen, Richard A},
  year={1984},
  publisher={CRC press}
}

@inproceedings{compounding-attack,
  title={Composition attacks and auxiliary information in data privacy},
  author={Ganta, Srivatsava Ranjit and Kasiviswanathan, Shiva Prasad and Smith, Adam},
  booktitle={Proceedings of the 14th ACM SIGKDD international conference on Knowledge discovery and data mining},
  pages={265--273},
  year={2008},
  organization={ACM}
}

@article{background-attack,
  title={Can the utility of anonymized data be used for privacy breaches?},
  author={Wong, Raymond Chi-Wing and Fu, Ada Wai-Chee and Wang, Ke and Yu, Philip S and Pei, Jian},
  journal={ACM Transactions on Knowledge Discovery from Data (TKDD)},
  volume={5},
  number={3},
  pages={16},
  year={2011},
  publisher={ACM}
}

@inproceedings{information-loss,
  title={Utility-based anonymization using local recoding},
  author={Xu, Jian and Wang, Wei and Pei, Jian and Wang, Xiaoyuan and Shi, Baile and Fu, Ada Wai-Chee},
  booktitle={Proceedings of the 12th ACM SIGKDD international conference on Knowledge discovery and data mining},
  pages={785--790},
  year={2006},
  organization={ACM}
}

@inproceedings{anonymity-np,
  title={On the complexity of optimal k-anonymity},
  author={Meyerson, Adam and Williams, Ryan},
  booktitle={Proceedings of the twenty-third ACM SIGMOD-SIGACT-SIGART symposium on Principles of database systems},
  pages={223--228},
  year={2004},
  organization={ACM}
}

@inproceedings{bottom-up-generalization,
  title={Bottom-up generalization: A data mining solution to privacy protection},
  author={Wang, Ke and Yu, Philip S and Chakraborty, Sourav},
  booktitle={Data Mining, 2004. ICDM'04. Fourth IEEE International Conference on},
  pages={249--256},
  year={2004},
  organization={IEEE}
}

@inproceedings{top-down-specialization,
  title={Top-down specialization for information and privacy preservation},
  author={Fung, Benjamin and Wang, Ke and Yu, Philip S},
  booktitle={Data Engineering, 2005. ICDE 2005. Proceedings. 21st International Conference on},
  pages={205--216},
  year={2005},
  organization={IEEE}
}

@inproceedings{SuLQ,
  title={Practical privacy: the SuLQ framework},
  author={Blum, Avrim and Dwork, Cynthia and McSherry, Frank and Nissim, Kobbi},
  booktitle={Proceedings of the twenty-fourth ACM SIGMOD-SIGACT-SIGART symposium on Principles of database systems},
  pages={128--138},
  year={2005},
  organization={ACM}
}

@inproceedings{diffp-c4.5,
  title={Data mining with differential privacy},
  author={Friedman, Arik and Schuster, Assaf},
  booktitle={Proceedings of the 16th ACM SIGKDD international conference on Knowledge discovery and data mining},
  pages={493--502},
  year={2010},
  organization={ACM}
}

@inproceedings{exponential,
  title={Mechanism design via differential privacy},
  author={McSherry, Frank and Talwar, Kunal},
  booktitle={Foundations of Computer Science, 2007. FOCS'07. 48th Annual IEEE Symposium on},
  pages={94--103},
  year={2007},
  organization={IEEE}
}

@inproceedings{contingency,
  title={Accurate and efficient private release of datacubes and contingency tables},
  author={Yaroslavtsev, Grigory and Cormode, Graham and Procopiuc, Cecilia M and Srivastava, Divesh},
  booktitle={Data Engineering (ICDE), 2013 IEEE 29th International Conference on},
  pages={745--756},
  year={2013},
  organization={IEEE}
}

@article{dp-histogram,
  title={Differentially private histogram publication},
  author={Xu, Jia and Zhang, Zhenjie and Xiao, Xiaokui and Yang, Yin and Yu, Ge and Winslett, Marianne},
  journal={The VLDB Journal—The International Journal on Very Large Data Bases},
  volume={22},
  number={6},
  pages={797--822},
  year={2013},
  publisher={Springer-Verlag New York, Inc.}
}

@inproceedings{cube,
  title={Differentially private data cubes: optimizing noise sources and consistency},
  author={Ding, Bolin and Winslett, Marianne and Han, Jiawei and Li, Zhenhui},
  booktitle={Proceedings of the 2011 ACM SIGMOD International Conference on Management of data},
  pages={217--228},
  year={2011},
  organization={ACM}
}

@inproceedings{privacy-accuracy-consistency,
  title={Privacy, accuracy, and consistency too: a holistic solution to contingency table release},
  author={Barak, Boaz and Chaudhuri, Kamalika and Dwork, Cynthia and Kale, Satyen and McSherry, Frank and Talwar, Kunal},
  booktitle={Proceedings of the twenty-sixth ACM SIGMOD-SIGACT-SIGART symposium on Principles of database systems},
  pages={273--282},
  year={2007},
  organization={ACM}
}

@inproceedings{marginals,
  title={Privacy, accuracy, and consistency too: a holistic solution to contingency table release},
  author={Barak, Boaz and Chaudhuri, Kamalika and Dwork, Cynthia and Kale, Satyen and McSherry, Frank and Talwar, Kunal},
  booktitle={Proceedings of the twenty-sixth ACM SIGMOD-SIGACT-SIGART symposium on Principles of database systems},
  pages={273--282},
  year={2007},
  organization={ACM}
}

@inproceedings{privbayes,
  title={Privbayes: Private data release via bayesian networks},
  author={Zhang, Jun and Cormode, Graham and Procopiuc, Cecilia M and Srivastava, Divesh and Xiao, Xiaokui},
  booktitle={Proceedings of the 2014 ACM SIGMOD international conference on Management of data},
  pages={1423--1434},
  year={2014},
  organization={ACM}
}

@article{wavelet,
  title={Differential privacy via wavelet transforms},
  author={Xiao, Xiaokui and Wang, Guozhang and Gehrke, Johannes},
  journal={Knowledge and Data Engineering, IEEE Transactions on},
  volume={23},
  number={8},
  pages={1200--1214},
  year={2011},
  publisher={IEEE}
}

@article{boosting,
  title={Boosting the accuracy of differentially-private queries through consistency},
  author={Hay, Michael and Rastogi, Vibhor and Miklau, Gerome and Suciu, Dan},
  journal={CoRR, abs/0904.0942, April},
  year={2009}
}

@inproceedings{dp-combination,
  title={Privacy integrated queries: an extensible platform for privacy-preserving data analysis},
  author={McSherry, Frank D},
  booktitle={Proceedings of the 2009 ACM SIGMOD International Conference on Management of data},
  pages={19--30},
  year={2009},
  organization={ACM}
}

@article{adult,
  title={$\{$UCI$\}$ Repository of machine learning databases},
  author={Blake, Catherine and Merz, Christopher J},
  year={1998}
}

@inproceedings{DiffGen,
  title={Differentially private data release for data mining},
  author={Mohammed, Noman and Chen, Rui and Fung, Benjamin and Yu, Philip S},
  booktitle={Proceedings of the 17th ACM SIGKDD international conference on Knowledge discovery and data mining},
  pages={493--501},
  year={2011},
  organization={ACM}
}

@article{overfitting,
  title={The problem of overfitting},
  author={Hawkins, Douglas M},
  journal={Journal of chemical information and computer sciences},
  volume={44},
  number={1},
  pages={1--12},
  year={2004},
  publisher={ACS Publications}
}

@inproceedings{composition,
  title={Privacy integrated queries: an extensible platform for privacy-preserving data analysis},
  author={McSherry, Frank D},
  booktitle={Proceedings of the 2009 ACM SIGMOD International Conference on Management of data},
  pages={19--30},
  year={2009},
  organization={ACM}
}

@inproceedings{gauss_markov,
  title={Interactive privacy via the median mechanism},
  author={Roth, Aaron and Roughgarden, Tim},
  booktitle={Proceedings of the forty-second ACM symposium on Theory of computing},
  pages={765--774},
  year={2010},
  organization={ACM}
}

@inproceedings{sparse_data_summary,
  title={Differentially private summaries for sparse data},
  author={Cormode, Graham and Procopiuc, Cecilia and Srivastava, Divesh and Tran, Thanh TL},
  booktitle={Proceedings of the 15th International Conference on Database Theory},
  pages={299--311},
  year={2012},
  organization={ACM}
}

@article{sparse_data,
  title={Differentially private publication of sparse data},
  author={Cormode, Graham and Procopiuc, Magda and Srivastava, Divesh and Tran, Thanh TL},
  journal={arXiv preprint arXiv:1103.0825},
  year={2011}
}

@article{lagrange,
  title={Dynamic programming and Lagrange multipliers},
  author={Bellman, Richard},
  journal={Proceedings of the National Academy of Sciences of the United States of America},
  volume={42},
  number={10},
  pages={767},
  year={1956},
  publisher={National Academy of Sciences}
}


text:
// Copyright 2021 TiKV Project Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package client_test

import (
	"fmt"
	"math"
	"time"

	"github.com/pingcap/kvproto/pkg/keyspacepb"
	"github.com/stretchr/testify/require"
	"github.com/tikv/pd/pkg/keyspace"
	"github.com/tikv/pd/pkg/mcs/utils"
	"github.com/tikv/pd/pkg/slice"
	"github.com/tikv/pd/server"
)

const (
	testConfig1       = "config_entry_1"
	testConfig2       = "config_entry_2"
	testKeyspaceCount = 10
)

func mustMakeTestKeyspaces(re *require.Assertions, server *server.Server, start int) []*keyspacepb.KeyspaceMeta {
	now := time.Now().Unix()
	var err error
	keyspaces := make([]*keyspacepb.KeyspaceMeta, testKeyspaceCount)
	manager := server.GetKeyspaceManager()
	for i := 0; i < testKeyspaceCount; i++ {
		keyspaces[i], err = manager.CreateKeyspace(&keyspace.CreateKeyspaceRequest{
			Name: fmt.Sprintf("test_keyspace_%d", start+i),
			Config: map[string]string{
				testConfig1: "100",
				testConfig2: "200",
			},
			CreateTime: now,
			IsPreAlloc: true, // skip wait region split
		})
		re.NoError(err)
	}
	return keyspaces
}

func (suite *clientTestSuite) TestLoadKeyspace() {
	re := suite.Require()
	metas := mustMakeTestKeyspaces(re, suite.srv, 0)
	for _, expected := range metas {
		loaded, err := suite.client.LoadKeyspace(suite.ctx, expected.GetName())
		re.NoError(err)
		re.Equal(expected, loaded)
	}
	// Loading non-existing keyspace should result in error.
	_, err := suite.client.LoadKeyspace(suite.ctx, "non-existing keyspace")
	re.Error(err)
	// Loading default keyspace should be successful.
	keyspaceDefault, err := suite.client.LoadKeyspace(suite.ctx, utils.DefaultKeyspaceName)
	re.NoError(err)
	re.Equal(utils.DefaultKeyspaceID, keyspaceDefault.GetId())
	re.Equal(utils.DefaultKeyspaceName, keyspaceDefault.GetName())
}

func (suite *clientTestSuite) TestGetAllKeyspaces() {
	re := suite.Require()
	metas := mustMakeTestKeyspaces(re, suite.srv, 20)
	for _, expected := range metas {
		loaded, err := suite.client.LoadKeyspace(suite.ctx, expected.GetName())
		re.NoError(err)
		re.Equal(expected, loaded)
	}
	// Get all keyspaces.
	resKeyspaces, err := suite.client.GetAllKeyspaces(suite.ctx, 1, math.MaxUint32)
	re.NoError(err)
	re.Equal(len(metas), len(resKeyspaces))
	// Check expected keyspaces all in resKeyspaces.
	for _, expected := range metas {
		var isExists bool
		for _, resKeyspace := range resKeyspaces {
			if expected.GetName() == resKeyspace.GetName() {
				isExists = true
				continue
			}
		}
		if !isExists {
			re.Fail("not exists keyspace")
		}
	}
}

func mustCreateKeyspaceAtState(re *require.Assertions, server *server.Server, index int, state keyspacepb.KeyspaceState) *keyspacepb.KeyspaceMeta {
	manager := server.GetKeyspaceManager()
	meta, err := manager.CreateKeyspace(&keyspace.CreateKeyspaceRequest{
		Name:       fmt.Sprintf("test_keyspace_%d", index),
		Config:     nil,
		CreateTime: 0,    // Use 0 to indicate unchanged keyspace.
		IsPreAlloc: true, // skip wait region split
	})
	re.NoError(err)
	switch state {
	case keyspacepb.KeyspaceState_ENABLED:
	case keyspacepb.KeyspaceState_DISABLED:
		meta, err = manager.UpdateKeyspaceStateByID(meta.GetId(), keyspacepb.KeyspaceState_DISABLED, 0)
		re.NoError(err)
	case keyspacepb.KeyspaceState_ARCHIVED:
		meta, err = manager.UpdateKeyspaceStateByID(meta.GetId(), keyspacepb.KeyspaceState_DISABLED, 0)
		re.NoError(err)
		meta, err = manager.UpdateKeyspaceStateByID(meta.GetId(), keyspacepb.KeyspaceState_ARCHIVED, 0)
		re.NoError(err)
	case keyspacepb.KeyspaceState_TOMBSTONE:
		meta, err = manager.UpdateKeyspaceStateByID(meta.GetId(), keyspacepb.KeyspaceState_DISABLED, 0)
		re.NoError(err)
		meta, err = manager.UpdateKeyspaceStateByID(meta.GetId(), keyspacepb.KeyspaceState_ARCHIVED, 0)
		re.NoError(err)
		meta, err = manager.UpdateKeyspaceStateByID(meta.GetId(), keyspacepb.KeyspaceState_TOMBSTONE, 0)
		re.NoError(err)
	default:
		re.Fail("unknown keyspace state")
	}
	return meta
}

func (suite *clientTestSuite) TestUpdateKeyspaceState() {
	re := suite.Require()
	allStates := []keyspacepb.KeyspaceState{
		keyspacepb.KeyspaceState_ENABLED,
		keyspacepb.KeyspaceState_DISABLED,
		keyspacepb.KeyspaceState_ARCHIVED,
		keyspacepb.KeyspaceState_TOMBSTONE,
	}
	allowedTransitions := map[keyspacepb.KeyspaceState][]keyspacepb.KeyspaceState{
		keyspacepb.KeyspaceState_ENABLED:   {keyspacepb.KeyspaceState_ENABLED, keyspacepb.KeyspaceState_DISABLED},
		keyspacepb.KeyspaceState_DISABLED:  {keyspacepb.KeyspaceState_DISABLED, keyspacepb.KeyspaceState_ENABLED, keyspacepb.KeyspaceState_ARCHIVED},
		keyspacepb.KeyspaceState_ARCHIVED:  {keyspacepb.KeyspaceState_ARCHIVED, keyspacepb.KeyspaceState_TOMBSTONE},
		keyspacepb.KeyspaceState_TOMBSTONE: {keyspacepb.KeyspaceState_TOMBSTONE},
	}
	// Use index to avoid collision with other tests.
	index := 1000
	for _, originState := range allStates {
		for _, targetState := range allStates {
			meta := mustCreateKeyspaceAtState(re, suite.srv, index, originState)
			updated, err := suite.client.UpdateKeyspaceState(suite.ctx, meta.GetId(), targetState)
			if slice.Contains(allowedTransitions[originState], targetState) {
				// If transition is allowed, then update must be successful.
				re.NoError(err)
				if originState != targetState {
					// If changing state, then must record stateChangedAt.
					re.NotEqual(updated.GetStateChangedAt(), meta.GetStateChangedAt())
				} else {
					// Otherwise the request should be idempotent.
					re.Equal(updated, meta)
				}
			} else {
				// If operation is not allowed, then update must fail, returned meta must be nil.
				re.Error(err)
				re.Nil(updated)
			}
			index++
		}
	}
}

repository: tikv/pd

repo_name: tikv/pd